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
6 changed files with 77 additions and 41 deletions
|
@ -1,14 +1,21 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Gestion en ligne de commande des reventes.
|
||||||
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
from django.core.management import BaseCommand
|
from django.core.management import BaseCommand
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from datetime import timedelta
|
|
||||||
from bda.models import SpectacleRevente
|
from bda.models import SpectacleRevente
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
"""
|
||||||
|
Objet `BaseCommand`, cf ``self.help`` pour plus d'informations.
|
||||||
|
"""
|
||||||
help = "Envoie les mails de notification et effectue " \
|
help = "Envoie les mails de notification et effectue " \
|
||||||
"les tirages au sort des reventes"
|
"les tirages au sort des reventes"
|
||||||
leave_locale_alone = True
|
leave_locale_alone = True
|
||||||
|
@ -19,21 +26,21 @@ class Command(BaseCommand):
|
||||||
for revente in reventes:
|
for revente in reventes:
|
||||||
# Check si < 24h
|
# Check si < 24h
|
||||||
if (revente.attribution.spectacle.date <=
|
if (revente.attribution.spectacle.date <=
|
||||||
revente.date + timedelta(days=1)) and \
|
revente.date + timedelta(days=1)) and \
|
||||||
now >= revente.date + timedelta(minutes=15) and \
|
now >= revente.date + timedelta(minutes=15) and \
|
||||||
not revente.notif_sent:
|
not revente.notif_sent:
|
||||||
self.stdout.write(str(now))
|
self.stdout.write(str(now))
|
||||||
revente.mail_shotgun()
|
revente.mail_shotgun()
|
||||||
self.stdout.write("Mail de disponibilité immédiate envoyé")
|
self.stdout.write("Mail de disponibilité immédiate envoyé")
|
||||||
# Check si délai de retrait dépassé
|
# Check si délai de retrait dépassé
|
||||||
elif (now >= revente.date + timedelta(hours=1) and
|
elif (now >= revente.date + timedelta(hours=1) and
|
||||||
not revente.notif_sent):
|
not revente.notif_sent):
|
||||||
self.stdout.write(str(now))
|
self.stdout.write(str(now))
|
||||||
revente.send_notif()
|
revente.send_notif()
|
||||||
self.stdout.write("Mail d'inscription à une revente envoyé")
|
self.stdout.write("Mail d'inscription à une revente envoyé")
|
||||||
# Check si tirage à faire
|
# Check si tirage à faire
|
||||||
elif (now >= revente.expiration_time and
|
elif (now >= revente.expiration_time and
|
||||||
not revente.tirage_done):
|
not revente.tirage_done):
|
||||||
self.stdout.write(str(now))
|
self.stdout.write(str(now))
|
||||||
revente.tirage()
|
revente.tirage()
|
||||||
self.stdout.write("Tirage effectué, mails envoyés")
|
self.stdout.write("Tirage effectué, mails envoyés")
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Gestion en ligne de commande des mails de rappel.
|
||||||
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from datetime import timedelta
|
|
||||||
from bda.models import Spectacle
|
from bda.models import Spectacle
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
"""
|
||||||
|
Objet Command, cf ``self.help`` pour plus d'informations.
|
||||||
|
"""
|
||||||
help = 'Envoie les mails de rappel des spectacles dont la date ' \
|
help = 'Envoie les mails de rappel des spectacles dont la date ' \
|
||||||
'approche.\nNe renvoie pas les mails déjà envoyés.'
|
'approche.\nNe renvoie pas les mails déjà envoyés.'
|
||||||
leave_locale_alone = True
|
leave_locale_alone = True
|
||||||
|
|
|
@ -29,7 +29,8 @@ class Tirage(models.Model):
|
||||||
default=False)
|
default=False)
|
||||||
|
|
||||||
def __str__(self):
|
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
|
@python_2_unicode_compatible
|
||||||
|
@ -91,6 +92,10 @@ class Spectacle(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
def send_rappel(self):
|
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
|
# On récupère la liste des participants
|
||||||
members = {}
|
members = {}
|
||||||
for attr in Attribution.objects.filter(spectacle=self).all():
|
for attr in Attribution.objects.filter(spectacle=self).all():
|
||||||
|
@ -107,14 +112,14 @@ class Spectacle(models.Model):
|
||||||
mail_object = str(self)
|
mail_object = str(self)
|
||||||
for member in members.values():
|
for member in members.values():
|
||||||
mail_body = loader.render_to_string('bda/mails/rappel.txt', {
|
mail_body = loader.render_to_string('bda/mails/rappel.txt', {
|
||||||
'name': member[0],
|
'name': member[0],
|
||||||
'nb_attr': member[1],
|
'nb_attr': member[1],
|
||||||
'show': self})
|
'show': self})
|
||||||
mail_tot = mail.EmailMessage(
|
mail_tot = mail.EmailMessage(
|
||||||
mail_object, mail_body,
|
mail_object, mail_body,
|
||||||
settings.MAIL_DATA['rappels']['FROM'], [member[2]],
|
settings.MAIL_DATA['rappels']['FROM'], [member[2]],
|
||||||
[], headers={
|
[], headers={
|
||||||
'Reply-To': settings.MAIL_DATA['rappels']['REPLYTO']})
|
'Reply-To': settings.MAIL_DATA['rappels']['REPLYTO']})
|
||||||
mails_to_send.append(mail_tot)
|
mails_to_send.append(mail_tot)
|
||||||
# On envoie les mails
|
# On envoie les mails
|
||||||
connection = mail.get_connection()
|
connection = mail.get_connection()
|
||||||
|
@ -267,16 +272,16 @@ class SpectacleRevente(models.Model):
|
||||||
mail_object = "%s" % (self.attribution.spectacle)
|
mail_object = "%s" % (self.attribution.spectacle)
|
||||||
for participant in inscrits:
|
for participant in inscrits:
|
||||||
mail_body = loader.render_to_string('bda/mails/revente.txt', {
|
mail_body = loader.render_to_string('bda/mails/revente.txt', {
|
||||||
'user': participant.user,
|
'user': participant.user,
|
||||||
'spectacle': self.attribution.spectacle,
|
'spectacle': self.attribution.spectacle,
|
||||||
'revente': self,
|
'revente': self,
|
||||||
'domain': Site.objects.get_current().domain})
|
'domain': Site.objects.get_current().domain})
|
||||||
mail_tot = mail.EmailMessage(
|
mail_tot = mail.EmailMessage(
|
||||||
mail_object, mail_body,
|
mail_object, mail_body,
|
||||||
settings.MAIL_DATA['revente']['FROM'],
|
settings.MAIL_DATA['revente']['FROM'],
|
||||||
[participant.user.email],
|
[participant.user.email],
|
||||||
[], headers={
|
[], headers={
|
||||||
'Reply-To': settings.MAIL_DATA['revente']['REPLYTO']})
|
'Reply-To': settings.MAIL_DATA['revente']['REPLYTO']})
|
||||||
mails_to_send.append(mail_tot)
|
mails_to_send.append(mail_tot)
|
||||||
|
|
||||||
connection = mail.get_connection()
|
connection = mail.get_connection()
|
||||||
|
@ -285,22 +290,26 @@ class SpectacleRevente(models.Model):
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def mail_shotgun(self):
|
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')
|
inscrits = self.attribution.spectacle.subscribed.select_related('user')
|
||||||
|
|
||||||
mails_to_send = []
|
mails_to_send = []
|
||||||
mail_object = "%s" % (self.attribution.spectacle)
|
mail_object = "%s" % (self.attribution.spectacle)
|
||||||
for participant in inscrits:
|
for participant in inscrits:
|
||||||
mail_body = loader.render_to_string('bda/mails/shotgun.txt', {
|
mail_body = loader.render_to_string('bda/mails/shotgun.txt', {
|
||||||
'user': participant.user,
|
'user': participant.user,
|
||||||
'spectacle': self.attribution.spectacle,
|
'spectacle': self.attribution.spectacle,
|
||||||
'domain': Site.objects.get_current(),
|
'domain': Site.objects.get_current(),
|
||||||
'mail': self.attribution.participant.user.email})
|
'mail': self.attribution.participant.user.email})
|
||||||
mail_tot = mail.EmailMessage(
|
mail_tot = mail.EmailMessage(
|
||||||
mail_object, mail_body,
|
mail_object, mail_body,
|
||||||
settings.MAIL_DATA['revente']['FROM'],
|
settings.MAIL_DATA['revente']['FROM'],
|
||||||
[participant.user.email],
|
[participant.user.email],
|
||||||
[], headers={
|
[], headers={
|
||||||
'Reply-To': settings.MAIL_DATA['revente']['REPLYTO']})
|
'Reply-To': settings.MAIL_DATA['revente']['REPLYTO']})
|
||||||
mails_to_send.append(mail_tot)
|
mails_to_send.append(mail_tot)
|
||||||
|
|
||||||
connection = mail.get_connection()
|
connection = mail.get_connection()
|
||||||
|
@ -309,6 +318,11 @@ class SpectacleRevente(models.Model):
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def tirage(self):
|
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())
|
inscrits = list(self.answered_mail.all())
|
||||||
spectacle = self.attribution.spectacle
|
spectacle = self.attribution.spectacle
|
||||||
seller = self.seller
|
seller = self.seller
|
||||||
|
@ -327,14 +341,16 @@ class SpectacleRevente(models.Model):
|
||||||
}
|
}
|
||||||
mails.append(mail.EmailMessage(
|
mails.append(mail.EmailMessage(
|
||||||
mail_subject,
|
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'],
|
from_email=settings.MAIL_DATA['revente']['FROM'],
|
||||||
to=[winner.user.email],
|
to=[winner.user.email],
|
||||||
reply_to=[seller.user.email],
|
reply_to=[seller.user.email],
|
||||||
))
|
))
|
||||||
mails.append(mail.EmailMessage(
|
mails.append(mail.EmailMessage(
|
||||||
mail_subject,
|
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'],
|
from_email=settings.MAIL_DATA['revente']['FROM'],
|
||||||
to=[seller.user.email],
|
to=[seller.user.email],
|
||||||
reply_to=[winner.user.email],
|
reply_to=[winner.user.email],
|
||||||
|
@ -345,11 +361,12 @@ class SpectacleRevente(models.Model):
|
||||||
if inscrit == winner:
|
if inscrit == winner:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
mail_body = loader.render_to_string('bda/mails/revente-loser.txt', {
|
mail_body = loader.render_to_string(
|
||||||
'acheteur': inscrit.user,
|
'bda/mails/revente-loser.txt',
|
||||||
'vendeur': seller.user,
|
{'acheteur': inscrit.user,
|
||||||
'spectacle': spectacle,
|
'vendeur': seller.user,
|
||||||
})
|
'spectacle': spectacle}
|
||||||
|
)
|
||||||
mails.append(mail.EmailMessage(
|
mails.append(mail.EmailMessage(
|
||||||
mail_subject, mail_body,
|
mail_subject, mail_body,
|
||||||
from_email=settings.MAIL_DATA['revente']['FROM'],
|
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.
|
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
|
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.
|
http://{{ domain }}{% url "bda-buy-revente" spectacle.id %}, à la disposition de tous.
|
||||||
|
|
||||||
Chaleureusement,
|
Chaleureusement,
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Formats français.
|
||||||
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
DATETIME_FORMAT = r'j F Y \à H:i'
|
DATETIME_FORMAT = r'j F Y \à H:i'
|
||||||
|
|
|
@ -45,7 +45,7 @@ INSTALLED_APPS = (
|
||||||
'autocomplete_light',
|
'autocomplete_light',
|
||||||
'captcha',
|
'captcha',
|
||||||
'django_cas_ng',
|
'django_cas_ng',
|
||||||
'debug_toolbar',
|
# 'debug_toolbar',
|
||||||
'bootstrapform',
|
'bootstrapform',
|
||||||
'kfet',
|
'kfet',
|
||||||
'channels',
|
'channels',
|
||||||
|
|
Loading…
Reference in a new issue