From f93b095e0fba71b3d94cb5529e56990ecdbabef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sun, 20 Nov 2016 16:39:26 +0100 Subject: [PATCH] Styling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ou comment faire plaisir à pylint sur les bouts de code concernés par cette MR --- bda/management/commands/manage_reventes.py | 17 +++-- bda/management/commands/sendrappels.py | 9 ++- bda/models.py | 83 +++++++++++++--------- bda/templates/bda/mails/shotgun.txt | 2 +- cof/locale/fr/formats.py | 5 ++ cof/settings_dev.py | 2 +- 6 files changed, 77 insertions(+), 41 deletions(-) diff --git a/bda/management/commands/manage_reventes.py b/bda/management/commands/manage_reventes.py index a10c1ca5..310bb618 100644 --- a/bda/management/commands/manage_reventes.py +++ b/bda/management/commands/manage_reventes.py @@ -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") diff --git a/bda/management/commands/sendrappels.py b/bda/management/commands/sendrappels.py index aa54337b..3c42170c 100644 --- a/bda/management/commands/sendrappels.py +++ b/bda/management/commands/sendrappels.py @@ -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 diff --git a/bda/models.py b/bda/models.py index cb642b4f..29e3dccd 100644 --- a/bda/models.py +++ b/bda/models.py @@ -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'], diff --git a/bda/templates/bda/mails/shotgun.txt b/bda/templates/bda/mails/shotgun.txt index 53462fb3..69bc704c 100644 --- a/bda/templates/bda/mails/shotgun.txt +++ b/bda/templates/bda/mails/shotgun.txt @@ -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, diff --git a/cof/locale/fr/formats.py b/cof/locale/fr/formats.py index 2a926447..879d5ab8 100644 --- a/cof/locale/fr/formats.py +++ b/cof/locale/fr/formats.py @@ -1,4 +1,9 @@ # -*- encoding: utf-8 -*- + +""" +Formats français. +""" + from __future__ import unicode_literals DATETIME_FORMAT = r'j F Y \à H:i' diff --git a/cof/settings_dev.py b/cof/settings_dev.py index 12a58b26..0650eed4 100644 --- a/cof/settings_dev.py +++ b/cof/settings_dev.py @@ -45,7 +45,7 @@ INSTALLED_APPS = ( 'autocomplete_light', 'captcha', 'django_cas_ng', - 'debug_toolbar', +# 'debug_toolbar', 'bootstrapform', 'kfet', 'channels',