def add_respond_urls_to_event_coorganization_activities(apps, schema_editor):
    Activity = apps.get_model("activity", "Activity")
    Invitation = apps.get_model("events", "Invitation")
    activities = Activity.objects.filter(
        type=TYPE_GROUP_COORGANIZATION_INVITE).exclude(
            meta__has_keys=[ACCEPT_URL_KEY, REFUSE_URL_KEY])
    for activity in activities:
        invitation = Invitation.objects.filter(
            event=activity.event, group=activity.supportgroup).first()
        if not invitation:
            continue
        activity.meta = {
            **activity.meta,
            ACCEPT_URL_KEY:
            front_url(
                "accept_event_group_coorganization",
                absolute=False,
                kwargs={"pk": invitation.pk},
            ),
            REFUSE_URL_KEY:
            front_url(
                "refuse_event_group_coorganization",
                absolute=False,
                kwargs={"pk": invitation.pk},
            ),
        }
        activity.save()
예제 #2
0
def follow_activity_link(request, pk):
    user = request.user
    if user.is_authenticated and user.person is not None:
        try:
            activity = Activity.objects.get(pk=pk, recipient=user.person)
            activity.status = Activity.STATUS_INTERACTED
            activity.save()
        except Activity.DoesNotExist:
            pass

    next = request.GET.get("next", front_url("list_activities"))
    allowed_hosts = {
        s.strip("/").rsplit("/", 1)[-1]
        for s in [
            settings.MAIN_DOMAIN,
            settings.API_DOMAIN,
            settings.FRONT_DOMAIN,
            settings.NSP_DOMAIN,
            "https://infos.actionpopulaire.fr",
        ]
    }
    url_is_safe = url_has_allowed_host_and_scheme(
        url=next,
        allowed_hosts=allowed_hosts,
        require_https=True,
    )
    if not url_is_safe:
        next = front_url("list_activities")

    return HttpResponseRedirect(next)
예제 #3
0
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,
        "GROUP_LINK": front_url(
            "view_group", auto_login=False, 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 "
        + ("nouvelle équipe" if group.is_2022 else "nouveau groupe"),
        from_email=settings.EMAIL_FROM,
        recipients=[referent],
        bindings=bindings,
    )
예제 #4
0
    def test_rsvp_notification_mail(self):
        tasks.send_rsvp_notification(self.rsvp1.pk)

        self.assertEqual(len(mail.outbox), 2)

        attendee_message = mail.outbox[0]
        self.assertEqual(attendee_message.recipients(),
                         ["*****@*****.**"])

        text = attendee_message.body.replace("\n", "")
        mail_content = {
            "event name": self.event.name,
            "event link": front_url("view_event", kwargs={"pk":
                                                          self.event.pk}),
        }

        for name, value in mail_content.items():
            self.assert_(value in text, "{} missing from mail".format(name))

        org_message = mail.outbox[1]
        self.assertEqual(org_message.recipients(), ["*****@*****.**"])

        text = org_message.body.replace("\n", "")

        mail_content = {
            "attendee information":
            str(self.attendee1),
            "event name":
            self.event.name,
            "event management link":
            front_url("manage_event", kwargs={"pk": self.event.pk}),
        }

        for name, value in mail_content.items():
            self.assert_(value in text, "{} missing from mail".format(name))
예제 #5
0
def send_message_notification_email(message_pk):

    message = SupportGroupMessage.objects.get(pk=message_pk)

    memberships = message.supportgroup.memberships.filter(
        membership_type__gte=message.required_membership_type)
    recipients = Person.objects.filter(
        id__in=memberships.values_list("person_id", flat=True))
    recipients_id = [recipient.id for recipient in recipients]

    recipients = Person.objects.exclude(id=message.author.id).filter(
        id__in=recipients_id,
        notification_subscriptions__membership__supportgroup=message.
        supportgroup,
        notification_subscriptions__type=Subscription.SUBSCRIPTION_EMAIL,
        notification_subscriptions__activity_type=Activity.TYPE_NEW_MESSAGE,
    )

    if len(recipients) == 0:
        return

    # Get membership to display author status
    membership_type = None
    membership = Membership.objects.filter(person=message.author,
                                           supportgroup=message.supportgroup)
    if membership.exists():
        membership_type = membership.first().membership_type
    author_status = genrer_membership(message.author.gender, membership_type)

    bindings = {
        "MESSAGE_HTML":
        format_html_join("", "<p>{}</p>",
                         ((p, ) for p in message.text.split("\n"))),
        "DISPLAY_NAME":
        message.author.display_name,
        "MESSAGE_LINK":
        front_url("user_message_details", kwargs={"pk": message_pk}),
        "AUTHOR_STATUS":
        format_html(
            '{} de <a href="{}">{}</a>',
            author_status,
            front_url("view_group", args=[message.supportgroup.pk]),
            message.supportgroup.name,
        ),
    }

    if message.subject:
        subject = message.subject
    else:
        subject = f"Nouveau message de {message.author.display_name}"
    subject = clean_subject_email(subject)

    send_mosaico_email(
        code="NEW_MESSAGE",
        subject=subject,
        from_email=settings.EMAIL_FROM,
        recipients=recipients,
        bindings=bindings,
    )
예제 #6
0
    def get_form_for_transaction(cls, transaction, sp_config):
        person = transaction.subscription.person

        success_url = front_url(
            "subscription_return", kwargs={"pk": transaction.subscription_id}
        )
        failure_url = front_url(
            f"{transaction.subscription.mode}:failure", kwargs={"pk": transaction.pk}
        )

        person_data = {}
        if person is not None:
            person_data.update(
                {
                    f.name: getattr(person, f.name)
                    for f in person._meta.get_fields()
                    if not f.is_relation
                }
            )
        person_data.update(transaction.subscription.meta)

        form = cls(
            initial={
                "vads_site_id": sp_config["site_id"],
                "vads_ctx_mode": "PRODUCTION" if sp_config["production"] else "TEST",
                "vads_sub_currency": sp_config["currency"],
                "vads_order_id": transaction.pk,
                "vads_trans_id": get_trans_id_from_order_id(transaction.pk),
                "vads_trans_date": transaction.created.strftime("%Y%m%d%H%M%S"),
                "vads_sub_effect_date": transaction.created.strftime("%Y%m%d"),
                "vads_sub_amount": transaction.subscription.price,
                "vads_cust_email": person.email,
                "vads_cust_id": transaction.subscription.person_id,
                "vads_cust_first_name": person_data.get("first_name"),
                "vads_cust_last_name": person_data.get("last_name"),
                "vads_cust_address": ", ".join(
                    [
                        person_data.get("location_address1", ""),
                        person_data.get("location_address2", ""),
                    ]
                ).strip(),
                "vads_cust_zip": person_data.get("location_zip"),
                "vads_cust_city": person_data.get("location_city"),
                "vads_cust_state": person_data.get("location_state"),
                "vads_cust_country": person_data.get("location_country"),
                "vads_sub_desc": get_recurrence_rule(transaction.subscription),
                "vads_url_success": success_url,
                **{
                    f"vads_url_{status}": f"{failure_url}?status={status}"
                    for status in ["cancel", "error", "refused"]
                },
            }
        )

        form.update_signature(sp_config["certificate"])

        return form
    def handle(self, *args, person_email, **options):
        try:
            p = Person.objects.get_by_natural_key(person_email)
        except Person.DoesNotExist:
            raise CommandError("L'email donné est inconnu.")

        spec_role = get_all_fields(Role)

        spec_event = {
            "Nom": "name",
            "URL": ("id", lambda id: front_url("view_event", args=[id])),
        }
        spec_membership = {
            "Nom":
            "supportgroup.name",
            "URL":
            ("supportgroup.id", lambda id: front_url("view_group", args=[id])),
            "Animateur":
            "is_referent",
            "Gestionnaire":
            "is_manager",
        }

        spec_payment = get_all_fields(Payment)
        spec_subscription = get_all_fields(Subscription)
        spec_event_images = get_all_fields(EventImage)
        spec_form_submissions = get_all_fields(PersonFormSubmission)
        spec_tags = get_all_fields(PersonTag)

        spec_person = {
            **get_all_fields(Person),
            "pays": ("location_country", str),
            "Rôle": ("role", spec_role),
            "événements organisés":
            ("organized_events", T.all(), [spec_event]),
            "participations aux événements": (
                "rsvps",
                T.all(),
                [("event", spec_event)],
            ),
            "participations à des groupes":
            ("memberships", T.all(), [spec_membership]),
            "paiements": ("payments", T.all(), [spec_payment]),
            "souscription au don mensuel":
            Coalesce(("subscription", spec_subscription), default=None),
            "images d'événements":
            ("event_images", T.all(), [spec_event_images]),
            "réponses à des formulaires": (
                "form_submissions",
                T.all(),
                [spec_form_submissions],
            ),
            "libellés": ("tags", T.all(), [spec_tags]),
        }

        self.stdout.ending = ""
        json.dump(glom(p, spec_person), self.stdout, cls=DjangoJSONEncoder)
