diff --git a/src/pretix/control/forms/__init__.py b/src/pretix/control/forms/__init__.py index 6eff11a8c9..d3345b606e 100644 --- a/src/pretix/control/forms/__init__.py +++ b/src/pretix/control/forms/__init__.py @@ -153,7 +153,7 @@ class CachedFileInput(forms.ClearableFileInput): @property def is_img(self): - return any(self.file.filename.lower().endswith(e) for e in ('.jpg', '.jpeg', '.png', '.gif')) + return False # thumbnailing doesn't work since the file isn't available publicly def __str__(self): return self.file.filename diff --git a/src/pretix/plugins/sendmail/forms.py b/src/pretix/plugins/sendmail/forms.py index 80748496aa..0a9a384dec 100644 --- a/src/pretix/plugins/sendmail/forms.py +++ b/src/pretix/plugins/sendmail/forms.py @@ -177,7 +177,7 @@ class MailForm(FormPlaceholderMixin, forms.Form): self.fields['sendto'] = forms.MultipleChoiceField( label=_("Send to customers with order status"), widget=forms.CheckboxSelectMultiple( - attrs={'class': 'scrolling-multiple-choice'} + attrs={'class': 'scrolling-multiple-choice no-search'} ), choices=choices ) 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 2cc6383e92..daca36416a 100644 --- a/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/send_form.html +++ b/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/send_form.html @@ -1,63 +1,103 @@ {% extends "pretixcontrol/event/base.html" %} {% load i18n %} {% load bootstrap3 %} +{% load humanize %} {% block title %}{% trans "Send out emails" %}{% endblock %} {% block content %}

{% trans "Send out emails" %}

{% block inner %}
{% csrf_token %} - {% bootstrap_form_errors form %} - {% bootstrap_field form.recipients layout='horizontal' %} - {% bootstrap_field form.sendto layout='horizontal' %} - {% if form.subevent %} - {% bootstrap_field form.subevent layout='horizontal' %} - {% bootstrap_field form.subevents_from layout='horizontal' %} - {% bootstrap_field form.subevents_to layout='horizontal' %} + {% if is_preview %} + {% for k, l in request.POST.lists %} + {% if k != "action" %} + {% for v in l %} + + {% endfor %} + {% endif %} + {% endfor %} {% endif %} - {% bootstrap_field form.created_from layout='horizontal' %} - {% bootstrap_field form.created_to layout='horizontal' %} - {% bootstrap_field form.items layout='horizontal' %} -
-
-
-
-
- -
-
- {% bootstrap_field form.not_checked_in layout='horizontal' %} - {% bootstrap_field form.checkin_lists layout='horizontal' %} + {% bootstrap_form_errors form %} +
+ {% trans "Recipients" %} + {% bootstrap_field form.recipients layout='horizontal' %} + {% bootstrap_field form.sendto layout='horizontal' %} + {% if form.subevent %} + {% bootstrap_field form.subevent layout='horizontal' %} + {% bootstrap_field form.subevents_from layout='horizontal' %} + {% bootstrap_field form.subevents_to layout='horizontal' %} + {% endif %} + {% bootstrap_field form.created_from layout='horizontal' %} + {% bootstrap_field form.created_to layout='horizontal' %} + {% bootstrap_field form.items layout='horizontal' %} +
+
+
+
+
+ +
+
+ {% bootstrap_field form.not_checked_in layout='horizontal' %} + {% bootstrap_field form.checkin_lists layout='horizontal' %} +
-
- {% bootstrap_field form.subject layout='horizontal' %} - {% bootstrap_field form.message layout='horizontal' %} - {% bootstrap_field form.attachment layout='horizontal' %} - {% if request.method == "POST" %} + +
+ {% trans "Content" %} + {% bootstrap_field form.subject layout='horizontal' %} + {% bootstrap_field form.message layout='horizontal' %} + {% bootstrap_field form.attachment layout='horizontal' %} +
+ {% if is_preview %}
- {% trans "E-mail preview" %} + {% trans "E-mail preview" %}
{% for locale, out in output.items %}
{{ out.subject|safe }}

{{ out.html|safe }} + {% if out.attachment %} +

+ + + {{ out.attachment.filename }} + +

