From f3b355e9f32e3d5b6396c2dfa91b0077df33cfcf Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 16 Feb 2022 10:42:48 +0100 Subject: [PATCH] Sendmail: Allow to attach tickets to emails --- src/pretix/control/forms/orders.py | 2 +- src/pretix/plugins/sendmail/forms.py | 5 +++++ src/pretix/plugins/sendmail/tasks.py | 4 +++- .../templates/pretixplugins/sendmail/send_form.html | 9 ++++++++- src/pretix/plugins/sendmail/views.py | 3 +++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/pretix/control/forms/orders.py b/src/pretix/control/forms/orders.py index 7011c3efc..f22bdd643 100644 --- a/src/pretix/control/forms/orders.py +++ b/src/pretix/control/forms/orders.py @@ -612,7 +612,7 @@ class OrderMailForm(forms.Form): ) attach_tickets = forms.BooleanField( label=_("Attach tickets"), - help_text=_("Will be ignored if all tickets in this order exceed a given size limit to ensure email deliverability."), + help_text=_("Will be ignored if tickets exceed a given size limit to ensure email deliverability."), required=False ) attach_invoices = forms.ModelMultipleChoiceField( diff --git a/src/pretix/plugins/sendmail/forms.py b/src/pretix/plugins/sendmail/forms.py index c90881654..67109e77d 100644 --- a/src/pretix/plugins/sendmail/forms.py +++ b/src/pretix/plugins/sendmail/forms.py @@ -132,6 +132,11 @@ class MailForm(FormPlaceholderMixin, forms.Form): label=pgettext_lazy('subevent', 'Only send to customers with orders created before'), required=False, ) + attach_tickets = forms.BooleanField( + label=_("Attach tickets"), + help_text=_("Will be ignored if tickets exceed a given size limit to ensure email deliverability."), + required=False + ) def clean(self): d = super().clean() diff --git a/src/pretix/plugins/sendmail/tasks.py b/src/pretix/plugins/sendmail/tasks.py index 15e8b5422..db4fe861c 100644 --- a/src/pretix/plugins/sendmail/tasks.py +++ b/src/pretix/plugins/sendmail/tasks.py @@ -45,7 +45,7 @@ from pretix.celery_app import app @app.task(base=ProfiledEventTask, acks_late=True) def send_mails(event: Event, user: int, subject: dict, message: dict, orders: list, items: list, recipients: str, filter_checkins: bool, not_checked_in: bool, checkin_lists: list, - attachments: list = None) -> None: + attachments: list = None, attach_tickets: bool = False) -> None: failures = [] user = User.objects.get(pk=user) if user else None orders = Order.objects.filter(pk__in=orders, event=event) @@ -97,6 +97,7 @@ def send_mails(event: Event, user: int, subject: dict, message: dict, orders: li locale=o.locale, order=o, position=p, + attach_tickets=attach_tickets, attach_cached_files=attachments ) o.log_action( @@ -124,6 +125,7 @@ def send_mails(event: Event, user: int, subject: dict, message: dict, orders: li event, locale=o.locale, order=o, + attach_tickets=attach_tickets, attach_cached_files=attachments ) o.log_action( diff --git a/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/send_form.html b/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/send_form.html index daca36416..4250aa6c7 100644 --- a/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/send_form.html +++ b/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/send_form.html @@ -53,6 +53,7 @@ {% bootstrap_field form.subject layout='horizontal' %} {% bootstrap_field form.message layout='horizontal' %} {% bootstrap_field form.attachment layout='horizontal' %} + {% bootstrap_field form.attach_tickets layout='horizontal' %} {% if is_preview %}
@@ -65,12 +66,18 @@ {% if out.attachment %}

+ target="_blank"> {{ out.attachment.filename }}

{% endif %} + {% if form.cleaned_data.attach_tickets %} +

+ + {% trans "Tickets" %} +

+ {% endif %} {% endfor %} diff --git a/src/pretix/plugins/sendmail/views.py b/src/pretix/plugins/sendmail/views.py index 6cd296edf..962c08210 100644 --- a/src/pretix/plugins/sendmail/views.py +++ b/src/pretix/plugins/sendmail/views.py @@ -108,6 +108,8 @@ class SenderView(EventPermissionRequiredMixin, FormView): kwargs['initial']['created_from'] = dateutil.parser.parse(logentry.parsed_data['created_from']) if logentry.parsed_data.get('created_to'): kwargs['initial']['created_to'] = dateutil.parser.parse(logentry.parsed_data['created_to']) + if logentry.parsed_data.get('attach_tickets'): + kwargs['initial']['attach_tickets'] = logentry.parsed_data['attach_tickets'] if logentry.parsed_data.get('subevent'): try: kwargs['initial']['subevent'] = self.request.event.subevents.get( @@ -229,6 +231,7 @@ class SenderView(EventPermissionRequiredMixin, FormView): 'not_checked_in': form.cleaned_data.get('not_checked_in'), 'checkin_lists': [i.pk for i in form.cleaned_data.get('checkin_lists')], 'filter_checkins': form.cleaned_data.get('filter_checkins'), + 'attach_tickets': form.cleaned_data.get('attach_tickets'), } attachment = form.cleaned_data.get('attachment') if attachment is not None and attachment is not False: