Remove duplicate rendering of plain content without variables

This commit is contained in:
Raphael Michel
2026-02-13 10:37:27 +01:00
parent 2d2663f15f
commit 88c9f8c047

View File

@@ -254,20 +254,20 @@ def mail(email: Union[str, Sequence[str]], subject: str, template: Union[str, La
if event and attach_tickets and not event.settings.mail_attach_tickets: if event and attach_tickets and not event.settings.mail_attach_tickets:
attach_tickets = False attach_tickets = False
with language(locale): with language(locale), override(timezone):
if isinstance(context, dict) and order: if isinstance(context, dict) and order:
_autoextend_context(context, order) _autoextend_context(context, order)
# Build raw content # Build raw content
body_plain = render_mail(template, context, placeholder_mode=None) content_plain = render_mail(template, context, placeholder_mode=None)
if settings_holder: if settings_holder:
signature = str(settings_holder.settings.get('mail_text_signature')) signature = str(settings_holder.settings.get('mail_text_signature'))
else: else:
signature = "" signature = ""
# Build full plain-text body # Build full plain-text body
body_plain = format_map(content_plain, context, mode=SafeFormatter.MODE_RICH_TO_PLAIN)
body_plain = _wrap_plain_body(body_plain, signature, event, order, position, no_order_links) body_plain = _wrap_plain_body(body_plain, signature, event, order, position, no_order_links)
body_plain = format_map(body_plain, context, mode=SafeFormatter.MODE_RICH_TO_PLAIN)
# Build subject # Build subject
if not isinstance(subject, FormattedString): if not isinstance(subject, FormattedString):
@@ -291,26 +291,24 @@ def mail(email: Union[str, Sequence[str]], subject: str, template: Union[str, La
else: else:
renderer = ClassicMailRenderer(None, organizer) renderer = ClassicMailRenderer(None, organizer)
with override(timezone): try:
content_plain = render_mail(template, context, placeholder_mode=None) if 'context' in inspect.signature(renderer.render).parameters:
try: body_html = renderer.render(content_plain, signature, raw_subject, order, position, context)
if 'context' in inspect.signature(renderer.render).parameters: elif 'position' in inspect.signature(renderer.render).parameters:
body_html = renderer.render(content_plain, signature, raw_subject, order, position, context) # Backwards compatibility
elif 'position' in inspect.signature(renderer.render).parameters: warnings.warn('Email renderer called without context argument because context argument is not '
# Backwards compatibility 'supported.',
warnings.warn('Email renderer called without context argument because context argument is not ' DeprecationWarning)
'supported.', body_html = renderer.render(content_plain, signature, raw_subject, order, position)
DeprecationWarning) else:
body_html = renderer.render(content_plain, signature, raw_subject, order, position) # Backwards compatibility
else: warnings.warn('Email renderer called without position argument because position argument is not '
# Backwards compatibility 'supported.',
warnings.warn('Email renderer called without position argument because position argument is not ' DeprecationWarning)
'supported.', body_html = renderer.render(content_plain, signature, raw_subject, order)
DeprecationWarning) except:
body_html = renderer.render(content_plain, signature, raw_subject, order) logger.exception('Could not render HTML body')
except: body_html = None
logger.exception('Could not render HTML body')
body_html = None
m = OutgoingMail.objects.create( m = OutgoingMail.objects.create(
organizer=organizer, organizer=organizer,
@@ -941,7 +939,7 @@ def _wrap_plain_body(content_plain, signature, event, order, position, no_order_
body_plain += "\r\n\r\n-- \r\n" body_plain += "\r\n\r\n-- \r\n"
if signature: if signature:
signature = signature.format(event=event.name if event else '') signature = format_map(signature, {"event": event.name if event else ''})
body_plain += signature body_plain += signature
body_plain += "\r\n\r\n-- \r\n" body_plain += "\r\n\r\n-- \r\n"
@@ -953,7 +951,7 @@ def _wrap_plain_body(content_plain, signature, event, order, position, no_order_
body_plain += _( body_plain += _(
"You can view your order details at the following URL:\n{orderurl}." "You can view your order details at the following URL:\n{orderurl}."
).replace("\n", "\r\n").format( ).replace("\n", "\r\n").format(
event=event.name, orderurl=build_absolute_uri( orderurl=build_absolute_uri(
order.event, 'presale:event.order.position', kwargs={ order.event, 'presale:event.order.position', kwargs={
'order': order.code, 'order': order.code,
'secret': position.web_secret, 'secret': position.web_secret,