Sendmail: Add option to attach calendar invites (#3224)

This commit is contained in:
Michael Stapelberg
2023-04-17 09:38:36 +02:00
committed by GitHub
parent 6aeb82b06a
commit c890f4cdc0
8 changed files with 53 additions and 2 deletions
+5 -1
View File
@@ -218,6 +218,10 @@ class OrderMailForm(BaseMailForm):
help_text=_("Will be ignored if tickets 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 required=False
) )
attach_ical = forms.BooleanField(
label=_("Attach calendar files"),
required=False
)
def clean(self): def clean(self):
d = super().clean() d = super().clean()
@@ -305,7 +309,7 @@ class RuleForm(FormPlaceholderMixin, I18nModelForm):
class Meta: class Meta:
model = Rule model = Rule
fields = ['subject', 'template', fields = ['subject', 'template', 'attach_ical',
'send_date', 'send_offset_days', 'send_offset_time', 'send_date', 'send_offset_days', 'send_offset_time',
'include_pending', 'all_products', 'limit_products', 'include_pending', 'all_products', 'limit_products',
'send_to', 'enabled'] 'send_to', 'enabled']
@@ -0,0 +1,18 @@
# Generated by Django 3.2.18 on 2023-04-13 21:39
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sendmail', '0002_rule_enabled'),
]
operations = [
migrations.AddField(
model_name='rule',
name='attach_ical',
field=models.BooleanField(default=False),
),
]
+8
View File
@@ -153,6 +153,7 @@ class ScheduledMail(models.Model):
email_ctx = get_email_context(event=e, order=o, invoice_address=ia) email_ctx = get_email_context(event=e, order=o, invoice_address=ia)
try: try:
o.send_mail(self.rule.subject, self.rule.template, email_ctx, o.send_mail(self.rule.subject, self.rule.template, email_ctx,
attach_ical=self.rule.attach_ical,
log_entry_type='pretix.plugins.sendmail.rule.order.email.sent') log_entry_type='pretix.plugins.sendmail.rule.order.email.sent')
o_sent = True o_sent = True
except SendMailException: except SendMailException:
@@ -169,10 +170,12 @@ class ScheduledMail(models.Model):
if p.attendee_email and (p.attendee_email != o.email or not o_sent): if p.attendee_email and (p.attendee_email != o.email or not o_sent):
email_ctx = get_email_context(event=e, order=o, invoice_address=ia, position=p) email_ctx = get_email_context(event=e, order=o, invoice_address=ia, position=p)
p.send_mail(self.rule.subject, self.rule.template, email_ctx, p.send_mail(self.rule.subject, self.rule.template, email_ctx,
attach_ical=self.rule.attach_ical,
log_entry_type='pretix.plugins.sendmail.rule.order.position.email.sent') log_entry_type='pretix.plugins.sendmail.rule.order.position.email.sent')
elif not o_sent and o.email: elif not o_sent and o.email:
email_ctx = get_email_context(event=e, order=o, invoice_address=ia) email_ctx = get_email_context(event=e, order=o, invoice_address=ia)
o.send_mail(self.rule.subject, self.rule.template, email_ctx, o.send_mail(self.rule.subject, self.rule.template, email_ctx,
attach_ical=self.rule.attach_ical,
log_entry_type='pretix.plugins.sendmail.rule.order.email.sent') log_entry_type='pretix.plugins.sendmail.rule.order.email.sent')
o_sent = True o_sent = True
except SendMailException: except SendMailException:
@@ -207,6 +210,11 @@ class Rule(models.Model, LoggingMixin):
help_text=_('By default, only paid orders will receive the email') help_text=_('By default, only paid orders will receive the email')
) )
attach_ical = models.BooleanField(
default=False,
verbose_name=_("Attach calendar files"),
)
# either send_date or send_offset_* have to be set # either send_date or send_offset_* have to be set
send_date = models.DateTimeField(null=True, blank=True, verbose_name=_('Send date')) send_date = models.DateTimeField(null=True, blank=True, verbose_name=_('Send date'))
send_offset_days = models.IntegerField(null=True, blank=True, verbose_name=_('Number of days')) send_offset_days = models.IntegerField(null=True, blank=True, verbose_name=_('Number of days'))
+4 -1
View File
@@ -46,7 +46,8 @@ from pretix.helpers.format import format_map
@app.task(base=ProfiledEventTask, acks_late=True) @app.task(base=ProfiledEventTask, acks_late=True)
def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict, objects: list, items: list, def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict, objects: list, items: list,
recipients: str, filter_checkins: bool, not_checked_in: bool, checkin_lists: list, recipients: str, filter_checkins: bool, not_checked_in: bool, checkin_lists: list,
attachments: list = None, attach_tickets: bool = False) -> None: attachments: list = None, attach_tickets: bool = False,
attach_ical: bool = False) -> None:
failures = [] failures = []
user = User.objects.get(pk=user) if user else None user = User.objects.get(pk=user) if user else None
orders = Order.objects.filter(pk__in=objects, event=event) orders = Order.objects.filter(pk__in=objects, event=event)
@@ -110,6 +111,7 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
order=o, order=o,
position=p, position=p,
attach_tickets=attach_tickets, attach_tickets=attach_tickets,
attach_ical=attach_ical,
attach_cached_files=attachments attach_cached_files=attachments
) )
o.log_action( o.log_action(
@@ -138,6 +140,7 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
locale=o.locale, locale=o.locale,
order=o, order=o,
attach_tickets=attach_tickets, attach_tickets=attach_tickets,
attach_ical=attach_ical,
attach_cached_files=attachments, attach_cached_files=attachments,
) )
o.log_action( o.log_action(
@@ -20,6 +20,9 @@
<legend>{% trans "Content" %}</legend> <legend>{% trans "Content" %}</legend>
{% bootstrap_field form.subject layout='control' %} {% bootstrap_field form.subject layout='control' %}
{% bootstrap_field form.template layout='control' %} {% bootstrap_field form.template layout='control' %}
{% if form.attach_ical %}
{% bootstrap_field form.attach_ical layout='horizontal' %}
{% endif %}
</fieldset> </fieldset>
<fieldset> <fieldset>
<legend>{% trans "Recipients" %}</legend> <legend>{% trans "Recipients" %}</legend>
@@ -34,6 +34,9 @@
<legend>{% trans "Content" %}</legend> <legend>{% trans "Content" %}</legend>
{% bootstrap_field form.subject layout='control' %} {% bootstrap_field form.subject layout='control' %}
{% bootstrap_field form.template layout='control' %} {% bootstrap_field form.template layout='control' %}
{% if form.attach_ical %}
{% bootstrap_field form.attach_ical layout='horizontal' %}
{% endif %}
</fieldset> </fieldset>
<fieldset> <fieldset>
<legend>{% trans "Recipients" %}</legend> <legend>{% trans "Recipients" %}</legend>
@@ -33,6 +33,9 @@
{% if form.attach_tickets %} {% if form.attach_tickets %}
{% bootstrap_field form.attach_tickets layout='horizontal' %} {% bootstrap_field form.attach_tickets layout='horizontal' %}
{% endif %} {% endif %}
{% if form.attach_ical %}
{% bootstrap_field form.attach_ical layout='horizontal' %}
{% endif %}
</fieldset> </fieldset>
{% if is_preview %} {% if is_preview %}
<fieldset> <fieldset>
@@ -57,6 +60,12 @@
{% trans "Tickets" %} {% trans "Tickets" %}
</p> </p>
{% endif %} {% endif %}
{% if form.cleaned_data.attach_ical %}
<p>
<span class="fa fa-file" aria-hidden="true"></span>
{% trans "Attach calendar files" %}
</p>
{% endif %}
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
+3
View File
@@ -330,6 +330,8 @@ class OrderSendView(BaseSenderView):
initial['created_to'] = dateutil.parser.parse(logentry.parsed_data['created_to']) initial['created_to'] = dateutil.parser.parse(logentry.parsed_data['created_to'])
if logentry.parsed_data.get('attach_tickets'): if logentry.parsed_data.get('attach_tickets'):
initial['attach_tickets'] = logentry.parsed_data['attach_tickets'] initial['attach_tickets'] = logentry.parsed_data['attach_tickets']
if logentry.parsed_data.get('attach_ical'):
initial['attach_ical'] = logentry.parsed_data['attach_ical']
if logentry.parsed_data.get('subevent'): if logentry.parsed_data.get('subevent'):
try: try:
initial['subevent'] = self.request.event.subevents.get( initial['subevent'] = self.request.event.subevents.get(
@@ -425,6 +427,7 @@ class OrderSendView(BaseSenderView):
'checkin_lists': [i.pk for i in form.cleaned_data.get('checkin_lists')], 'checkin_lists': [i.pk for i in form.cleaned_data.get('checkin_lists')],
'filter_checkins': form.cleaned_data.get('filter_checkins'), 'filter_checkins': form.cleaned_data.get('filter_checkins'),
'attach_tickets': form.cleaned_data.get('attach_tickets'), 'attach_tickets': form.cleaned_data.get('attach_tickets'),
'attach_ical': form.cleaned_data.get('attach_ical'),
}) })
return kwargs return kwargs