forked from CGM_Public/pretix_original
Sendmail: Add option to attach calendar invites (#3224)
This commit is contained in:
committed by
GitHub
parent
6aeb82b06a
commit
c890f4cdc0
@@ -218,6 +218,10 @@ class OrderMailForm(BaseMailForm):
|
||||
help_text=_("Will be ignored if tickets exceed a given size limit to ensure email deliverability."),
|
||||
required=False
|
||||
)
|
||||
attach_ical = forms.BooleanField(
|
||||
label=_("Attach calendar files"),
|
||||
required=False
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
d = super().clean()
|
||||
@@ -305,7 +309,7 @@ class RuleForm(FormPlaceholderMixin, I18nModelForm):
|
||||
class Meta:
|
||||
model = Rule
|
||||
|
||||
fields = ['subject', 'template',
|
||||
fields = ['subject', 'template', 'attach_ical',
|
||||
'send_date', 'send_offset_days', 'send_offset_time',
|
||||
'include_pending', 'all_products', 'limit_products',
|
||||
'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),
|
||||
),
|
||||
]
|
||||
@@ -153,6 +153,7 @@ class ScheduledMail(models.Model):
|
||||
email_ctx = get_email_context(event=e, order=o, invoice_address=ia)
|
||||
try:
|
||||
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')
|
||||
o_sent = True
|
||||
except SendMailException:
|
||||
@@ -169,10 +170,12 @@ class ScheduledMail(models.Model):
|
||||
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)
|
||||
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')
|
||||
elif not o_sent and o.email:
|
||||
email_ctx = get_email_context(event=e, order=o, invoice_address=ia)
|
||||
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')
|
||||
o_sent = True
|
||||
except SendMailException:
|
||||
@@ -207,6 +210,11 @@ class Rule(models.Model, LoggingMixin):
|
||||
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
|
||||
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'))
|
||||
|
||||
@@ -46,7 +46,8 @@ from pretix.helpers.format import format_map
|
||||
@app.task(base=ProfiledEventTask, acks_late=True)
|
||||
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,
|
||||
attachments: list = None, attach_tickets: bool = False) -> None:
|
||||
attachments: list = None, attach_tickets: bool = False,
|
||||
attach_ical: bool = False) -> None:
|
||||
failures = []
|
||||
user = User.objects.get(pk=user) if user else None
|
||||
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,
|
||||
position=p,
|
||||
attach_tickets=attach_tickets,
|
||||
attach_ical=attach_ical,
|
||||
attach_cached_files=attachments
|
||||
)
|
||||
o.log_action(
|
||||
@@ -138,6 +140,7 @@ def send_mails_to_orders(event: Event, user: int, subject: dict, message: dict,
|
||||
locale=o.locale,
|
||||
order=o,
|
||||
attach_tickets=attach_tickets,
|
||||
attach_ical=attach_ical,
|
||||
attach_cached_files=attachments,
|
||||
)
|
||||
o.log_action(
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
<legend>{% trans "Content" %}</legend>
|
||||
{% bootstrap_field form.subject layout='control' %}
|
||||
{% bootstrap_field form.template layout='control' %}
|
||||
{% if form.attach_ical %}
|
||||
{% bootstrap_field form.attach_ical layout='horizontal' %}
|
||||
{% endif %}
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{% trans "Recipients" %}</legend>
|
||||
|
||||
@@ -34,6 +34,9 @@
|
||||
<legend>{% trans "Content" %}</legend>
|
||||
{% bootstrap_field form.subject layout='control' %}
|
||||
{% bootstrap_field form.template layout='control' %}
|
||||
{% if form.attach_ical %}
|
||||
{% bootstrap_field form.attach_ical layout='horizontal' %}
|
||||
{% endif %}
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{% trans "Recipients" %}</legend>
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
{% if form.attach_tickets %}
|
||||
{% bootstrap_field form.attach_tickets layout='horizontal' %}
|
||||
{% endif %}
|
||||
{% if form.attach_ical %}
|
||||
{% bootstrap_field form.attach_ical layout='horizontal' %}
|
||||
{% endif %}
|
||||
</fieldset>
|
||||
{% if is_preview %}
|
||||
<fieldset>
|
||||
@@ -57,6 +60,12 @@
|
||||
{% trans "Tickets" %}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if form.cleaned_data.attach_ical %}
|
||||
<p>
|
||||
<span class="fa fa-file" aria-hidden="true"></span>
|
||||
{% trans "Attach calendar files" %}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
@@ -330,6 +330,8 @@ class OrderSendView(BaseSenderView):
|
||||
initial['created_to'] = dateutil.parser.parse(logentry.parsed_data['created_to'])
|
||||
if logentry.parsed_data.get('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'):
|
||||
try:
|
||||
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')],
|
||||
'filter_checkins': form.cleaned_data.get('filter_checkins'),
|
||||
'attach_tickets': form.cleaned_data.get('attach_tickets'),
|
||||
'attach_ical': form.cleaned_data.get('attach_ical'),
|
||||
})
|
||||
return kwargs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user