예제 #8
0
def invite_to_group(group_id, invited_email, inviter_id):
    try:
        group = SupportGroup.objects.get(pk=group_id)
    except SupportGroup.DoesNotExist:
        return

    try:
        person = Person.objects.get_by_natural_key(invited_email)
    except Person.DoesNotExist:
        person = None

    group_name = group.name

    report_url = make_abusive_invitation_report_link(group_id, inviter_id)
    invitation_token = make_subscription_token(email=invited_email, group_id=group_id)
    join_url = front_url(
        "invitation_with_subscription_confirmation",
        query={
            "email": invited_email,
            "group_id": group_id,
            "token": invitation_token,
        },
    )

    if person:
        Activity.objects.create(
            type=Activity.TYPE_GROUP_INVITATION,
            recipient=person,
            supportgroup=group,
            meta={"joinUrl": join_url},
        )
    else:
        invitation_token = make_subscription_token(
            email=invited_email, group_id=group_id
        )
        join_url = front_url(
            "invitation_with_subscription_confirmation",
            query={
                "email": invited_email,
                "group_id": group_id,
                "token": invitation_token,
            },
        )

        send_mosaico_email(
            code="GROUP_INVITATION_WITH_SUBSCRIPTION_MESSAGE",
            subject="Vous avez été invité⋅e à rejoindre la France insoumise",
            from_email=settings.EMAIL_FROM,
            recipients=[invited_email],
            bindings={
                "GROUP_NAME": group_name,
                "CONFIRMATION_URL": join_url,
                "REPORT_URL": report_url,
            },
        )
예제 #9
0
def send_event_changed_notification(event_pk, changed_data):
    event = Event.objects.get(pk=event_pk)

    changed_data = [f for f in changed_data if f in NOTIFIED_CHANGES]

    recipients = [
        r.person
        for r in event.rsvps.prefetch_related("person__emails").filter(
            person__notification_subscriptions__type=Subscription.
            SUBSCRIPTION_EMAIL,
            person__notification_subscriptions__activity_type=Activity.
            TYPE_EVENT_UPDATE,
        )
    ]

    if len(recipients) == 0:
        return

    changed_categories = {NOTIFIED_CHANGES[f] for f in changed_data}
    change_descriptions = [
        desc for id, desc in CHANGE_DESCRIPTION.items()
        if id in changed_categories
    ]
    change_fragment = render_to_string(template_name="lib/list_fragment.html",
                                       context={"items": change_descriptions})

    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 participez ont été changées"
          ),
        from_email=settings.EMAIL_FROM,
        recipients=recipients,
        bindings=bindings,
        attachments=({
            "filename":
            "event.ics",
            "content":
            str(ics.Calendar(events=[event.to_ics(
                text_only_description=True)])),
            "mimetype":
            "text/calendar",
        }, ),
    )
예제 #10
0
def send_event_creation_notification(organizer_config_pk):
    organizer_config = OrganizerConfig.objects.select_related(
        "event", "person").get(pk=organizer_config_pk)

    event = organizer_config.event
    organizer = organizer_config.person
    document_deadline = event.end_time + timedelta(days=15)

    bindings = {
        "EVENT_NAME":
        event.name,
        "EVENT_SCHEDULE":
        event.get_display_date(),
        "LOCATION_NAME":
        event.location_name,
        "LOCATION_ADDRESS":
        event.short_address,
        "EVENT_LINK":
        front_url("view_event", auto_login=False, kwargs={"pk": event.pk}),
        "MANAGE_EVENT_LINK":
        front_url("manage_event", auto_login=False, kwargs={"pk": event.pk}),
        "DOCUMENTS_LINK":
        front_url("event_project", auto_login=False, kwargs={"pk": event.pk}),
        "EVENT_NAME_ENCODED":
        event.name,
        "EVENT_LINK_ENCODED":
        front_url("view_event", auto_login=False, kwargs={"pk": event.pk}),
        "DOCUMENT_DEADLINE":
        document_deadline.strftime("%d/%m"),
        "REQUIRED_DOCUMENT_TYPES":
        event.subtype.required_documents,
        "NEEDS_DOCUMENTS":
        len(event.subtype.required_documents) > 0,
    }

    send_mosaico_email(
        code="EVENT_CREATION",
        subject=_("Les informations de votre nouvel événement"),
        from_email=settings.EMAIL_FROM,
        recipients=[organizer],
        bindings=bindings,
        attachments=({
            "filename":
            "event.ics",
            "content":
            str(ics.Calendar(events=[event.to_ics(
                text_only_description=True)])),
            "mimetype":
            "text/calendar",
        }, ),
    )
예제 #11
0
파일: tasks.py 프로젝트: nipal/api-django
def send_confirmation_change_email(self, new_email, user_pk, **kwargs):
    try:
        Person.objects.get(pk=user_pk)
    except Person.DoesNotExist:
        return

    subscription_token = add_email_confirmation_token_generator.make_token(
        new_email=new_email, user=user_pk
    )
    query_args = {
        "new_email": new_email,
        "user": user_pk,
        "token": subscription_token,
        **kwargs,
    }
    confirm_change_mail_url = front_url(
        "confirm_change_mail", query=query_args, auto_login=False
    )

    try:
        send_mosaico_email(
            code="CHANGE_MAIL_CONFIRMATION",
            subject="confirmer votre changement d'adresse",
            from_email=settings.EMAIL_FROM,
            recipients=[new_email],
            bindings={"CONFIRMATION_URL": confirm_change_mail_url},
        )
    except (smtplib.SMTPException, socket.error) as exc:
        self.retry(countdown=60, exc=exc)
예제 #12
0
    def status_buttons(self, payment):
        if payment.status not in [
                Payment.STATUS_WAITING,
                Payment.STATUS_REFUSED,
                Payment.STATUS_ABANDONED,
        ]:
            return "-"

        if not PAYMENT_MODES[payment.mode].can_admin:
            return format_html(
                '<a href="{}" target="_blank" class="button">Effectuer le paiement en ligne</a>',
                front_url("payment_page", args=[payment.pk]),
            )

        statuses = [
            (Payment.STATUS_COMPLETED, "Valider"),
            (Payment.STATUS_CANCELED, "Annuler"),
            (Payment.STATUS_REFUSED, "Refuser"),
        ]

        return format_html_join(
            " ",
            '<button type="submit" class="button" name="_changestatus" value="{}">{}</button>',
            ((status, label) for status, label in statuses),
        )
예제 #13
0
def send_expiration_sms_reminder(sp_subscription_pk):
    try:
        sp_subscription = SystemPaySubscription.objects.select_related(
            "subscription__person", "alias"
        ).get(pk=sp_subscription_pk)
    except SystemPaySubscription.DoesNotExist:
        return

    recipient = sp_subscription.subscription.person

    if (
        not recipient.contact_phone
        or not is_french_number(recipient.contact_phone)
        or not is_mobile_number(recipient.contact_phone)
    ):
        return

    connection_params = generate_token_params(recipient)

    url = shorten_url(
        add_params_to_urls(front_url("view_payments"), connection_params), secret=True
    )

    send_sms(
        f"Votre carte bleue arrive à expiration. Pour continuer votre don régulier à la France insoumise, "
        f"mettez là à jour : {url}\n"
        f"Merci encore de votre soutien !",
        recipient.contact_phone,
    )
예제 #14
0
    def get(self, request, *args, **kwargs):
        group = self.get_object()
        donation = get_balance(group)
        spending_requests = [{
            "id":
            spending_request.id,
            "title":
            spending_request.title,
            "status":
            spending_request.get_status_display(),
            "date":
            spending_request.spending_date,
            "link":
            front_url("manage_spending_request",
                      kwargs={"pk": spending_request.pk}),
        } for spending_request in (
            SpendingRequest.objects.filter(group=group).exclude(
                status=SpendingRequest.STATUS_PAID).order_by("-spending_date").
            only("id", "title", "status", "spending_date"))]

        return Response(
            status=status.HTTP_200_OK,
            data={
                "donation": donation,
                "spendingRequests": spending_requests
            },
        )
예제 #15
0
 def link(self, object):
     if object.pk:
         return format_html(
             '<a href="{url}">{text}</a>',
             url=front_url("participate_poll", args=[object.pk]),
             text=_("Voir la consultation"),
         )
예제 #16
0
def send_event_report(event_pk):
    event = Event.objects.get(pk=event_pk)
    if event.report_summary_sent:
        return

    recipients = event.attendees.filter(
        notification_subscriptions__type=Subscription.SUBSCRIPTION_EMAIL,
        notification_subscriptions__activity_type=Activity.TYPE_NEW_REPORT,
        notification_subscriptions__membership__supportgroup__in=event.
        organizers_groups.all(),
    )

    if len(recipients) == 0:
        return

    bindings = {
        "EVENT_NAME":
        event.name,
        "EVENT_REPORT_SUMMARY":
        sanitize_html(str_summary(event.report_content, length_max=500)),
        "EVENT_REPORT_LINK":
        front_url("view_event", kwargs={"pk": event_pk}),
    }

    send_mosaico_email(
        code="EVENT_REPORT",
        subject=f"Compte-rendu de l'événement {event.name}",
        from_email=settings.EMAIL_FROM,
        recipients=recipients,
        bindings=bindings,
    )

    event.report_summary_sent = True
    event.save()
예제 #17
0
def send_monthly_donation_confirmation_email(
    email, confirmation_view_name="monthly_donation_confirm", **kwargs
):
    query_params = {
        "email": email,
        **{k: v for k, v in kwargs.items() if v is not None},
    }
    query_params["token"] = monthly_donation_confirmation_token_generator.make_token(
        **query_params
    )

    confirmation_link = front_url(confirmation_view_name, query=query_params)

    from_email = "La France insoumise <*****@*****.**>"
    template_email = "CONFIRM_SUBSCRIPTION_LFI"

    if (
        "payment_mode" in query_params
        and query_params["payment_mode"] is not None
        and "2022" in query_params["payment_mode"]
    ):
        from_email = "Mélenchon 2022 <*****@*****.**>"
        template_email = "CONFIRM_SUBSCRIPTION_2022"

    send_mosaico_email(
        code=template_email,
        subject="Finalisez votre don mensuel",
        from_email=from_email,
        bindings={"CONFIRM_SUBSCRIPTION_LINK": confirmation_link},
        recipients=[email],
    )
예제 #18
0
    def test_changed_event_notification_mail(self):
        tasks.send_event_changed_notification(self.event.pk,
                                              ["information", "timing"])

        self.assertEqual(len(mail.outbox), 2)

        for message in mail.outbox:
            self.assertEqual(len(message.recipients()), 1)

        messages = {
            message.recipients()[0]: message
            for message in mail.outbox
        }

        self.assertCountEqual(messages.keys(),
                              [self.attendee1.email, self.attendee2.email])

        for recipient, message in messages.items():
            text = message.body.replace("\n", "")

            self.assert_(self.event.name in text, "event name not in message")
            self.assert_(
                front_url("quit_event", kwargs={"pk": self.event.pk}) in text,
                "quit event link not in message",
            )

            self.assert_(str(tasks.CHANGE_DESCRIPTION["information"]) in text)
            self.assert_(str(tasks.CHANGE_DESCRIPTION["timing"]) in text)
            self.assert_(str(tasks.CHANGE_DESCRIPTION["contact"]) not in text)
예제 #19
0
def send_secretariat_notification(event_pk, person_pk, complete=True):
    try:
        event = Event.objects.get(pk=event_pk)
        person = Person.objects.get(pk=person_pk)
    except (Event.DoesNotExist, Person.DoesNotExist):
        return

    from agir.events.admin import EventAdmin

    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,
        "LOCATION_NAME": event.location_name,
        "LOCATION_ADDRESS": event.short_address,
        "EVENT_LINK": front_url("view_event", args=[event.pk]),
        "LEGAL_INFORMATIONS": EventAdmin.legal_informations(event),
    }

    send_mosaico_email(
        code="EVENT_SECRETARIAT_NOTIFICATION",
        subject=_(
            f"Événement {'complété' if complete else 'en attente'} : {str(event)}"
        ),
        from_email=settings.EMAIL_FROM,
        reply_to=[person.email],
        recipients=[settings.EMAIL_SECRETARIAT],
        bindings=bindings,
    )
예제 #20
0
파일: actions.py 프로젝트: nipal/api-django
def admin_summary(spending_request):
    shown_fields = [
        "id",
        "title",
        "status",
        "group",
        "event",
        "category",
        "category_precisions",
        "explanation",
        "amount",
        "spending_date",
        "provider",
        "iban",
    ]

    values = {f: getattr(spending_request, f) for f in shown_fields}

    values["group"] = format_html(
        '<a href="{group_link}">{group_name}</a> ({group_balance})<br><a href="mailto:{group_email}">{group_email}</a><br>{group_phone}',
        group_name=spending_request.group.name,
        group_email=spending_request.group.contact_email,
        group_phone=spending_request.group.contact_phone,
        group_link=front_url("view_group", args=(spending_request.group_id, )),
        group_balance=display_price(get_balance(spending_request.group)),
    )

    values["amount"] = display_price(spending_request.amount)

    return [{
        "label": SpendingRequest._meta.get_field(f).verbose_name,
        "value": values[f]
    } for f in shown_fields]
예제 #21
0
def send_post_event_required_documents_reminder_email(event_pk):
    event = Event.objects.select_related("subtype").get(pk=event_pk)
    organizers = event.organizers.all()
    document_deadline = event.end_time + timedelta(days=15)

    bindings = {
        "EVENT_NAME":
        event.name,
        "DOCUMENTS_LINK":
        front_url("event_project", auto_login=False, kwargs={"pk": event.pk}),
        "DOCUMENT_DEADLINE":
        document_deadline.strftime("%d/%m"),
        "REQUIRED_DOCUMENT_TYPES":
        event.subtype.required_documents,
        "NEEDS_DOCUMENTS":
        len(event.subtype.required_documents) > 0,
    }

    send_mosaico_email(
        code="POST_EVENT_REQUIRED_DOCUMENTS_REMINDER",
        subject=_("Rappel : envoyez les justificatifs de l'événement d'hier"),
        from_email=settings.EMAIL_FROM,
        recipients=[organizer for organizer in organizers],
        bindings=bindings,
    )
예제 #22
0
def send_donation_email(person_pk, payment_type):
    person = Person.objects.prefetch_related("emails").get(pk=person_pk)
    template_code = "DONATION_MESSAGE"
    email_from = settings.EMAIL_FROM

    if (
        payment_type in PAYMENT_TYPES
        and hasattr(PAYMENT_TYPES[payment_type], "email_from")
        and PAYMENT_TYPES[payment_type].email_from
    ):
        email_from = PAYMENT_TYPES[payment_type].email_from

    if (
        payment_type in PAYMENT_TYPES
        and hasattr(PAYMENT_TYPES[payment_type], "email_template_code")
        and PAYMENT_TYPES[payment_type].email_template_code
    ):
        template_code = PAYMENT_TYPES[payment_type].email_template_code

    send_mosaico_email(
        code=template_code,
        subject="Merci d'avoir donné !",
        from_email=email_from,
        bindings={"PROFILE_LINK": front_url("personal_information")},
        recipients=[person],
    )
