From 981ff48e3d8e232816ac743d357704b71fd32605 Mon Sep 17 00:00:00 2001 From: Basile Clement Date: Sat, 5 Nov 2016 22:35:46 +0100 Subject: [PATCH] Envoie un mail de confirmation lors d'une mise en vente Ce mail contient la date du tirage. --- bda/templates/mail-revente-new.txt | 13 +++++++++++ bda/views.py | 37 ++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 bda/templates/mail-revente-new.txt diff --git a/bda/templates/mail-revente-new.txt b/bda/templates/mail-revente-new.txt new file mode 100644 index 00000000..ffba3083 --- /dev/null +++ b/bda/templates/mail-revente-new.txt @@ -0,0 +1,13 @@ +Bonjour {{ vendeur.first_name }}, + +Tu t’es bien inscrit-e pour la revente de {{ spectacle.title }}. + +{% with revente.expiration_time as time %} +Le tirage au sort entre tout-e-s les racheteuse-eur-s potentiel-le-s aura lieu +le {{ time|date:"DATE_FORMAT" }} à {{ time|time:"TIME_FORMAT" }} (dans {{time|timeuntil }}). +Si personne ne s’est inscrit pour racheter la place, celle-ci apparaitra parmi +les « Places disponibles immédiatement à la revente » sur GestioCOF. +{% endwith %} + +Bonne revente ! +Le Bureau des Arts diff --git a/bda/views.py b/bda/views.py index 756525f2..8beeb84b 100644 --- a/bda/views.py +++ b/bda/views.py @@ -8,15 +8,17 @@ import random from django.shortcuts import render, get_object_or_404 from django.contrib.auth.decorators import login_required -from django.db import models +from django.db import models, transaction from django.db.models import Count, Q -from django.core import serializers +from django.core import serializers, mail from django.forms.models import inlineformset_factory from django.http import HttpResponseBadRequest, HttpResponseRedirect from django.core.urlresolvers import reverse +from django.conf import settings import hashlib from django.core.mail import send_mail +from django.template import loader from django.utils import timezone from django.views.generic.list import ListView @@ -292,15 +294,30 @@ def revente(request, tirage_id): resellform = ResellForm(participant, request.POST, prefix='resell') annulform = AnnulForm(participant, prefix='annul') if resellform.is_valid(): + mails = [] attributions = resellform.cleaned_data["attributions"] - for attribution in attributions: - revente, created = SpectacleRevente.objects.get_or_create( - attribution=attribution, - defaults={'seller': participant}) - if not created: - revente.seller = participant - revente.date = timezone.now() - revente.save() + with transaction.atomic(): + for attribution in attributions: + revente, created = SpectacleRevente.objects.get_or_create( + attribution=attribution, + defaults={'seller': participant}) + if not created: + revente.seller = participant + revente.date = timezone.now() + mail_subject = "BdA-Revente : {:s}".format(attribution.spectacle.title) + mail_body = loader.render_to_string('mail-revente-new.txt', { + 'vendeur': participant.user, + 'spectacle': attribution.spectacle, + 'revente': revente, + }) + mails.append(mail.EmailMessage( + mail_subject, mail_body, + from_email=settings.MAIL_DATA['revente']['FROM'], + to=[participant.user.email], + reply_to=[settings.MAIL_DATA['revente']['REPLYTO']], + )) + revente.save() + mail.get_connection().send_messages(mails) elif 'annul' in request.POST: annulform = AnnulForm(participant, request.POST, prefix='annul')