+ {% endif %}
{% endfor %}
{% endif %}
- - + {% if not is_preview %} + {% trans "You need to preview your email before you can send it." %} +    + + {% else %} + + + {% endif %}
{% endblock %} diff --git a/src/pretix/plugins/sendmail/views.py b/src/pretix/plugins/sendmail/views.py index c2d432f20d..4dd76d1a4d 100644 --- a/src/pretix/plugins/sendmail/views.py +++ b/src/pretix/plugins/sendmail/views.py @@ -183,12 +183,16 @@ class SenderView(EventPermissionRequiredMixin, FormView): orders = orders.annotate(match_pos=Exists(opq)).filter(match_pos=True).distinct() + ocnt = orders.count() + self.output = {} - if not orders: + if not ocnt: messages.error(self.request, _('There are no orders matching this selection.')) + self.request.POST = self.request.POST.copy() + self.request.POST.pop("action", "") return self.get(self.request, *self.args, **self.kwargs) - if self.request.POST.get("action") == "preview": + if self.request.POST.get("action") != "send": for l in self.request.event.settings.locales: with language(l, self.request.event.settings.region): context_dict = TolerantDict() @@ -207,8 +211,10 @@ class SenderView(EventPermissionRequiredMixin, FormView): self.output[l] = { 'subject': _('Subject: {subject}').format(subject=preview_subject), 'html': preview_text, + 'attachment': form.cleaned_data.get('attachment') } + self.order_count = ocnt return self.get(self.request, *self.args, **self.kwargs) kwargs = { @@ -244,8 +250,18 @@ class SenderView(EventPermissionRequiredMixin, FormView): def get_context_data(self, *args, **kwargs): ctx = super().get_context_data(*args, **kwargs) ctx['output'] = getattr(self, 'output', None) + ctx['order_count'] = getattr(self, 'order_count', None) + ctx['is_preview'] = self.request.method == 'POST' and self.request.POST.get('action') == 'preview' and ctx['form'].is_valid() return ctx + def get_form(self, form_class=None): + f = super().get_form(form_class) + if self.request.method == 'POST' and self.request.POST.get('action') == 'preview': + if f.is_valid(): + for fname, field in f.fields.items(): + field.widget.attrs['disabled'] = 'disabled' + return f + class EmailHistoryView(EventPermissionRequiredMixin, ListView): template_name = 'pretixplugins/sendmail/history.html' diff --git a/src/tests/plugins/sendmail/test_sendmail.py b/src/tests/plugins/sendmail/test_sendmail.py index 699067824b..0a6857e80a 100644 --- a/src/tests/plugins/sendmail/test_sendmail.py +++ b/src/tests/plugins/sendmail/test_sendmail.py @@ -84,6 +84,7 @@ def test_sendmail_simple_case(logged_in_client, sendmail_url, event, order, pos) djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'na', + 'action': 'send', 'recipients': 'orders', 'items': pos.item_id, 'subject_0': 'Test subject', @@ -110,6 +111,7 @@ def test_sendmail_email_not_sent_if_order_not_match(logged_in_client, sendmail_u djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'p', + 'action': 'send', 'recipients': 'orders', 'items': pos.item_id, 'subject_0': 'Test subject', @@ -144,6 +146,7 @@ def test_sendmail_invalid_data(logged_in_client, sendmail_url, event, order, pos djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'na', + 'action': 'send', 'recipients': 'orders', 'items': pos.item_id, 'subject_0': 'Test subject', @@ -171,6 +174,7 @@ def test_sendmail_multi_locales(logged_in_client, sendmail_url, event, item): response = logged_in_client.post(sendmail_url, {'sendto': 'p', + 'action': 'send', 'recipients': 'orders', 'items': item.pk, 'subject_0': 'Test subject', @@ -209,6 +213,7 @@ def test_sendmail_subevents(logged_in_client, sendmail_url, event, order, pos): djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'na', + 'action': 'send', 'recipients': 'orders', 'items': pos.item_id, 'subject_0': 'Test subject', @@ -223,6 +228,7 @@ def test_sendmail_subevents(logged_in_client, sendmail_url, event, order, pos): djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'na', + 'action': 'send', 'recipients': 'orders', 'items': pos.item_id, 'subject_0': 'Test subject', @@ -268,6 +274,7 @@ def test_sendmail_attendee_mails(logged_in_client, sendmail_url, event, order, p djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'na', + 'action': 'send', 'recipients': 'attendees', 'items': pos.item_id, 'subject_0': 'Test subject', @@ -292,6 +299,7 @@ def test_sendmail_both_mails(logged_in_client, sendmail_url, event, order, pos): djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'na', + 'action': 'send', 'recipients': 'both', 'items': pos.item_id, 'subject_0': 'Test subject', @@ -319,6 +327,7 @@ def test_sendmail_both_but_same_address(logged_in_client, sendmail_url, event, o djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'na', + 'action': 'send', 'recipients': 'both', 'items': pos.item_id, 'subject_0': 'Test subject', @@ -343,6 +352,7 @@ def test_sendmail_attendee_fallback(logged_in_client, sendmail_url, event, order djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'na', + 'action': 'send', 'recipients': 'attendees', 'items': pos.item_id, 'subject_0': 'Test subject', @@ -372,6 +382,7 @@ def test_sendmail_attendee_product_filter(logged_in_client, sendmail_url, event, djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'na', + 'action': 'send', 'recipients': 'attendees', 'items': i2.pk, 'subject_0': 'Test subject', @@ -400,6 +411,7 @@ def test_sendmail_attendee_checkin_filter(logged_in_client, sendmail_url, event, djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'na', + 'action': 'send', 'recipients': 'attendees', 'items': pos2.item_id, 'filter_checkins': 'on', @@ -418,6 +430,7 @@ def test_sendmail_attendee_checkin_filter(logged_in_client, sendmail_url, event, djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'na', + 'action': 'send', 'recipients': 'attendees', 'items': pos2.item_id, 'subject_0': 'Test subject', @@ -437,6 +450,7 @@ def test_sendmail_attendee_checkin_filter(logged_in_client, sendmail_url, event, djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'na', + 'action': 'send', 'recipients': 'attendees', 'items': pos2.item_id, 'subject_0': 'Test subject', @@ -456,6 +470,7 @@ def test_sendmail_attendee_checkin_filter(logged_in_client, sendmail_url, event, djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'na', + 'action': 'send', 'recipients': 'attendees', 'items': pos2.item_id, 'subject_0': 'Test subject', @@ -477,6 +492,7 @@ def test_sendmail_attendee_checkin_filter(logged_in_client, sendmail_url, event, djmail.outbox = [] response = logged_in_client.post(sendmail_url, {'sendto': 'na', + 'action': 'send', 'recipients': 'attendees', 'items': pos2.item_id, 'subject_0': 'Test subject',