예제 #23
0
def send_joined_notification_email(membership_pk):
    try:
        membership = Membership.objects.select_related("person", "supportgroup").get(
            pk=membership_pk
        )
    except Membership.DoesNotExist:
        return

    person_information = str(membership.person)

    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 "
        + ("équipe" if membership.supportgroup.is_2022 else "groupe"),
        from_email=settings.EMAIL_FROM,
        recipients=membership.supportgroup.managers,
        bindings=bindings,
    )
예제 #24
0
    def test_create_and_subscribe_with_new_address(self):

        res = self.client.post(
            self.create_donation_session_url,
            {
                "paymentTimes": donations.serializers.TYPE_SINGLE_TIME,
                "amount": "200"
            },
        )
        self.assertEqual(res.status_code, 201)
        self.assertIn(self.information_modal_url, res.data["next"])

        self.donation_information_payload["email"] = "*****@*****.**"
        res = self.client.post(
            self.send_donation_url,
            {
                **self.donation_information_payload, "subscribed2022": True
            },
        )
        payment = Payment.objects.get()
        self.assertEqual(res.status_code, 200)
        self.assertIn(front_url("payment_page", args=(payment.pk, )),
                      res.data["next"])

        self.assertTrue(payment.meta.get("subscribed_2022"))

        # simulate correct payment
        complete_payment(payment)
        donation_notification_listener(payment)

        p2 = Person.objects.exclude(pk=self.p1.pk).get()
        self.assertIn(Person.NEWSLETTER_2022, p2.newsletters)
예제 #25
0
def send_joined_notification_email(membership_pk):
    membership = Membership.objects.select_related(
        "person", "supportgroup").get(pk=membership_pk)
    person_information = str(membership.person)

    recipients = Person.objects.filter(
        notification_subscriptions__membership__supportgroup=membership.
        supportgroup,
        notification_subscriptions__membership__membership_type__gte=Membership
        .MEMBERSHIP_TYPE_MANAGER,
        notification_subscriptions__type=Subscription.SUBSCRIPTION_EMAIL,
        notification_subscriptions__activity_type=Activity.TYPE_NEW_MEMBER,
    )

    if len(recipients) == 0:
        return

    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",
        from_email=settings.EMAIL_FROM,
        recipients=recipients,
        bindings=bindings,
    )
예제 #26
0
def send_external_join_confirmation(group_pk, email, **kwargs):
    try:
        group = SupportGroup.objects.get(pk=group_pk)
    except SupportGroup.DoesNotExist:
        return

    subscription_token = subscription_confirmation_token_generator.make_token(
        email=email, **kwargs)
    confirm_subscription_url = front_url("external_join_group",
                                         args=[group_pk],
                                         auto_login=False)
    query_args = {"email": email, **kwargs, "token": subscription_token}
    confirm_subscription_url += "?" + urlencode(query_args)

    bindings = {
        "GROUP_NAME": group.name,
        "JOIN_LINK": confirm_subscription_url
    }

    send_mosaico_email(
        code="GROUP_EXTERNAL_JOIN_OPTIN",
        subject=_(f"Confirmez que vous souhaitez rejoindre « {group.name} »"),
        from_email=settings.EMAIL_FROM,
        recipients=[email],
        bindings=bindings,
    )
예제 #27
0
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(
        membership_type__gte=Membership.MEMBERSHIP_TYPE_MANAGER)) & 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,
    )
예제 #28
0
 def link(self, object):
     if object.slug:
         return format_html(
             '<a href="{0}">{0}</a>',
             front_url("view_calendar", kwargs={"slug": object.slug}),
         )
     else:
         return "-"
예제 #29
0
 def link(self, object):
     if object.pk:
         return format_html(
             '<a href="{0}">{0}</a>',
             front_url("view_event", kwargs={"pk": object.pk}),
         )
     else:
         return "-"
예제 #30
0
 def simple_link(self, object):
     if object.slug:
         return format_html(
             '<a href="{0}">{0}</a>',
             front_url("view_person_form", args=(object.slug, )),
         )
     else:
         return "-"