Localize ical attachments (Z#23227987)

This commit is contained in:
Kara Engelhardt
2026-03-17 12:01:19 +01:00
committed by pajowu
parent bb8f50a4df
commit d475cba820
2 changed files with 40 additions and 10 deletions

View File

@@ -512,16 +512,17 @@ def mail_send_task(self, **kwargs) -> bool:
# Attach calendar files # Attach calendar files
if outgoing_mail.should_attach_ical and outgoing_mail.order: if outgoing_mail.should_attach_ical and outgoing_mail.order:
fname = re.sub('[^a-zA-Z0-9 ]', '-', unidecode(pgettext('attachment_filename', 'Calendar invite'))) with language(outgoing_mail.order.locale, outgoing_mail.event.settings.region):
icals = get_private_icals( fname = re.sub('[^a-zA-Z0-9 ]', '-', unidecode(pgettext('attachment_filename', 'Calendar invite')))
outgoing_mail.event, icals = get_private_icals(
[outgoing_mail.orderposition] if outgoing_mail.orderposition else outgoing_mail.order.positions.all() outgoing_mail.event,
) [outgoing_mail.orderposition] if outgoing_mail.orderposition else outgoing_mail.order.positions.all()
for i, cal in enumerate(icals): )
name = '{}{}.ics'.format(fname, f'-{i + 1}' if i > 0 else '') for i, cal in enumerate(icals):
content = cal.serialize() name = '{}{}.ics'.format(fname, f'-{i + 1}' if i > 0 else '')
mimetype = 'text/calendar' content = cal.serialize()
email.attach(name, content, mimetype) mimetype = 'text/calendar'
email.attach(name, content, mimetype)
invoices_to_mark_transmitted = [] invoices_to_mark_transmitted = []
for inv in outgoing_mail.should_attach_invoices.all(): for inv in outgoing_mail.should_attach_invoices.all():

View File

@@ -562,3 +562,32 @@ def test_escaped_braces_mail_services(env):
for part in (html, plain, djmail.outbox[0].subject): for part in (html, plain, djmail.outbox[0].subject):
assert "EUR" not in part assert "EUR" not in part
assert "-{currency}-" in part assert "-{currency}-" in part
@pytest.mark.django_db
def test_attached_ical_localization(env, order):
event, _, _ = env
descriptions = {"de": "german description", "en": "english description"}
event.settings.mail_attach_ical_description = LazyI18nString(descriptions)
event.settings.mail_attach_ical = True
event.settings.mail_attach_ical_paid_only = False
for locale, description in descriptions.items():
order.locale = locale
order.save()
djmail.outbox = []
mail(
"dummy@dummy.dummy",
"",
LazyI18nString(""),
event=event,
order=order,
attach_ical=True
)
assert len(djmail.outbox) == 1
assert len(djmail.outbox[0].attachments) == 1
assert description in djmail.outbox[0].attachments[0][1]