Sendmail: Allow to disable rules (#2111)

This commit is contained in:
Julia Luna
2021-06-07 12:40:01 +02:00
committed by GitHub
parent b11ae9e5dd
commit 050f3990c3
8 changed files with 46 additions and 4 deletions

View File

@@ -231,7 +231,7 @@ class RuleForm(FormPlaceholderMixin, I18nModelForm):
fields = ['subject', 'template',
'send_date', 'send_offset_days', 'send_offset_time',
'include_pending', 'all_products', 'limit_products',
'send_to']
'send_to', 'enabled']
field_classes = {
'subevent': SafeModelMultipleChoiceField,

View File

@@ -0,0 +1,18 @@
# Generated by Django 3.2.3 on 2021-06-07 09:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sendmail', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='rule',
name='enabled',
field=models.BooleanField(default=True),
),
]

View File

@@ -201,6 +201,12 @@ class Rule(models.Model):
send_to = models.CharField(max_length=10, choices=SEND_TO_CHOICES, default=CUSTOMERS, verbose_name='Send email to')
enabled = models.BooleanField(
default=True,
verbose_name=_('Enabled'),
help_text=_('Only enabled rules are actually sent')
)
objects = ScopedManager(organizer='event__organizer')
def save(self, **kwargs):

View File

@@ -146,6 +146,7 @@ def sendmail_run_rules(sender, **kwargs):
)
for m_id in mails.filter(
state__in=(ScheduledMail.STATE_SCHEDULED, ScheduledMail.STATE_FAILED),
rule__enabled=True,
computed_datetime__gte=timezone.now() - datetime.timedelta(days=2),
computed_datetime__lte=timezone.now(),
).values_list('pk', flat=True):
@@ -161,7 +162,7 @@ def sendmail_run_rules(sender, **kwargs):
# emails might be sent a second time. This isn't nice, but any solution would either
# require settings some arbitrary timeout for a process or risk not sending some
# emails at all. Under the assumption that system-level failures are rare and (more
# importantly) usually don't happen multiple times in a row, this seems liek a
# importantly) usually don't happen multiple times in a row, this seems like a
# good tradeoff.
# - We never retry for more than two days.

View File

@@ -9,6 +9,8 @@
{% csrf_token %}
{% bootstrap_form_errors form %}
{% bootstrap_field form.enabled layout='control' %}
<fieldset>
<legend>{% trans "Content" %}</legend>
{% bootstrap_field form.subject layout='control' %}

View File

@@ -6,7 +6,7 @@
<h1>{% trans "Automated email rules" %}</h1>
<p>
{% blocktrans trimmed %}
Email rules allow you to automatically sent emails to your customers at a specific time before or after
Email rules allow you to automatically send emails to your customers at a specific time before or after
your event.
{% endblocktrans %}
</p>
@@ -31,9 +31,11 @@
</thead>
<tbody>
{% for r in rules %}
<tr>
<tr{% if not r.enabled %} class="row-muted"{% endif %}>
<td>
{% if not r.enabled %}<strike>{% endif %}
<strong><a href="{% url "plugins:sendmail:rule.update" organizer=request.organizer.slug event=request.event.slug rule=r.pk %}">{{ r.subject }}</a></strong>
{% if not r.enabled %}</strike>{% endif %}
</td>
<td>
{{ r.get_send_to_display }}

View File

@@ -10,6 +10,8 @@
{% csrf_token %}
{% bootstrap_form_errors form %}
{% bootstrap_field form.enabled layout='control' %}
<fieldset>
<legend>{% trans "Content" %}</legend>
{% bootstrap_field form.subject layout='control' %}