示例#1
0
    def send_email(self):
        subject, template = self.type.get_email_template(self)
        context = self.type.get_email_context(self)

        if subject and template:
            send_template_email(
                self.user.email,
                f"[{self.org.name}] {subject}",
                template,
                context,
                self.org.get_branding(),
            )
        else:  # pragma: no cover
            logger.warning(
                f"skipping email send for notification type {self.type.slug} not configured for email"
            )

        self.email_status = Notification.EMAIL_STATUS_SENT
        self.save(update_fields=("email_status", ))
示例#2
0
    def form_valid(self, form):
        from .type import MailgunType

        branding = self.org.get_branding()
        domain = self.org.get_branding()["ticket_domain"]
        api_key = settings.MAILGUN_API_KEY
        verification_code = self.request.session["verification_code"]

        # step 1, they entered their email, off to verify
        if isinstance(form, ConnectView.EmailForm):
            to_address = form.cleaned_data["to_address"]
            subject = _("Verify your email address for tickets")
            template = "tickets/types/mailgun/verify_email"
            context = {"verification_code": verification_code}
            send_template_email(to_address, subject, template, context,
                                self.request.branding)

            self.request.session["to_address"] = to_address
            return HttpResponseRedirect(
                reverse("tickets.types.mailgun.connect") + "?verify=true")

        # delete code so it can't be re-used
        del self.request.session["verification_code"]

        to_address = self.request.session["to_address"]
        config = {
            MailgunType.CONFIG_DOMAIN: domain,
            MailgunType.CONFIG_API_KEY: api_key,
            MailgunType.CONFIG_TO_ADDRESS: to_address,
            MailgunType.CONFIG_BRAND_NAME: branding["name"],
            MailgunType.CONFIG_URL_BASE: branding["link"],
        }

        self.object = Ticketer.create(
            org=self.org,
            user=self.request.user,
            ticketer_type=MailgunType.slug,
            config=config,
            name=to_address,
        )

        return super().form_valid(form)