def send_someone_joined_notification(membership_pk): try: membership = Membership.objects.select_related( 'person', 'supportgroup').get(pk=membership_pk) except Membership.DoesNotExist: return person_information = str(membership.person) managers_filter = (Q(is_referent=True) | Q(is_manager=True)) & Q(notifications_enabled=True) managing_membership = membership.supportgroup.memberships.filter( managers_filter).select_related('person').prefetch_related( 'person__emails') recipients = [membership.person for membership in managing_membership] bindings = { "GROUP_NAME": membership.supportgroup.name, "PERSON_INFORMATION": person_information, "MANAGE_GROUP_LINK": front_url("manage_group", kwargs={"pk": membership.supportgroup.pk}) } send_mosaico_email( code='GROUP_SOMEONE_JOINED_NOTIFICATION', subject=_("Un nouveau membre dans votre groupe d'action"), from_email=settings.EMAIL_FROM, recipients=recipients, bindings=bindings)
def send_cancellation_notification(event_pk): try: event = Event.objects.get(pk=event_pk) except Event.DoesNotExist: return # check it is indeed cancelled if event.published: return event_name = event.name notifications_enabled = Q(notifications_enabled=True) & Q( person__event_notifications=True) recipients = [ rsvp.person for rsvp in event.rsvps.filter( notifications_enabled).prefetch_related('person__emails') ] bindings = {"EVENT_NAME": event_name} send_mosaico_email( code='EVENT_CANCELLATION', subject=_("Un événement auquel vous participiez a été annulé"), from_email=settings.EMAIL_FROM, recipients=recipients, bindings=bindings)
def send_support_group_changed_notification(support_group_pk, changes): try: group = SupportGroup.objects.get(pk=support_group_pk, published=True) except SupportGroup.DoesNotExist: return change_descriptions = [ desc for label, desc in CHANGE_DESCRIPTION.items() if label in changes ] change_fragment = render_to_string(template_name='lib/list_fragment.html', context={'items': change_descriptions}) # TODO: find adequate way to set up domain names to use for these links bindings = { "GROUP_NAME": group.name, "GROUP_CHANGES": change_fragment, "GROUP_LINK": front_url("view_group", kwargs={'pk': support_group_pk}) } notifications_enabled = Q(notifications_enabled=True) & Q( person__group_notifications=True) recipients = [ membership.person for membership in group.memberships.filter( notifications_enabled).prefetch_related('person__emails') ] send_mosaico_email( code='GROUP_CHANGED', subject=_( "Les informations de votre groupe d'action ont été changées"), from_email=settings.EMAIL_FROM, recipients=recipients, bindings=bindings, )
def send_welcome_mail(person_pk): person = Person.objects.prefetch_related('emails').get(pk=person_pk) send_mosaico_email( code='WELCOME_MESSAGE', subject=_("Bienvenue sur la plateforme de la France insoumise"), from_email=settings.EMAIL_FROM, bindings={'PROFILE_LINK': front_url('change_profile')}, recipients=[person])
def send_unsubscribe_email(person_pk): person = Person.objects.prefetch_related('emails').get(pk=person_pk) bindings = { "MANAGE_SUBSCRIPTIONS_LINK": front_url('message_preferences'), } send_mosaico_email( code='UNSUBSCRIBE_CONFIRMATION', subject=_( 'Vous avez été désabonné⋅e des emails de la France insoumise'), from_email=settings.EMAIL_FROM, recipients=[person], bindings=bindings)
def send_rsvp_notification(rsvp_pk): try: rsvp = RSVP.objects.select_related('person', 'event').get(pk=rsvp_pk) except RSVP.DoesNotExist: # RSVP does not exist any more?! return person_information = str(rsvp.person) recipients = [ organizer_config.person for organizer_config in rsvp.event.organizer_configs.filter( notifications_enabled=True) if organizer_config.person != rsvp.person ] attendee_bindings = { "EVENT_NAME": rsvp.event.name, "EVENT_SCHEDULE": rsvp.event.get_display_date(), "CONTACT_NAME": rsvp.event.contact_name, "CONTACT_EMAIL": rsvp.event.contact_email, "LOCATION_NAME": rsvp.event.location_name, "LOCATION_ADDRESS": rsvp.event.short_address, "EVENT_LINK": front_url("view_event", args=[rsvp.event.pk]) } send_mosaico_email( code='EVENT_RSVP_CONFIRMATION', subject=_("Confirmation de votre participation à l'événement"), from_email=settings.EMAIL_FROM, recipients=[rsvp.person], bindings=attendee_bindings) organizer_bindings = { "EVENT_NAME": rsvp.event.name, "PERSON_INFORMATION": person_information, "MANAGE_EVENT_LINK": front_url("manage_event", kwargs={"pk": rsvp.event.pk}) } send_mosaico_email( code='EVENT_RSVP_NOTIFICATION', subject=_("Un nouveau participant à l'un de vos événements"), from_email=settings.EMAIL_FROM, recipients=recipients, bindings=organizer_bindings)
def send_event_creation_notification(organizer_config_pk): try: organizer_config = OrganizerConfig.objects.select_related( 'event', 'person').get(pk=organizer_config_pk) except OrganizerConfig.DoesNotExist: return event = organizer_config.event organizer = organizer_config.person bindings = { "EVENT_NAME": event.name, "EVENT_SCHEDULE": event.get_display_date(), "CONTACT_NAME": event.contact_name, "CONTACT_EMAIL": event.contact_email, "CONTACT_PHONE": event.contact_phone, "CONTACT_PHONE_VISIBILITY": _("caché") if event.contact_hide_phone else _("public"), "LOCATION_NAME": event.location_name, "LOCATION_ADDRESS": event.short_address, "EVENT_LINK": front_url("view_event", kwargs={'pk': event.pk}), "MANAGE_EVENT_LINK": front_url('manage_event', kwargs={'pk': event.pk}), } send_mosaico_email( code='EVENT_CREATION', subject=_("Les informations de votre nouvel événement"), from_email=settings.EMAIL_FROM, recipients=[organizer], bindings=bindings, )
def send_support_group_creation_notification(membership_pk): try: membership = Membership.objects.select_related( 'supportgroup', 'person').get(pk=membership_pk) except Membership.DoesNotExist: return group = membership.supportgroup referent = membership.person bindings = { "GROUP_NAME": group.name, "CONTACT_NAME": group.contact_name, "CONTACT_EMAIL": group.contact_email, "CONTACT_PHONE": group.contact_phone, "CONTACT_PHONE_VISIBILITY": _("caché") if group.contact_hide_phone else _("public"), "LOCATION_NAME": group.location_name, "LOCATION_ADDRESS": group.short_address, "GROUP_LINK": front_url("view_group", kwargs={'pk': group.pk}), "MANAGE_GROUP_LINK": front_url('manage_group', kwargs={'pk': group.pk}), } send_mosaico_email( code='GROUP_CREATION', subject=_("Les informations de votre nouveau groupe d'action"), from_email=settings.EMAIL_FROM, recipients=[referent], bindings=bindings, )
def send_event_changed_notification(event_pk, changes): try: event = Event.objects.get(pk=event_pk) except Event.DoesNotExist: # event does not exist anymore ?! nothing to do return change_descriptions = [ desc for label, desc in CHANGE_DESCRIPTION.items() if label in changes ] change_fragment = render_to_string(template_name='lib/list_fragment.html', context={'items': change_descriptions}) notifications_enabled = Q(notifications_enabled=True) & Q( person__event_notifications=True) recipients = [ rsvp.person for rsvp in event.rsvps.filter( notifications_enabled).prefetch_related('person__emails') ] bindings = { "EVENT_NAME": event.name, "EVENT_CHANGES": change_fragment, "EVENT_LINK": front_url("view_event", kwargs={'pk': event_pk}), "EVENT_QUIT_LINK": front_url("quit_event", kwargs={'pk': event_pk}) } send_mosaico_email( code='EVENT_CHANGED', subject= _("Les informations d'un événement auquel vous assistez ont été changées" ), from_email=settings.EMAIL_FROM, recipients=recipients, bindings=bindings, )