Verified Commit 8546c7fe authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Fix problems with pizza event notifications

parent 81642569
......@@ -56,6 +56,14 @@ module
pizzas.signals module
.. automodule:: pizzas.signals
pizzas.urls module
......@@ -5,3 +5,7 @@ from django.utils.translation import gettext_lazy as _
class PizzasConfig(AppConfig):
name = 'pizzas'
verbose_name = _('Pizzas')
def ready(self):
"""Imports the signals when the app is ready"""
from . import signals # noqa: F401
......@@ -65,7 +65,6 @@ 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):
......@@ -89,30 +88,29 @@ class PizzaEvent(models.Model):
def save(self, *args, **kwargs):
if ((not self.end_reminder or
(not self._send_notification and self.send_notification))
and self.send_notification):
if self.send_notification and not self.end_reminder:
end_reminder = ScheduledMessage()
end_reminder.title_en = 'Order pizza'
end_reminder.title_nl = 'Pizza bestellen'
end_reminder.body_en = 'You can order pizzas for 10 more minutes'
end_reminder.body_nl = "Je kan nog 10 minuten pizza's bestellen"
end_reminder.category = Category.objects.get(key='pizza')
end_reminder.time = self.end
end_reminder.time = self.end - timezone.timedelta(minutes=10)
if self.event.registration_required:
.values_list('member', flat=True))
self.end_reminder = end_reminder
if self._end != self.end and self.send_notification:
elif (self.send_notification and self.end_reminder and
self._end != self.end):
self.end_reminder.time = self.end
if self._send_notification and not self.send_notification:
elif not self.send_notification and self.end_reminder:
super().save(*args, **kwargs)
"""The signals checked by the pizzas package"""
from django.db.models.signals import post_save
from django.dispatch import receiver
@receiver(post_save, sender='events.Registration',
def post_registration_save(sender, instance, **kwargs):
"""Update members on pizza reminder notification"""
event = instance.event
if (event.is_pizza_event() and event.pizzaevent.send_notification
and instance.member is not None):
if instance.date_cancelled:
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