gère les places demandées

This commit is contained in:
Ludovic Stephan 2016-09-04 11:14:09 +02:00
parent a607f35342
commit e9e0be7960
4 changed files with 59 additions and 1 deletions

View file

@ -6,6 +6,7 @@ from __future__ import unicode_literals
import calendar
import datetime
import random
from django.db import models
from django.contrib.auth.models import User
@ -256,3 +257,34 @@ class SpectacleRevente(models.Model):
connection = mail.get_connection()
connection.send_messages(mails_to_send)
def tirage(self):
inscrits = self.interested
spectacle = self.attribution.spectacle
user = self.attribution.participant.user
if inscrits.exists():
idx = random.randint(0, inscrits.count() - 1)
winner = inscrits.all()[idx]
self.soldTo = winner
mail_buyer = """Bonjour,
Tu as été tiré-e au sort pour racheter une place pour %s le %s (%s) à %0.02f.
Tu peux contacter le vendeur à l'adresse %s.
Chaleureusement,
Le BdA""" % (spectacle.title, spectacle.date_no_seconds(),
spectacle.location, spectacle.price, user.email)
mail.send_mail("BdA-Revente : %s" % spectacle.title,
mail_buyer, "bda@ens.fr", [winner.user.email],
fail_silently=False)
mail_seller = """Bonjour,
La personne tirée au sort pour racheter ta place pour %s est %s.
Tu peux le/la contacter à l'adresse %s.
Chaleureusement,
Le BdA""" % (spectacle.title, winner.user.get_full_name(), winner.user.email)
mail.send_mail("BdA-Revente : %s" % spectacle.title,
mail_seller, "bda@ens.fr", [user.email],
fail_silently=False)