mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
Sendmail: Allow to notify a date range of subevents
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _, pgettext_lazy
|
||||
from django_scopes.forms import SafeModelMultipleChoiceField
|
||||
@@ -6,6 +7,7 @@ from i18nfield.forms import I18nFormField, I18nTextarea, I18nTextInput
|
||||
|
||||
from pretix.base.email import get_available_placeholders
|
||||
from pretix.base.forms import PlaceholderValidator
|
||||
from pretix.base.forms.widgets import SplitDateTimePickerWidget
|
||||
from pretix.base.models import CheckinList, Item, Order, SubEvent
|
||||
from pretix.control.forms import ExtFileField
|
||||
from pretix.control.forms.widgets import Select2, Select2Multiple
|
||||
@@ -53,6 +55,24 @@ class MailForm(forms.Form):
|
||||
required=False,
|
||||
empty_label=pgettext_lazy('subevent', 'All dates')
|
||||
)
|
||||
subevents_from = forms.SplitDateTimeField(
|
||||
widget=SplitDateTimePickerWidget(),
|
||||
label=pgettext_lazy('subevent', 'Only send to customers of dates starting at or after'),
|
||||
required=False,
|
||||
)
|
||||
subevents_to = forms.SplitDateTimeField(
|
||||
widget=SplitDateTimePickerWidget(),
|
||||
label=pgettext_lazy('subevent', 'Only send to customers of dates starting before'),
|
||||
required=False,
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
d = super().clean()
|
||||
if d.get('subevent') and d.get('subevents_from'):
|
||||
raise ValidationError(pgettext_lazy('subevent', 'Please either select a specific date or a date range, not both.'))
|
||||
if bool(d.get('subevents_from')) != bool(d.get('subevents_to')):
|
||||
raise ValidationError(pgettext_lazy('subevent', 'If you set a date range, please set both a start and an end.'))
|
||||
return d
|
||||
|
||||
def _set_field_placeholders(self, fn, base_parameters):
|
||||
phs = [
|
||||
@@ -145,3 +165,5 @@ class MailForm(forms.Form):
|
||||
self.fields['subevent'].widget.choices = self.fields['subevent'].choices
|
||||
else:
|
||||
del self.fields['subevent']
|
||||
del self.fields['subevents_from']
|
||||
del self.fields['subevents_to']
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
{% endif %}
|
||||
{% if log.pdata.subevent_obj %}
|
||||
<br/><span class="fa fa-calendar fa-fw"></span> {{ log.pdata.subevent_obj }}
|
||||
{% elif log.pdata.subevents_from %}
|
||||
<br/><span class="fa fa-calendar fa-fw"></span> {{ log.pdata.subevents_from }} – {{ log.pdata.subevents_to }}
|
||||
{% endif %}
|
||||
{% if log.pdata.recipients == "attendees" %}
|
||||
<br/><span class="fa fa-envelope fa-fw"></span> {% trans "Attendee contact addresses" %}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
{% 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.items layout='horizontal' %}
|
||||
<div class="row">
|
||||
|
||||
@@ -2,6 +2,7 @@ import logging
|
||||
from datetime import timedelta
|
||||
|
||||
import bleach
|
||||
import dateutil
|
||||
from django.contrib import messages
|
||||
from django.db.models import Exists, OuterRef, Q
|
||||
from django.http import Http404
|
||||
@@ -60,6 +61,10 @@ class SenderView(EventPermissionRequiredMixin, FormView):
|
||||
)
|
||||
kwargs['initial']['filter_checkins'] = logentry.parsed_data.get('filter_checkins', False)
|
||||
kwargs['initial']['not_checked_in'] = logentry.parsed_data.get('not_checked_in', False)
|
||||
if logentry.parsed_data.get('subevents_from'):
|
||||
kwargs['initial']['subevents_from'] = dateutil.parser.parse(logentry.parsed_data['subevents_from'])
|
||||
if logentry.parsed_data.get('subevents_to'):
|
||||
kwargs['initial']['subevents_to'] = dateutil.parser.parse(logentry.parsed_data['subevents_to'])
|
||||
if logentry.parsed_data.get('subevent'):
|
||||
try:
|
||||
kwargs['initial']['subevent'] = self.request.event.subevents.get(
|
||||
@@ -105,6 +110,10 @@ class SenderView(EventPermissionRequiredMixin, FormView):
|
||||
|
||||
if form.cleaned_data.get('subevent'):
|
||||
opq = opq.filter(subevent=form.cleaned_data.get('subevent'))
|
||||
if form.cleaned_data.get('subevents_from'):
|
||||
opq = opq.filter(subevent__date_from__gte=form.cleaned_data.get('subevents_from'))
|
||||
if form.cleaned_data.get('subevents_to'):
|
||||
opq = opq.filter(subevent__date_from__lt=form.cleaned_data.get('subevents_to'))
|
||||
|
||||
orders = orders.annotate(match_pos=Exists(opq)).filter(match_pos=True).distinct()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user