Skip to content
Snippets Groups Projects
Commit c896a89e authored by Hangzhi Yu's avatar Hangzhi Yu
Browse files

Move update/create follow up logic in own method

parent 46ab9d4f
No related branches found
No related tags found
1 merge request!360Resolve "Reimplement notification system on base of new calendar system"
Pipeline #194729 failed
......@@ -482,13 +482,7 @@ class LessonEvent(CalendarEvent):
else:
alarms = LessonEventAlarm.objects.filter(event=self, status="c")
for alarm in alarms:
if alarm.has_sent_notifications:
follow_up_alarm = LessonEventAlarm(
event=self, send_notifications=True, status="e"
)
follow_up_alarm.save()
else:
alarm.update_or_create_notifications()
alarm.update_or_create_follow_up()
class Meta:
verbose_name = _("Lesson Event")
......@@ -509,13 +503,7 @@ def create_alarm_on_teachers_m2m_changed(
alarms = LessonEventAlarm.objects.filter(event=instance, status="c")
for alarm in alarms:
if alarm.has_sent_notifications:
follow_up_alarm = LessonEventAlarm(
event=self, send_notifications=True, status="e"
)
follow_up_alarm.save()
else:
alarm.update_or_create_notifications()
alarm.update_or_create_follow_up()
class LessonEventAlarm(CalendarAlarm):
......@@ -571,6 +559,15 @@ class LessonEventAlarm(CalendarAlarm):
def has_sent_notifications(self) -> bool:
return self.notifications.filter(sent=True).exists()
def update_or_create_follow_up(self):
if self.has_sent_notifications:
follow_up_alarm = LessonEventAlarm(
event=self.event, send_notifications=True, status="e"
)
follow_up_alarm.save()
else:
self.update_or_create_notifications()
class Meta:
verbose_name = _("Lesson event alarm")
verbose_name_plural = _("Lesson event alarms")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment