from django.apps import apps from django.dispatch import Signal from . import emails event_submitted = Signal(providing_args=['event']) event_accepted = Signal(providing_args=['event']) event_publishing = Signal(providing_args=['event']) event_published = Signal(providing_args=['event']) event_expired = Signal(providing_args=['event']) def notify_submitted_event(sender, **kwargs): event = kwargs.get('event') app_config = apps.get_containing_app_config(__package__) if app_config.settings.enable_email_notifications: if event.owner.email: email = emails.NewEventMail(recipient=event.owner, event=event) email.send() def notify_accepted_event(sender, **kwargs): event = kwargs.get('event') app_config = apps.get_containing_app_config(__package__) if app_config.settings.enable_email_notifications: if event.owner.email: email = emails.EventAcceptedMail(recipient=event.owner, event=event) email.send() def notify_to_accept_event(sender, **kwargs): event = kwargs.get('event') app_config = apps.get_containing_app_config(__package__) if app_config.settings.enable_email_notifications: from .utils import get_users_by_role managers = get_users_by_role('manage_all') managers += get_users_by_role('manage_{}'.format(event.sport.lower())) OneClickAction = app_config.get_model('OneClickAction') for user in managers: if user.email: action = OneClickAction(command='EA') action.parameters = '{event},{user}'.format(event=event.id, user=user.id) action.save() email = emails.EventToAcceptMail(recipient=user, event=event, accept_action=action) email.send() def notify_to_publish_event(sender, **kwargs): event = kwargs.get('event') app_config = apps.get_containing_app_config(__package__) if app_config.settings.enable_email_notifications: from .utils import get_users_by_role publishers = get_users_by_role('publish_incremental') OneClickAction = app_config.get_model('OneClickAction') for user in publishers: if user.email: action = OneClickAction(command='EP') action.parameters = '{event},{user}'.format(event=event.id, user=user.id) action.save() email = emails.EventToPublishMail(recipient=user, event=event, confirm_publication_action=action) email.send()