Files
@ 7fac10241ec7
Branch filter:
Location: symposion_app/vendor/symposion/utils/mail.py - annotation
7fac10241ec7
1.8 KiB
text/x-python
Improve attendee reports
Display attendee profile data in normal table without DataTables so
sorting is not applied, causing data to be confusing to read.
Include item quantity in attendee data report for accurate schwag packing.
Display attendee profile data in normal table without DataTables so
sorting is not applied, causing data to be confusing to read.
Include item quantity in attendee data report for accurate schwag packing.
d54d47487ecc d54d47487ecc db95cb618099 db95cb618099 db95cb618099 db95cb618099 db95cb618099 db95cb618099 db95cb618099 db95cb618099 96683b6d7dba 96683b6d7dba d54d47487ecc 96683b6d7dba 96683b6d7dba 96683b6d7dba 96683b6d7dba d54d47487ecc d54d47487ecc d54d47487ecc d54d47487ecc 96683b6d7dba d54d47487ecc d54d47487ecc d54d47487ecc d54d47487ecc 96683b6d7dba d54d47487ecc 96683b6d7dba d54d47487ecc d54d47487ecc 96683b6d7dba d54d47487ecc d54d47487ecc d54d47487ecc 36ab6d599ffc db95cb618099 36ab6d599ffc db95cb618099 db95cb618099 db95cb618099 db95cb618099 db95cb618099 d54d47487ecc d54d47487ecc db95cb618099 db95cb618099 d54d47487ecc db95cb618099 36ab6d599ffc d54d47487ecc db95cb618099 36ab6d599ffc db95cb618099 36ab6d599ffc 6fadca1773a2 db95cb618099 db95cb618099 | import os
from django.conf import settings
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
from django.utils.html import strip_tags
from django.contrib.sites.models import Site
class Sender(object):
''' Class for sending e-mails under a templete prefix. '''
def __init__(self, template_prefix):
self.template_prefix = template_prefix
def send_email(self, to, kind, **kwargs):
''' Sends an e-mail to the given address.
to: The address
kind: the ID for an e-mail kind; it should point to a subdirectory of
self.template_prefix containing subject.txt and message.html, which
are django templates for the subject and HTML message respectively.
context: a context for rendering the e-mail.
'''
return __send_email__(self.template_prefix, to, kind, **kwargs)
send_email = Sender("symposion/emails").send_email
def __send_email__(template_prefix, to, kind, **kwargs):
current_site = Site.objects.get_current()
ctx = {
"current_site": current_site,
"STATIC_URL": settings.STATIC_URL,
}
ctx.update(kwargs.get("context", {}))
subject_template = os.path.join(template_prefix, "%s/subject.txt" % kind)
message_template = os.path.join(template_prefix, "%s/message.html" % kind)
subject = "[%s] %s" % (
current_site.name,
render_to_string(subject_template, ctx).strip()
)
message_html = render_to_string(message_template, ctx)
message_plaintext = strip_tags(message_html)
from_email = settings.DEFAULT_FROM_EMAIL
email = EmailMultiAlternatives(subject, message_plaintext, from_email, to)
email.attach_alternative(message_html, "text/html")
email.send()
|