Sendmail: Allow to attach tickets to emails

This commit is contained in:
Raphael Michel
2022-02-16 10:42:48 +01:00
parent f7d2645e76
commit f3b355e9f3
5 changed files with 20 additions and 3 deletions

View File

@@ -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(

View File

@@ -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()

View File

@@ -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(

View File

@@ -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' %}
</fieldset>
{% if is_preview %}
<fieldset>
@@ -65,12 +66,18 @@
{% if out.attachment %}
<p>
<a href="{% url 'cachedfile.download' id=out.attachment.id %}" class="btn btn-default"
target="_blank">
target="_blank">
<span class="fa fa-file" aria-hidden="true"></span>
{{ out.attachment.filename }}
</a>
</p>
{% endif %}
{% if form.cleaned_data.attach_tickets %}
<p>
<span class="fa fa-file" aria-hidden="true"></span>
{% trans "Tickets" %}
</p>
{% endif %}
</div>
{% endfor %}
</div>

View File

@@ -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: