Ou comment faire plaisir à pylint sur les bouts de code concernés
par cette MR
This commit is contained in:
Martin Pépin 2016-11-20 16:39:26 +01:00
parent 03f7dff813
commit f93b095e0f
6 changed files with 77 additions and 41 deletions

View file

@ -29,7 +29,8 @@ class Tirage(models.Model):
default=False)
def __str__(self):
return "%s - %s" % (self.title, formats.localize(timezone.template_localtime(self.fermeture)))
return "%s - %s" % (self.title, formats.localize(
timezone.template_localtime(self.fermeture)))
@python_2_unicode_compatible
@ -91,6 +92,10 @@ class Spectacle(models.Model):
)
def send_rappel(self):
"""
Envoie un mail de rappel à toutes les personnes qui ont une place pour
ce spectacle.
"""
# On récupère la liste des participants
members = {}
for attr in Attribution.objects.filter(spectacle=self).all():
@ -107,14 +112,14 @@ class Spectacle(models.Model):
mail_object = str(self)
for member in members.values():
mail_body = loader.render_to_string('bda/mails/rappel.txt', {
'name': member[0],
'nb_attr': member[1],
'show': self})
'name': member[0],
'nb_attr': member[1],
'show': self})
mail_tot = mail.EmailMessage(
mail_object, mail_body,
settings.MAIL_DATA['rappels']['FROM'], [member[2]],
[], headers={
'Reply-To': settings.MAIL_DATA['rappels']['REPLYTO']})
mail_object, mail_body,
settings.MAIL_DATA['rappels']['FROM'], [member[2]],
[], headers={
'Reply-To': settings.MAIL_DATA['rappels']['REPLYTO']})
mails_to_send.append(mail_tot)
# On envoie les mails
connection = mail.get_connection()
@ -267,16 +272,16 @@ class SpectacleRevente(models.Model):
mail_object = "%s" % (self.attribution.spectacle)
for participant in inscrits:
mail_body = loader.render_to_string('bda/mails/revente.txt', {
'user': participant.user,
'spectacle': self.attribution.spectacle,
'revente': self,
'domain': Site.objects.get_current().domain})
'user': participant.user,
'spectacle': self.attribution.spectacle,
'revente': self,
'domain': Site.objects.get_current().domain})
mail_tot = mail.EmailMessage(
mail_object, mail_body,
settings.MAIL_DATA['revente']['FROM'],
[participant.user.email],
[], headers={
'Reply-To': settings.MAIL_DATA['revente']['REPLYTO']})
mail_object, mail_body,
settings.MAIL_DATA['revente']['FROM'],
[participant.user.email],
[], headers={
'Reply-To': settings.MAIL_DATA['revente']['REPLYTO']})
mails_to_send.append(mail_tot)
connection = mail.get_connection()
@ -285,22 +290,26 @@ class SpectacleRevente(models.Model):
self.save()
def mail_shotgun(self):
"""
Envoie un mail à toutes les personnes intéréssées par le spectacle pour
leur indiquer qu'il est désormais disponible au shotgun.
"""
inscrits = self.attribution.spectacle.subscribed.select_related('user')
mails_to_send = []
mail_object = "%s" % (self.attribution.spectacle)
for participant in inscrits:
mail_body = loader.render_to_string('bda/mails/shotgun.txt', {
'user': participant.user,
'spectacle': self.attribution.spectacle,
'domain': Site.objects.get_current(),
'mail': self.attribution.participant.user.email})
'user': participant.user,
'spectacle': self.attribution.spectacle,
'domain': Site.objects.get_current(),
'mail': self.attribution.participant.user.email})
mail_tot = mail.EmailMessage(
mail_object, mail_body,
settings.MAIL_DATA['revente']['FROM'],
[participant.user.email],
[], headers={
'Reply-To': settings.MAIL_DATA['revente']['REPLYTO']})
mail_object, mail_body,
settings.MAIL_DATA['revente']['FROM'],
[participant.user.email],
[], headers={
'Reply-To': settings.MAIL_DATA['revente']['REPLYTO']})
mails_to_send.append(mail_tot)
connection = mail.get_connection()
@ -309,6 +318,11 @@ class SpectacleRevente(models.Model):
self.save()
def tirage(self):
"""
Lance le tirage au sort associé à la revente. Un gagnant est choisi
parmis les personnes intéressées par le spectacle. Les personnes sont
ensuites prévenues par mail du résultat du tirage.
"""
inscrits = list(self.answered_mail.all())
spectacle = self.attribution.spectacle
seller = self.seller
@ -327,14 +341,16 @@ class SpectacleRevente(models.Model):
}
mails.append(mail.EmailMessage(
mail_subject,
loader.render_to_string('bda/mails/revente-winner.txt', context),
loader.render_to_string('bda/mails/revente-winner.txt',
context),
from_email=settings.MAIL_DATA['revente']['FROM'],
to=[winner.user.email],
reply_to=[seller.user.email],
))
mails.append(mail.EmailMessage(
mail_subject,
loader.render_to_string('bda/mails/revente-seller.txt', context),
loader.render_to_string('bda/mails/revente-seller.txt',
context),
from_email=settings.MAIL_DATA['revente']['FROM'],
to=[seller.user.email],
reply_to=[winner.user.email],
@ -345,11 +361,12 @@ class SpectacleRevente(models.Model):
if inscrit == winner:
continue
mail_body = loader.render_to_string('bda/mails/revente-loser.txt', {
'acheteur': inscrit.user,
'vendeur': seller.user,
'spectacle': spectacle,
})
mail_body = loader.render_to_string(
'bda/mails/revente-loser.txt',
{'acheteur': inscrit.user,
'vendeur': seller.user,
'spectacle': spectacle}
)
mails.append(mail.EmailMessage(
mail_subject, mail_body,
from_email=settings.MAIL_DATA['revente']['FROM'],