Styling
Ou comment faire plaisir à pylint sur les bouts de code concernés par cette MR
This commit is contained in:
parent
03f7dff813
commit
f93b095e0f
|
@ -1,14 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Gestion en ligne de commande des reventes.
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from datetime import timedelta
|
||||
from django.core.management import BaseCommand
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
from bda.models import SpectacleRevente
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
Objet `BaseCommand`, cf ``self.help`` pour plus d'informations.
|
||||
"""
|
||||
help = "Envoie les mails de notification et effectue " \
|
||||
"les tirages au sort des reventes"
|
||||
leave_locale_alone = True
|
||||
|
@ -19,21 +26,21 @@ class Command(BaseCommand):
|
|||
for revente in reventes:
|
||||
# Check si < 24h
|
||||
if (revente.attribution.spectacle.date <=
|
||||
revente.date + timedelta(days=1)) and \
|
||||
now >= revente.date + timedelta(minutes=15) and \
|
||||
revente.date + timedelta(days=1)) and \
|
||||
now >= revente.date + timedelta(minutes=15) and \
|
||||
not revente.notif_sent:
|
||||
self.stdout.write(str(now))
|
||||
revente.mail_shotgun()
|
||||
self.stdout.write("Mail de disponibilité immédiate envoyé")
|
||||
# Check si délai de retrait dépassé
|
||||
elif (now >= revente.date + timedelta(hours=1) and
|
||||
not revente.notif_sent):
|
||||
not revente.notif_sent):
|
||||
self.stdout.write(str(now))
|
||||
revente.send_notif()
|
||||
self.stdout.write("Mail d'inscription à une revente envoyé")
|
||||
# Check si tirage à faire
|
||||
elif (now >= revente.expiration_time and
|
||||
not revente.tirage_done):
|
||||
not revente.tirage_done):
|
||||
self.stdout.write(str(now))
|
||||
revente.tirage()
|
||||
self.stdout.write("Tirage effectué, mails envoyés")
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Gestion en ligne de commande des mails de rappel.
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from datetime import timedelta
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
from bda.models import Spectacle
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
Objet Command, cf ``self.help`` pour plus d'informations.
|
||||
"""
|
||||
help = 'Envoie les mails de rappel des spectacles dont la date ' \
|
||||
'approche.\nNe renvoie pas les mails déjà envoyés.'
|
||||
leave_locale_alone = True
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -4,7 +4,7 @@ Une place pour le spectacle {{ spectacle.title }} ({{ spectacle.date }})
|
|||
a été postée sur BdA-Revente.
|
||||
|
||||
Puisque ce spectacle a lieu dans moins de 24h, il n'y a pas de tirage au sort pour
|
||||
cette place : elle est disponible immédiatement à l'addresse
|
||||
cette place : elle est disponible immédiatement à l'adresse
|
||||
http://{{ domain }}{% url "bda-buy-revente" spectacle.id %}, à la disposition de tous.
|
||||
|
||||
Chaleureusement,
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Formats français.
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
DATETIME_FORMAT = r'j F Y \à H:i'
|
||||
|
|
|
@ -45,7 +45,7 @@ INSTALLED_APPS = (
|
|||
'autocomplete_light',
|
||||
'captcha',
|
||||
'django_cas_ng',
|
||||
'debug_toolbar',
|
||||
# 'debug_toolbar',
|
||||
'bootstrapform',
|
||||
'kfet',
|
||||
'channels',
|
||||
|
|
Loading…
Reference in a new issue