Commit bc470873 authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Merge branch 'fix/donot-scheduled-messages-unpublished' into 'master'

Do not schedule or delete messages for unpublished events

Closes #655 and #656

See merge request !847
parents 7278f4d0 97851733
......@@ -280,43 +280,55 @@ class Event(models.Model, metaclass=ModelTranslateMeta):
return reverse('events:event', args=[str(self.pk)])
def save(self, *args, **kwargs):
if self.registration_required:
registration_reminder = ScheduledMessage()
if self.registration_reminder is not None:
registration_reminder = self.registration_reminder
registration_reminder.title_en = 'Event registration'
registration_reminder.title_nl = 'Evenement registratie'
registration_reminder.body_en = ('Registration for \'{}\' '
'starts in 1 hour'
.format(self.title_en))
registration_reminder.body_nl = ('Registratie voor \'{}\' '
'start in 1 uur'
.format(self.title_nl))
registration_reminder.category = Category.objects.get(key='event')
registration_reminder.time = (self.registration_start -
timezone.timedelta(hours=1))
registration_reminder.save()
self.registration_reminder = registration_reminder
self.registration_reminder.users.set(Member.active_members.all())
start_reminder = ScheduledMessage()
if self.start_reminder is not None:
start_reminder = self.start_reminder
start_reminder.title_en = 'Event'
start_reminder.title_nl = 'Evenement'
start_reminder.body_en = ('\'{}\' starts in '
'1 hour'.format(self.title_en))
start_reminder.body_nl = ('\'{}\' begint over '
'1 uur'.format(self.title_nl))
start_reminder.category = Category.objects.get(key='event')
start_reminder.time = (self.start - timezone.timedelta(hours=1))
start_reminder.save()
self.start_reminder = start_reminder
if self.registration_required:
self.start_reminder.users.set(self.participants.values_list(
'member', flat=True))
if self.published:
if self.registration_required:
registration_reminder = ScheduledMessage()
if (self.registration_reminder is not None
and not self.registration_reminder.sent):
registration_reminder = self.registration_reminder
registration_reminder.title_en = 'Event registration'
registration_reminder.title_nl = 'Evenement registratie'
registration_reminder.body_en = ('Registration for \'{}\' '
'starts in 1 hour'
.format(self.title_en))
registration_reminder.body_nl = ('Registratie voor \'{}\' '
'start in 1 uur'
.format(self.title_nl))
registration_reminder.category = Category.objects.get(
key='event')
registration_reminder.time = (self.registration_start -
timezone.timedelta(hours=1))
registration_reminder.save()
self.registration_reminder = registration_reminder
self.registration_reminder.users.set(
Member.active_members.all())
start_reminder = ScheduledMessage()
if (self.start_reminder is not None
and not self.start_reminder.sent):
start_reminder = self.start_reminder
start_reminder.title_en = 'Event'
start_reminder.title_nl = 'Evenement'
start_reminder.body_en = ('\'{}\' starts in '
'1 hour'.format(self.title_en))
start_reminder.body_nl = ('\'{}\' begint over '
'1 uur'.format(self.title_nl))
start_reminder.category = Category.objects.get(key='event')
start_reminder.time = (self.start - timezone.timedelta(hours=1))
start_reminder.save()
self.start_reminder = start_reminder
if self.registration_required:
self.start_reminder.users.set(self.participants.values_list(
'member', flat=True))
else:
self.start_reminder.users.set(Member.active_members.all())
else:
self.start_reminder.users.set(Member.active_members.all())
if (self.registration_reminder is not None
and not self.registration_reminder.sent):
self.registration_reminder.delete()
if (self.start_reminder is not None
and not self.start_reminder.sent):
self.start_reminder.delete()
super().save(*args, **kwargs)
......
......@@ -9,7 +9,6 @@ from pyfcm import FCMNotification
from utils.tasks import revoke_task, schedule_task
from utils.translation import MultilingualField, ModelTranslateMeta
from .tasks import send_message
from thaliawebsite import celery_app
class Category(models.Model, metaclass=ModelTranslateMeta):
......@@ -231,5 +230,5 @@ class ScheduledMessage(Message, metaclass=ModelTranslateMeta):
def delete(self, using=None, keep_parents=False):
if self.task_id:
celery_app.control.revoke(self.task_id)
revoke_task(self.task_id)
return super().delete(using, keep_parents)
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