mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Sendmail: Force preview and show number of orders (#2099)
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -1,63 +1,103 @@
|
||||
{% extends "pretixcontrol/event/base.html" %}
|
||||
{% load i18n %}
|
||||
{% load bootstrap3 %}
|
||||
{% load humanize %}
|
||||
{% block title %}{% trans "Send out emails" %}{% endblock %}
|
||||
{% block content %}
|
||||
<h1>{% trans "Send out emails" %}</h1>
|
||||
{% block inner %}
|
||||
<form class="form-horizontal" method="post" action="" enctype="multipart/form-data">
|
||||
{% 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 %}
|
||||
<input type="hidden" name="{{ k }}" value="{{ v }}">
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% bootstrap_field form.created_from layout='horizontal' %}
|
||||
{% bootstrap_field form.created_to layout='horizontal' %}
|
||||
{% bootstrap_field form.items layout='horizontal' %}
|
||||
<div class="row">
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<div class="panel-group">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<label data-toggle="collapse" data-target="#checkin_filter">
|
||||
{{ form.filter_checkins }} {{ form.filter_checkins.label }}
|
||||
</label>
|
||||
</div>
|
||||
<div id="checkin_filter" class="panel-body panel-collapse collapse {% if form.filter_checkins.value %} in {% else %} out {% endif %}">
|
||||
{% bootstrap_field form.not_checked_in layout='horizontal' %}
|
||||
{% bootstrap_field form.checkin_lists layout='horizontal' %}
|
||||
{% bootstrap_form_errors form %}
|
||||
<fieldset>
|
||||
<legend>{% trans "Recipients" %}</legend>
|
||||
{% 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' %}
|
||||
<div class="row">
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<div class="panel-group">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<label data-toggle="collapse" data-target="#checkin_filter">
|
||||
{{ form.filter_checkins }} {{ form.filter_checkins.label }}
|
||||
</label>
|
||||
</div>
|
||||
<div id="checkin_filter" class="panel-body panel-collapse collapse {% if form.filter_checkins.value %} in {% else %} out {% endif %}">
|
||||
{% bootstrap_field form.not_checked_in layout='horizontal' %}
|
||||
{% bootstrap_field form.checkin_lists layout='horizontal' %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% bootstrap_field form.subject layout='horizontal' %}
|
||||
{% bootstrap_field form.message layout='horizontal' %}
|
||||
{% bootstrap_field form.attachment layout='horizontal' %}
|
||||
{% if request.method == "POST" %}
|
||||
</fieldset>
|
||||
<fieldset {% if is_preview %}class="hidden"{% endif %}>
|
||||
<legend>{% trans "Content" %}</legend>
|
||||
{% bootstrap_field form.subject layout='horizontal' %}
|
||||
{% bootstrap_field form.message layout='horizontal' %}
|
||||
{% bootstrap_field form.attachment layout='horizontal' %}
|
||||
</fieldset>
|
||||
{% if is_preview %}
|
||||
<fieldset>
|
||||
<legend>{% trans "E-mail preview" %}</legend>
|
||||
<legend>{% trans "E-mail preview" %}</legend>
|
||||
<div class="tab-pane mail-preview-group">
|
||||
{% for locale, out in output.items %}
|
||||
<div lang="{{ locale }}" class="mail-preview">
|
||||
<strong>{{ out.subject|safe }}</strong><br><br>
|
||||
{{ out.html|safe }}
|
||||
{% if out.attachment %}
|
||||
<p>
|
||||
<a href="{% url 'cachedfile.download' id=out.attachment.id %}" class="btn btn-default"
|
||||
target="_blank">
|
||||
<span class="fa fa-file" aria-hidden="true"></span>
|
||||
{{ out.attachment.filename }}
|
||||
</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
<div class="form-group submit-group">
|
||||
<button type="submit" class="btn btn-default btn-save pull-left" name="action" value="preview">
|
||||
{% trans "Preview email" %}
|
||||
</button>
|
||||
<button type="submit" class="btn btn-primary btn-save">
|
||||
{% trans "Send" %}
|
||||
</button>
|
||||
{% if not is_preview %}
|
||||
{% trans "You need to preview your email before you can send it." %}
|
||||
|
||||
<button type="submit" class="btn btn-default btn-save" name="action" value="preview">
|
||||
{% trans "Preview email" %}
|
||||
</button>
|
||||
{% else %}
|
||||
<button type="submit" class="btn btn-default btn-save pull-left" name="action" value="edit">
|
||||
<span class="fa fa-edit" aria-hidden="true"></span>
|
||||
{% trans "Edit" %}
|
||||
</button>
|
||||
<button type="submit" class="btn btn-danger btn-save" name="action" value="send">
|
||||
<span class="fa fa-send" aria-hidden="true"></span>
|
||||
{% trans "Send" %}
|
||||
({% blocktrans trimmed with number=order_count|default_if_none:0|intcomma count c=order_count|default_if_none:0 %}
|
||||
{{ number }} matching order
|
||||
{% plural %}
|
||||
{{ number }} matching orders
|
||||
{% endblocktrans %})
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user