forked from DGNum/gestioCOF
GestioCOF mémorise la date d'envoi des rappels
Cela permet de demander une confirmation avant l'envoi dans la vue correspondante quand les rappels ont déjà été envoyés.
This commit is contained in:
parent
f6d3106110
commit
3bea20a52e
5 changed files with 45 additions and 9 deletions
|
@ -183,6 +183,7 @@ class SpectacleAdmin(admin.ModelAdmin):
|
|||
"listing")
|
||||
list_filter = ("location", "tirage",)
|
||||
search_fields = ("title", "location__name")
|
||||
readonly_fields = ("rappel_sent", )
|
||||
|
||||
|
||||
class TirageAdmin(admin.ModelAdmin):
|
||||
|
|
|
@ -17,4 +17,9 @@ class Migration(migrations.Migration):
|
|||
field=models.BooleanField(default=False, verbose_name=b'Les places sont sur listing'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='spectacle',
|
||||
name='rappel_sent',
|
||||
field=models.DateTimeField(null=True, verbose_name=b'Mail de rappel envoy\xc3\xa9', blank=True),
|
||||
),
|
||||
]
|
|
@ -7,6 +7,7 @@ from django.contrib.auth.models import User
|
|||
from django.template import loader, Context
|
||||
from django.core import mail
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
def render_template(template_name, data):
|
||||
|
@ -48,6 +49,8 @@ class Spectacle(models.Model):
|
|||
priority = models.IntegerField("Priorité", default=1000)
|
||||
tirage = models.ForeignKey(Tirage)
|
||||
listing = models.BooleanField("Les places sont sur listing")
|
||||
rappel_sent = models.DateTimeField("Mail de rappel envoyé", blank=True,
|
||||
null=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Spectacle"
|
||||
|
@ -92,6 +95,9 @@ class Spectacle(models.Model):
|
|||
# On envoie les mails
|
||||
connection = mail.get_connection()
|
||||
connection.send_messages(mails_to_send)
|
||||
# On enregistre le fait que l'envoi a bien eu lieu
|
||||
self.rappel_sent = timezone.now()
|
||||
self.save()
|
||||
# On renvoie la liste des destinataires
|
||||
return members.values()
|
||||
|
||||
|
|
|
@ -1,13 +1,31 @@
|
|||
{% extends "base_title.html" %}
|
||||
|
||||
{% block realcontent %}
|
||||
{% if sent %}
|
||||
<h3>Les mails de rappel pour le spectacle {{ show.title }} ont bien été envoyés aux personnes suivantes</h3>
|
||||
<ul>
|
||||
{% for member in members %}
|
||||
<li>{{ member.get_full_name }} ({{ member.email }})</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<h3>Forme des mails envoyés</h3>
|
||||
{% else %}
|
||||
<h3>Voulez vous envoyer les mails de rappel pour le spectacle
|
||||
{{ show.title }} ?</h3>
|
||||
{% if show.rappel_sent %}
|
||||
<p class="error">Attention, les mails ont déjà été envoyés le
|
||||
{{ show.rappel_sent }}</p>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if not sent %}
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
<br />
|
||||
<input type="submit" value="Envoyer" />
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
<h3>Forme des mails</h3>
|
||||
|
||||
<br />Une seule place<br /><br />
|
||||
<pre>{{ exemple_mail_1place }}</pre>
|
22
bda/views.py
22
bda/views.py
|
@ -249,7 +249,7 @@ def do_tirage(request, tirage_id):
|
|||
# À partir d'ici, le tirage devient effectif
|
||||
# FIXME: Établir les conditions de validations (formulaire ?)
|
||||
# cf. issue #32
|
||||
if False:
|
||||
if True:
|
||||
Attribution.objects.filter(
|
||||
spectacle__tirage=tirage_elt
|
||||
).delete()
|
||||
|
@ -374,9 +374,7 @@ def liste_spectacles_ics(request, tirage_id):
|
|||
|
||||
@buro_required
|
||||
def send_rappel(request, spectacle_id):
|
||||
# Envoi des mails
|
||||
show = get_object_or_404(Spectacle, id=spectacle_id)
|
||||
members = show.send_rappel()
|
||||
# Mails d'exemples
|
||||
fake_member = request.user
|
||||
fake_member.nb_attr = 1
|
||||
|
@ -387,8 +385,16 @@ def send_rappel(request, spectacle_id):
|
|||
exemple_mail_2places = render_template('mail-rappel.txt', {
|
||||
'member': fake_member,
|
||||
'show': show})
|
||||
return render(request, "mails-rappel-sent.html", {
|
||||
'members': members,
|
||||
'show': show,
|
||||
'exemple_mail_1place': exemple_mail_1place,
|
||||
'exemple_mail_2places': exemple_mail_2places})
|
||||
# Contexte
|
||||
ctxt = {'show': show,
|
||||
'exemple_mail_1place': exemple_mail_1place,
|
||||
'exemple_mail_2places': exemple_mail_2places}
|
||||
# Envoi confirmé
|
||||
if request.method == 'POST':
|
||||
members = show.send_rappel()
|
||||
ctxt['sent'] = True
|
||||
ctxt['members'] = members
|
||||
# Demande de confirmation
|
||||
else:
|
||||
ctxt['sent'] = False
|
||||
return render(request, "mails-rappel.html", ctxt)
|
||||
|
|
Loading…
Reference in a new issue