Esempio n. 1
0
 def wasa2il_url(self, *args, **kwargs):
     from icepirate.utils import wasa2il_url
     return wasa2il_url(self, *args, **kwargs)
Esempio n. 2
0
    def get_bodies(message, recipient, with_html=True):
        body, html_body = message.body, None

        for field in (
            "ssn",
            "name",
            "username",
            "email",
            "phone",
            "added",
            "legal_name",
            "legal_address",
            "legal_zip_code",
            "legal_municipality_code",
        ):
            data = unicode(getattr(recipient, field))
            body = body.replace("{{%s}}" % field, data)

        # When embedding the following URLs into e-mails, we force them to
        # count as verified; this e-mail effectively becomes a verification
        # mail in disguise.
        if "{{wasa2il_url}}" in body:
            data = wasa2il_url(recipient, verified=True)
            body = body.replace("{{wasa2il_url}}", data)
        if "{{wasa2il_url_short}}" in body:
            data = wasa2il_url(recipient, verified=True, shorten=True)
            body = body.replace("{{wasa2il_url_short}}", data)

        if message.generate_html_mail and with_html:
            html_body = markdown(body)

        rejection_body = None
        try:
            rejection_message = InteractiveMessage.objects.get(interactive_type="reject_email_messages")

            if not recipient.temporary_web_id:
                random_string = generate_unique_random_string()
                recipient.temporary_web_id = random_string
                recipient.save()

            rejection_body = rejection_message.produce_links(recipient.temporary_web_id)

            body += "\n\n------------------------------\n"
            body += rejection_body

        except InteractiveMessage.DoesNotExist:
            pass

        if html_body:
            try:
                html_template = InteractiveMessage.objects.get(interactive_type="email_html_template")

                html_body = html_template.render_body(
                    recipient.temporary_web_id, message_content=html_body, footer_content=rejection_body
                )

            except InteractiveMessage.DoesNotExist:
                # If we have no HTML template, hard-code the basics.
                html_body += '\n<div class="icepirate_footer"><hr>\n%s\n</div>\n' % markdown(rejection_body)

            html_body = ("<html><body>\n%s\n</body></html>" % html_body).replace("\r", "").replace("\n", "\r\n")

        return body, html_body or None