Exemplo n.º 1
0
def send_invoice(invoice: Invoice, request=None):
    context = get_substitutions_templates()
    context["invoice"] = invoice
    context["event"] = invoice.company_event.event
    context["user"] = invoice.responsible_company
    template = get_notification_template(method="email",
                                         type="sponsorship",
                                         task="invoice",
                                         format="html")
    subject = get_notification_template(
        method="email", type="sponsorship", task="invoice",
        format="subject").format(event_name=str(invoice.company_event.event))
    body = render_to_string(template, context)
    attachments = [(
        invoice.invoice.name[invoice.invoice.name.rfind("/") + 1:],
        invoice.invoice.read(),
        "application/pdf",
    )]

    send_email(
        subject=subject,
        body=body,
        to=invoice.responsible_company.email,
        tags=[MailTag.INVOICE],
        attachments=attachments,
    )

    invoice.mark_as_sent(request=request)
Exemplo n.º 2
0
def send_subscriber_new(subscriber: Subscriber, event: Event = None):
    context = get_substitutions_templates()
    context["subscriber"] = subscriber
    if event:
        context["event"] = event
    template = get_notification_template(
        method="email", type="subscribe", task="new", format="html"
    )
    subject = get_notification_template(
        method="email", type="subscribe", task="new", format="subject"
    )
    body = render_to_string(template, context)

    print("HMMM")

    save_message_with_email(
        (event.id if event else None),
        subscriber.email,
        subject,
        body,
        MessageType.SUBSCRIBED,
    )

    send_email(
        subject=subject, body=body, to=subscriber.email, tags=[MailTag.SUBSCRIBE]
    )
Exemplo n.º 3
0
def send_url_email(registration_id: UUID):
    context = get_substitutions_templates()
    registration = Registration.objects.get(id=registration_id)
    context["registration"] = registration
    context["user"] = registration.user

    if registration.status in [
            RegistrationStatus.REGISTERED,
            RegistrationStatus.JOINED,
            RegistrationStatus.ATTENDED,
    ]:
        template = get_notification_template(method="email",
                                             app="event",
                                             task="url",
                                             format="html")
        subject = get_notification_template(method="email",
                                            app="event",
                                            task="url",
                                            format="subject")
        body = render_to_string(template, context)

        subject = subject.format(event=registration.event.name)

        send_email(subject=subject,
                   body=body,
                   to=registration.user.email,
                   tags=[MailTag.EVENT])
Exemplo n.º 4
0
def send_registration_email(registration_id: UUID):
    context = get_substitutions_templates()
    registration = Registration.objects.get(id=registration_id)
    context["registration"] = registration
    context["user"] = registration.user

    if registration.status in [
            RegistrationStatus.REQUESTED,
            RegistrationStatus.REGISTERED,
    ]:
        task = "register"
    elif registration.status == RegistrationStatus.CANCELLED:
        task = "cancel"
    else:
        task = None

    if task:
        template = get_notification_template(method="email",
                                             app="event",
                                             task=task,
                                             format="html")
        subject = get_notification_template(method="email",
                                            app="event",
                                            task=task,
                                            format="subject")
        body = render_to_string(template, context)

        subject = subject.format(event=registration.event.name)

        send_email(subject=subject,
                   body=body,
                   to=registration.user.email,
                   tags=[MailTag.EVENT])
Exemplo n.º 5
0
def send_verify_email(user: User, verify_key: str):
    context = get_substitutions_templates()
    context["user"] = user
    context["verify_key"] = verify_key
    context["event"] = get_next_or_past_event()
    template = get_notification_template(
        method="email", type="signup", task="verify", format="html"
    )
    subject = get_notification_template(
        method="email", type="signup", task="verify", format="subject"
    )
    body = render_to_string(template, context)

    send_email(subject=subject, body=body, to=user.email, tags=[MailTag.VERIFY])
Exemplo n.º 6
0
def send_slack_email(user_id: UUID):
    context = get_substitutions_templates()
    user = User.objects.get(id=user_id)
    context["user"] = user
    template = get_notification_template(method="email",
                                         app="user",
                                         task="slack",
                                         format="html")
    subject = get_notification_template(method="email",
                                        app="user",
                                        task="slack",
                                        format="subject")
    body = render_to_string(template, context)

    send_email(subject=subject, body=body, to=user.email, tags=[MailTag.SLACK])
Exemplo n.º 7
0
def send_subscriber_resubscribed(subscriber: Subscriber, event: Event = None):
    context = get_substitutions_templates()
    context["subscriber"] = subscriber
    if event:
        context["event"] = event
    template = get_notification_template(method="email",
                                         type="subscribe",
                                         task="resubscribe",
                                         format="html")
    subject = get_notification_template(method="email",
                                        type="subscribe",
                                        task="resubscribe",
                                        format="subject")
    body = render_to_string(template, context)

    send_email(subject=subject,
               body=body,
               to=subscriber.email,
               tags=[MailTag.SUBSCRIBE])