82 lines
3.5 KiB
Python
82 lines
3.5 KiB
Python
from django.apps import apps
|
|
|
|
from . import emails
|
|
|
|
|
|
def email_event_update(sender, **kwargs):
|
|
event = kwargs.get('event')
|
|
diff = kwargs.get('diff')
|
|
updater = kwargs.get('user')
|
|
|
|
app_config = apps.get_containing_app_config(__package__)
|
|
if not app_config.settings.enable_email_notifications:
|
|
return
|
|
|
|
# Who should be informed about the update?
|
|
recipients = [event.owner]
|
|
if event.is_flagged('submitted'):
|
|
# If the event is already submitted, add managers to the recipients.
|
|
from .utils import get_users_by_role
|
|
recipients += get_users_by_role('manage_all')
|
|
recipients += get_users_by_role('manage_{}'.format(event.sport.lower()))
|
|
if event.is_flagged('accepted'):
|
|
# If the event is already published, add publishers to the recipients.
|
|
recipients += get_users_by_role('publish_incremental')
|
|
|
|
for recipient in recipients:
|
|
if recipient.email and recipient.email != updater.email:
|
|
email = emails.EventUpdatedMail(recipient=recipient, event=event, editor=updater, diff=diff)
|
|
email.send()
|
|
|
|
|
|
def email_event_status_update(sender, **kwargs):
|
|
event = kwargs.get('event')
|
|
flag = kwargs.get('flag')
|
|
updator = flag.user
|
|
|
|
app_config = apps.get_containing_app_config(__package__)
|
|
if not app_config.settings.enable_email_notifications:
|
|
return
|
|
|
|
if flag.status.code == 'submitted':
|
|
# Inform event owner about his event (so he can keep the mail as a reminder for the event).
|
|
if event.owner.email:
|
|
email = emails.EventSubmittedMail(recipient=event.owner, event=event)
|
|
email.send()
|
|
|
|
# Inform managers that they have to accept the event.
|
|
# Also create OneClickActions for all of them and add the link to the mail,
|
|
# so they can accept the event with a click into the mail.
|
|
from .utils import get_users_by_role
|
|
recipients = get_users_by_role('manage_all')
|
|
recipients += get_users_by_role('manage_{}'.format(event.sport.lower()))
|
|
OneClickAction = app_config.get_model('OneClickAction')
|
|
for recipient in recipients:
|
|
if recipient.email:
|
|
action = OneClickAction(command='EA')
|
|
action.parameters = '{event},{user}'.format(event=event.id, user=recipient.id)
|
|
action.save()
|
|
email = emails.EventToAcceptMail(recipient=recipient, event=event, accept_action=action)
|
|
email.send()
|
|
|
|
elif flag.status.code == 'accepted':
|
|
# Inform event owner about the acceptance of his event.
|
|
if event.owner.email:
|
|
email = emails.EventAcceptedMail(recipient=event.owner, event=event, editor=updator)
|
|
email.send()
|
|
|
|
# Inform publishers that they have to publish the event.
|
|
# Also create OneClickActions for all of them and add the link to the mail,
|
|
# so they can confirm the publication with a click into the mail.
|
|
from .utils import get_users_by_role
|
|
recipients = get_users_by_role('publish_incremental')
|
|
OneClickAction = app_config.get_model('OneClickAction')
|
|
for recipient in recipients:
|
|
if recipient.email:
|
|
action = OneClickAction(command='EP')
|
|
action.parameters = '{event},{user}'.format(event=event.id, user=recipient.id)
|
|
action.save()
|
|
email = emails.EventToPublishMail(recipient=recipient, event=event, editor=updator,
|
|
confirm_publication_action=action)
|
|
email.send()
|