Commit dcc7f19c authored by Luko van der Maas's avatar Luko van der Maas
Browse files

fixed send_notifcation and admin

parent 390db682
...@@ -72,6 +72,7 @@ class RegistrationInformationFieldInline(admin.StackedInline): ...@@ -72,6 +72,7 @@ class RegistrationInformationFieldInline(admin.StackedInline):
class PizzaEventInline(admin.StackedInline): class PizzaEventInline(admin.StackedInline):
"""The inline for pizza events in the Event admin""" """The inline for pizza events in the Event admin"""
model = PizzaEvent model = PizzaEvent
exclude = ('end_reminder',)
extra = 0 extra = 0
max_num = 1 max_num = 1
......
...@@ -17,6 +17,7 @@ class ProductAdmin(admin.ModelAdmin): ...@@ -17,6 +17,7 @@ class ProductAdmin(admin.ModelAdmin):
@admin.register(PizzaEvent) @admin.register(PizzaEvent)
class PizzaEventAdmin(admin.ModelAdmin): class PizzaEventAdmin(admin.ModelAdmin):
list_display = ('title', 'orders') list_display = ('title', 'orders')
exclude = ('end_reminder',)
def orders(self, obj): def orders(self, obj):
return format_html(_('<strong><a href="{link}">Orders</a></strong>'), return format_html(_('<strong><a href="{link}">Orders</a></strong>'),
......
...@@ -65,6 +65,7 @@ class PizzaEvent(models.Model): ...@@ -65,6 +65,7 @@ class PizzaEvent(models.Model):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._end = self.end self._end = self.end
self._send_notification = self.send_notification
def validate_unique(self, exclude=None): def validate_unique(self, exclude=None):
super().validate_unique(exclude) super().validate_unique(exclude)
...@@ -88,7 +89,9 @@ class PizzaEvent(models.Model): ...@@ -88,7 +89,9 @@ class PizzaEvent(models.Model):
}) })
def save(self, *args, **kwargs): 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 = ScheduledMessage()
end_reminder.title_en = 'Order pizza' end_reminder.title_en = 'Order pizza'
end_reminder.title_nl = 'Pizza bestellen' end_reminder.title_nl = 'Pizza bestellen'
...@@ -105,10 +108,13 @@ class PizzaEvent(models.Model): ...@@ -105,10 +108,13 @@ class PizzaEvent(models.Model):
self.end_reminder = end_reminder 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.time = self.end
self.end_reminder.save() self.end_reminder.save()
if self._send_notification and not self.send_notification:
self.end_reminder.delete()
super().save(*args, **kwargs) super().save(*args, **kwargs)
def __str__(self): def __str__(self):
......
Supports Markdown
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