Commit f3d496a3 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Merge branch 'fix/pizzas' into 'master'

fixed send_notifcation and admin

See merge request !1121
parents 390db682 dcc7f19c
......@@ -72,6 +72,7 @@ class RegistrationInformationFieldInline(admin.StackedInline):
class PizzaEventInline(admin.StackedInline):
"""The inline for pizza events in the Event admin"""
model = PizzaEvent
exclude = ('end_reminder',)
extra = 0
max_num = 1
......
......@@ -17,6 +17,7 @@ class ProductAdmin(admin.ModelAdmin):
@admin.register(PizzaEvent)
class PizzaEventAdmin(admin.ModelAdmin):
list_display = ('title', 'orders')
exclude = ('end_reminder',)
def orders(self, obj):
return format_html(_('<strong><a href="{link}">Orders</a></strong>'),
......
......@@ -65,6 +65,7 @@ class PizzaEvent(models.Model):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._end = self.end
self._send_notification = self.send_notification
def validate_unique(self, exclude=None):
super().validate_unique(exclude)
......@@ -88,7 +89,9 @@ class PizzaEvent(models.Model):
})
def save(self, *args, **kwargs):
if not self.end_reminder:
if ((not self.end_reminder or
(not self._send_notification and self.send_notification))
and self.send_notification):
end_reminder = ScheduledMessage()
end_reminder.title_en = 'Order pizza'
end_reminder.title_nl = 'Pizza bestellen'
......@@ -105,10 +108,13 @@ class PizzaEvent(models.Model):
self.end_reminder = end_reminder
if self._end != self.end:
if self._end != self.end and self.send_notification:
self.end_reminder.time = self.end
self.end_reminder.save()
if self._send_notification and not self.send_notification:
self.end_reminder.delete()
super().save(*args, **kwargs)
def __str__(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment