diff --git a/bda/management/commands/sendrappels.py b/bda/management/commands/sendrappels.py index 65026736..e852b03a 100644 --- a/bda/management/commands/sendrappels.py +++ b/bda/management/commands/sendrappels.py @@ -22,7 +22,7 @@ class Command(BaseCommand): delay = timedelta(days=4) shows = ( Spectacle.objects.filter(date__range=(now, now + delay)) - .filter(tirage__active=True) + .filter(tirage__active=True, tirage__send_rappels_auto=True) .filter(rappel_sent__isnull=True) .all() ) diff --git a/bda/migrations/0019_tirage_send_rappels_auto.py b/bda/migrations/0019_tirage_send_rappels_auto.py new file mode 100644 index 00000000..c6846fc6 --- /dev/null +++ b/bda/migrations/0019_tirage_send_rappels_auto.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.17 on 2021-01-08 15:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bda", "0018_auto_20201021_1818"), + ] + + operations = [ + migrations.AddField( + model_name="tirage", + name="send_rappels_auto", + field=models.BooleanField( + default=True, verbose_name="Envoi automatique des mails de rappel" + ), + ), + ] diff --git a/bda/models.py b/bda/models.py index 578f235c..df4f91da 100644 --- a/bda/models.py +++ b/bda/models.py @@ -32,6 +32,9 @@ class Tirage(models.Model): ) enable_do_tirage = models.BooleanField("Le tirage peut être lancé", default=False) archived = models.BooleanField("Archivé", default=False) + send_rappels_auto = models.BooleanField( + "Envoi automatique des mails de rappel", default=True + ) def __str__(self): return "%s - %s" % ( diff --git a/bda/urls.py b/bda/urls.py index 5b452362..edfa62bb 100644 --- a/bda/urls.py +++ b/bda/urls.py @@ -1,4 +1,5 @@ from django.conf.urls import url +from django.urls import path from bda import views from bda.views import SpectacleListView @@ -71,4 +72,9 @@ urlpatterns = [ ), url(r"^mails-rappel/(?P\d+)$", views.send_rappel, name="bda-rappels"), url(r"^catalogue/(?P[a-z]+)$", views.catalogue, name="bda-catalogue"), + path( + "toggle-rappels/", + views.toggle_rappels, + name="bda-toggle-rappels", + ), ] diff --git a/bda/views.py b/bda/views.py index a6fb1804..4f468040 100644 --- a/bda/views.py +++ b/bda/views.py @@ -734,6 +734,18 @@ class SpectacleListView(ListView): return context +def toggle_rappels(request, tirage_id): + """ + Permet de désactiver ou de réactiver les envois de mails automatiques pour + les spectacles appartenant à ce tirage. + """ + tirage = get_object_or_404(Tirage, id=tirage_id) + tirage.send_rappels_auto = not tirage.send_rappels_auto + tirage.save() + + return HttpResponseRedirect(reverse("home")) + + class UnpaidParticipants(BuroRequiredMixin, ListView): context_object_name = "unpaid" template_name = "bda-unpaid.html" diff --git a/gestioncof/templates/gestioncof/home.html b/gestioncof/templates/gestioncof/home.html index 45b3e225..b25c2d24 100644 --- a/gestioncof/templates/gestioncof/home.html +++ b/gestioncof/templates/gestioncof/home.html @@ -97,12 +97,14 @@ {% if active_tirages %} {% for tirage in active_tirages %} {% endfor %} {% else %}