Exemplo n.º 1
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.º 2
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.º 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 get_invoice_file(self,
                      verification_control=None,
                      verification_code=None):
     template = get_template("file/invoice.html")
     html = template.render(context=dict(
         invoice=self,
         **get_substitutions_templates(),
         verification_control=verification_control,
         verification_code=verification_code,
     ))
     return weasyprint.HTML(string=html).write_pdf()
Exemplo n.º 6
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.º 7
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.º 8
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])
def render_mail(template_prefix, recipient_email, substitutions,
                from_email=FROM_EMAIL, action_required=False):
    """
    Renders an e-mail to `email`.  `template_prefix` identifies the
    e-mail that is to be sent, e.g. "account/email/email_confirmation"
    """
    substitutions.update(utils.get_substitutions_templates())
    subject = render_to_string('{0}_subject.txt'.format(template_prefix),
                               context=Context(substitutions))
    # remove superfluous line breaks
    subject = " ".join(subject.splitlines()).strip()
    prefix = '[' + settings.HACKATHON_NAME + ']'
    if action_required:
        prefix = '[ACTION REQUIRED]'
    subject = prefix + ' ' + subject
    substitutions.update({'subject': subject})

    bodies = {}
    for ext in ['html', 'txt']:
        try:
            template_name = '{0}_message.{1}'.format(template_prefix, ext)
            bodies[ext] = render_to_string(template_name,
                                           Context(substitutions)).strip()
        except TemplateDoesNotExist:
            if ext == 'txt' and not bodies:
                # We need at least one body
                raise
    if 'txt' in bodies:
        msg = EmailMultiAlternatives(subject,
                                     bodies['txt'],
                                     from_email,
                                     [recipient_email])
        if 'html' in bodies:
            msg.attach_alternative(bodies['html'], 'text/html')
    else:
        msg = EmailMessage(subject,
                           bodies['html'],
                           from_email,
                           [recipient_email])
        msg.content_subtype = 'html'  # Main content is now text/html
    return msg
Exemplo n.º 10
0
def variables_processor(request):
    c = get_substitutions_templates()
    from event.utils.utils import get_next_or_past_event, get_application

    event = get_next_or_past_event()
    if event:
        c["event"] = event
        c["background_video"] = event.background.name[-4:] == ".mp4"
        c["background_image"] = event.background.name[-4:] in [
            ".png",
            ".jpg",
            ".jpeg",
            ".gif",
            ".svg",
        ]
        application = get_application(event.id, request.user.id)
        if application:
            c["application"] = application
        if request.user.is_authenticated:
            c["to_review"] = is_application_to_review(request.user.id)
    return c
Exemplo n.º 11
0
def render_mail(template_prefix,
                recipient_email,
                substitutions,
                from_email=FROM_EMAIL,
                action_required=False):
    """
    Renders an e-mail to `email`.  `template_prefix` identifies the
    e-mail that is to be sent, e.g. "account/email/email_confirmation"
    """
    substitutions.update(utils.get_substitutions_templates())
    subject = render_to_string('{0}_subject.txt'.format(template_prefix),
                               context=substitutions)
    # remove superfluous line breaks
    subject = " ".join(subject.splitlines()).strip()
    prefix = '[' + settings.HACKATHON_NAME + ']'
    if action_required:
        prefix = '[ACTION REQUIRED]'
    subject = prefix + ' ' + subject
    substitutions.update({'subject': subject})

    bodies = {}
    for ext in ['html', 'txt']:
        try:
            template_name = '{0}_message.{1}'.format(template_prefix, ext)
            bodies[ext] = render_to_string(template_name,
                                           substitutions).strip()
        except TemplateDoesNotExist:
            if ext == 'txt' and not bodies:
                # We need at least one body
                raise
    if 'txt' in bodies:
        msg = EmailMultiAlternatives(subject, bodies['txt'], from_email,
                                     [recipient_email])
        if 'html' in bodies:
            msg.attach_alternative(bodies['html'], 'text/html')
    else:
        msg = EmailMessage(subject, bodies['html'], from_email,
                           [recipient_email])
        msg.content_subtype = 'html'  # Main content is now text/html
    return msg
Exemplo n.º 12
0
def variables_processor(request=None):
    c = get_substitutions_templates(request=request)
    from news.utils import get_latest_articles
    from event.utils import get_future_events, get_events
    from user.utils import get_organisers, get_board, get_histories
    from page.utils import get_menu_pages
    from business.utils import get_sponsorships, get_offers

    from event.enums import StreamingProviderDict
    from user.enums import GenderTypeDict, GenderTypeColoursDict
    from business.enums import OfferTypeDict

    c["articles"] = get_latest_articles()
    c["events"] = get_future_events()
    if not c["events"]:
        c["events"] = get_events()
    c["organisers"] = get_organisers()
    c["board"] = get_board()
    c["categories"] = get_menu_pages()
    c["histories"] = get_histories()
    c["sponsorships"] = get_sponsorships()
    c["offers"] = get_offers()

    c["enums"] = {
        "event": {
            "streaming_provider": StreamingProviderDict
        },
        "user": {
            "gender": GenderTypeDict,
            "gender_colours": GenderTypeColoursDict
        },
        "business": {
            "offer_type": OfferTypeDict
        },
    }

    return c
Exemplo n.º 13
0
def variables_processor(request=None):
    c = get_substitutions_templates()
    return c
Exemplo n.º 14
0
 def get_letter_file(self):
     template = get_template("file/letter.html")
     html = template.render(
         context=dict(letter=self, **get_substitutions_templates()))
     return weasyprint.HTML(string=html).write_pdf()