Fixed #42 -- Configurable e-mail texts

This commit is contained in:
Raphael Michel
2015-12-13 17:33:38 +01:00
parent 1e72c58219
commit d8ca0d527e
15 changed files with 1224 additions and 900 deletions

View File

@@ -13,6 +13,12 @@ from pretix.base.models import Event
logger = logging.getLogger('pretix.base.mail')
class TolerantDict(dict):
def __missing__(self, key):
return key
def mail(email: str, subject: str, template: str,
context: Dict[str, Any]=None, event: Event=None, locale: str=None):
"""
@@ -22,9 +28,11 @@ def mail(email: str, subject: str, template: str,
:param subject: The e-mail subject. Should be localized.
:param template: The filename of a template to be used. It will
be rendered with the recipient's locale. Alternatively, you
can pass a LazyI18nString and leave ``context`` empty
can pass a LazyI18nString and ``context`` will be used
for a Python .format() call.
:param context: The context for rendering the template.
:param event: The event, used for determining the sender of the e-mail
:param locale: The locale used while rendering the template
:return: ``False`` on obvious failures, like the user having to e-mail
address, ``True`` otherwise. ``True`` does not necessarily mean that
@@ -37,6 +45,8 @@ def mail(email: str, subject: str, template: str,
if isinstance(template, LazyI18nString):
body = str(template)
if context:
body = body.format_map(TolerantDict(context))
else:
tpl = get_template(template)
body = tpl.render(context)

View File

@@ -4,6 +4,7 @@ from django.conf import settings
from django.db import transaction
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from pretix.base.i18n import LazyDate, LazyNumber
from typing import List
from pretix.base.models import (
@@ -71,10 +72,9 @@ def mark_order_paid(order: Order, provider: str=None, info: str=None, date: date
mail(
order.email, _('Payment received for your order: %(code)s') % {'code': order.code},
'pretixpresale/email/order_paid.txt',
order.event.settings.mail_text_order_paid,
{
'order': order,
'event': order.event,
'event': order.event.name,
'url': build_absolute_uri(order.event, 'presale:event.order', kwargs={
'order': order.code,
'secret': order.secret
@@ -217,15 +217,17 @@ def _perform_order(event: str, payment_provider: str, position_ids: List[str],
mail(
order.email, _('Your order: %(code)s') % {'code': order.code},
'pretixpresale/email/order_placed.txt',
event.settings.mail_text_order_placed,
{
'order': order,
'event': event,
'total': LazyNumber(order.total),
'currency': event.currency,
'date': LazyDate(order.expires),
'event': event.name,
'url': build_absolute_uri(event, 'presale:event.order', kwargs={
'order': order.code,
'secret': order.secret
}),
'payment': pprov.order_pending_mail_render(order)
'paymentinfo': str(pprov.order_pending_mail_render(order))
},
event, locale=order.locale
)