From 4c6b33ccb452ed2b7810cb7f6d2850916d080634 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 10 Oct 2016 16:56:31 +0200 Subject: [PATCH 01/19] change shotgun en booleanfield --- bda/admin.py | 2 +- bda/models.py | 15 ++++----------- bda/views.py | 20 +++++++------------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/bda/admin.py b/bda/admin.py index 37fdf9c7..c706c0dd 100644 --- a/bda/admin.py +++ b/bda/admin.py @@ -218,7 +218,7 @@ class SpectacleReventeAdmin(admin.ModelAdmin): list_display = ("spectacle", "seller", "date", "soldTo") raw_id_fields = ("attribution",) - readonly_fields = ("shotgun", "expiration_time") + readonly_fields = ("expiration_time",) search_fields = ("spectacle__title", "seller__user__username", "seller__user__firstname", diff --git a/bda/models.py b/bda/models.py index 3642ee83..a9fd702f 100644 --- a/bda/models.py +++ b/bda/models.py @@ -228,7 +228,6 @@ class SpectacleRevente(models.Model): answered_mail = models.ManyToManyField(Participant, related_name="wanted", blank=True) - seller = models.ForeignKey(Participant, related_name="original_shows", verbose_name="Vendeur") @@ -239,6 +238,8 @@ class SpectacleRevente(models.Model): default=False) tirage_done = models.BooleanField("Tirage effectué", default=False) + shotgun = models.BooleanField("Disponible immédiatement", + default=False) @property def expiration_time(self): @@ -255,16 +256,6 @@ class SpectacleRevente(models.Model): .astimezone(timezone.get_current_timezone()) \ .strftime('%D à %H:%M') - @property - def shotgun(self): - # Soit on a dépassé le délai du tirage, soit il reste peu de - # temps avant le spectacle - # On se laisse 5min de marge pour cron - return (timezone.now() > self.expiration_time + timedelta(minutes=5) or - (self.attribution.spectacle.date <= timezone.now() + - timedelta(days=1))) and (timezone.now() >= self.date + - timedelta(minutes=15)) - def __str__(self): return "%s -- %s" % (self.seller, self.attribution.spectacle.title) @@ -318,6 +309,7 @@ class SpectacleRevente(models.Model): connection = mail.get_connection() connection.send_messages(mails_to_send) self.notif_sent = True + self.shotgun = True self.save() def tirage(self): @@ -350,4 +342,5 @@ Le BdA""" % (spectacle.title, winner.user.get_full_name(), winner.user.email) mail_seller, "bda@ens.fr", [seller.user.email], fail_silently=False) self.tirage_done = True + self.shotgun = True self.save() diff --git a/bda/views.py b/bda/views.py index b87b90d4..5cbe5b13 100644 --- a/bda/views.py +++ b/bda/views.py @@ -367,6 +367,7 @@ def revente_interested(request, revente_id): participant, created = Participant.objects.get_or_create( user=request.user, tirage=revente.attribution.spectacle.tirage) if timezone.now() < revente.date + timedelta(hours=1) or revente.shotgun: + # TODO améliorer le message d'erreur return render(request, "bda-wrongtime.html", {}) revente.answered_mail.add(participant) @@ -388,13 +389,9 @@ def list_revente(request, tirage_id): for spectacle in spectacles: revente_objects = SpectacleRevente.objects.filter( attribution__spectacle=spectacle, - soldTo__isnull=True) - revente_count = 0 - for revente in revente_objects: - if revente.shotgun: - revente_count += 1 - if revente_count: - spectacle.revente_count = revente_count + soldTo__isnull=True, + shotgun=True) + if revente_objects.exists(): shotgun.append(spectacle) if request.method == 'POST': @@ -440,16 +437,13 @@ def buy_revente(request, spectacle_id): revente.delete() return HttpResponseRedirect(reverse("bda-liste-revente", args=[tirage.id])) - reventes_shotgun = [] - for revente in reventes.all(): - if revente.shotgun: - reventes_shotgun.append(revente) + reventes_shotgun = reventes.filter(shotgun=True) - if not reventes_shotgun: + if not reventes_shotgun.exists(): return render(request, "bda-no-revente.html", {}) if request.POST: - revente = random.choice(reventes_shotgun) + revente = random.choice(reventes_shotgun.all()) revente.soldTo = participant revente.save() mail = """Bonjour ! From 6d8008ff39dc03ff8f78f5f2f02c897270a8db7e Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 10 Oct 2016 16:56:40 +0200 Subject: [PATCH 02/19] migration --- .../0010_spectaclerevente_shotgun.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 bda/migrations/0010_spectaclerevente_shotgun.py diff --git a/bda/migrations/0010_spectaclerevente_shotgun.py b/bda/migrations/0010_spectaclerevente_shotgun.py new file mode 100644 index 00000000..a4bf2abc --- /dev/null +++ b/bda/migrations/0010_spectaclerevente_shotgun.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('bda', '0009_revente'), + ] + + operations = [ + migrations.AddField( + model_name='spectaclerevente', + name='shotgun', + field=models.BooleanField(default=False, verbose_name='Disponible imm\xe9diatement'), + ), + ] From 04c75036ad6fba301f9f972a27eb4ede73b1da02 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 24 Oct 2016 14:44:57 -0200 Subject: [PATCH 03/19] =?UTF-8?q?commentaire=20plus=20pr=C3=A9cis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bda/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bda/models.py b/bda/models.py index a09652fd..b5ee094e 100644 --- a/bda/models.py +++ b/bda/models.py @@ -248,7 +248,7 @@ class SpectacleRevente(models.Model): - self.date - timedelta(hours=13)) # Au minimum, on attend 2 jours avant le tirage delay = min(remaining_time, timedelta(days=2)) - # On a aussi 1h pour changer d'avis + # Le vendeur a aussi 1h pour changer d'avis return self.date + delay + timedelta(hours=1) def expiration_time_str(self): From 27464aaa9336e39a8ccae00caeae5a51bdcf26e7 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 25 Oct 2016 12:44:28 -0200 Subject: [PATCH 04/19] should have been in bda_shotgun --- bda/views.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/bda/views.py b/bda/views.py index 3ca8d107..f604d808 100644 --- a/bda/views.py +++ b/bda/views.py @@ -381,19 +381,8 @@ def list_revente(request, tirage_id): tirage = get_object_or_404(Tirage, id=tirage_id) participant, created = Participant.objects.get_or_create( user=request.user, tirage=tirage) - spectacles = tirage.spectacle_set.filter( - date__gte=timezone.now()) - shotgun = [] deja_revente = False success = False - for spectacle in spectacles: - revente_objects = SpectacleRevente.objects.filter( - attribution__spectacle=spectacle, - soldTo__isnull=True, - shotgun=True) - if revente_objects.exists(): - shotgun.append(spectacle) - if request.method == 'POST': form = InscriptionReventeForm(tirage, request.POST) if form.is_valid(): @@ -419,7 +408,7 @@ def list_revente(request, tirage_id): initial={'spectacles': participant.choicesrevente.all()}) return render(request, "liste-reventes.html", - {"form": form, 'shotgun': shotgun, + {"form": form, "deja_revente": deja_revente, "success": success}) From 83f0328cc2043f97e1dfc4a9b37a03bfcbe7dd41 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 27 Oct 2016 12:38:14 -0200 Subject: [PATCH 05/19] added security to mail_shotgun --- bda/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bda/models.py b/bda/models.py index b5ee094e..cfd063f4 100644 --- a/bda/models.py +++ b/bda/models.py @@ -309,6 +309,8 @@ class SpectacleRevente(models.Model): connection = mail.get_connection() connection.send_messages(mails_to_send) self.notif_sent = True + # Flag inutile, sauf si l'horloge interne merde + self.tirage_done = True self.shotgun = True self.save() From 0a5b488d75e079c1457fe0d80f893bf8b458f274 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 27 Oct 2016 12:56:54 -0200 Subject: [PATCH 06/19] cleaner shotgun cases --- bda/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bda/models.py b/bda/models.py index cfd063f4..f3bf71a6 100644 --- a/bda/models.py +++ b/bda/models.py @@ -343,6 +343,9 @@ 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", [seller.user.email], fail_silently=False) + + else: # Si personne ne veut la place, elle part au shotgun + self.shotgun = True + self.tirage_done = True - self.shotgun = True self.save() From 5ebbf3f9b2c573f4bf776ab02a7b0161cc9aa30a Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 27 Oct 2016 13:05:59 -0200 Subject: [PATCH 07/19] delete old BdA-Revente --- bda/views.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/bda/views.py b/bda/views.py index f604d808..143d0cff 100644 --- a/bda/views.py +++ b/bda/views.py @@ -261,25 +261,6 @@ def tirage(request, tirage_id): return render(request, "bda-token.html", {"form": form}) -def do_resell(request, form): - spectacle = form.cleaned_data["spectacle"] - count = form.cleaned_data["count"] - places = "2 places" if count == "2" else "une place" - mail = """Bonjour, - -Je souhaite revendre %s pour %s le %s (%s) à %.02f€. -Contactez moi par email si vous êtes intéressé·e·s ! - -%s (%s)""" % (places, spectacle.title, spectacle.date_no_seconds(), - spectacle.location, spectacle.price, - request.user.get_full_name(), request.user.email) - send_mail("%s" % spectacle, mail, - request.user.email, ["bda-revente@lists.ens.fr"], - fail_silently=False) - return render(request, "bda-success.html", - {"show": spectacle, "places": places}) - - @login_required def revente(request, tirage_id): tirage = get_object_or_404(Tirage, id=tirage_id) From 1ba2766231c4b0896cabef54ed6eb392b16d3ede Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 12 Nov 2016 22:45:52 -0200 Subject: [PATCH 08/19] fix revente de reventes --- bda/views.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bda/views.py b/bda/views.py index ff6109fe..25db608c 100644 --- a/bda/views.py +++ b/bda/views.py @@ -285,6 +285,9 @@ def revente(request, tirage_id): if not created: revente.seller = participant revente.date = timezone.now() + revente.notif_sent = False + revente.tirage_done = False + revente.shotgun = False mail_subject = "BdA-Revente : {:s}".format(attribution.spectacle.title) mail_body = loader.render_to_string('mail-revente-new.txt', { 'vendeur': participant.user, @@ -421,18 +424,22 @@ def buy_revente(request, spectacle_id): reventes = SpectacleRevente.objects.filter( attribution__spectacle=spectacle, soldTo__isnull=True) + + # Si l'utilisateur veut racheter une place qu'il est en train de revendre, + # on supprime la revente en question. if reventes.filter(seller=participant).exists(): revente = reventes.filter(seller=participant)[0] revente.delete() return HttpResponseRedirect(reverse("bda-shotgun", args=[tirage.id])) - reventes_shotgun = reventes.filter(shotgun=True) - if not reventes_shotgun.exists(): + reventes_shotgun = list(reventes.filter(shotgun=True).all()) + + if not reventes_shotgun: return render(request, "bda-no-revente.html", {}) if request.POST: - revente = random.choice(reventes_shotgun.all()) + revente = random.choice(reventes_shotgun) revente.soldTo = participant revente.save() mail = """Bonjour ! From 790e73d7a4803fa690bca149cd820e011207d7fa Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 12 Nov 2016 23:45:14 -0200 Subject: [PATCH 09/19] fix messages revente_interested --- bda/templates/bda-interested.html | 2 +- bda/templates/bda-wrongtime.html | 11 +++++++++-- bda/views.py | 6 +++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bda/templates/bda-interested.html b/bda/templates/bda-interested.html index acfb1d1e..780330bd 100644 --- a/bda/templates/bda-interested.html +++ b/bda/templates/bda-interested.html @@ -3,7 +3,7 @@ {% block realcontent %}

Inscription à une revente

-

Votre inscription pour a bien été enregistrée !

+

Votre inscription a bien été enregistrée !

Le tirage au sort pour cette revente ({{spectacle}}) sera effectué le {{date}}. {% endblock %} diff --git a/bda/templates/bda-wrongtime.html b/bda/templates/bda-wrongtime.html index 5e17926b..dfafb05f 100644 --- a/bda/templates/bda-wrongtime.html +++ b/bda/templates/bda-wrongtime.html @@ -1,6 +1,13 @@ {% extends "base_title.html" %} {% block realcontent %} -

Nope

-

Cette revente n'est pas disponible actuellement, désolé !

+

Nope

+ {% if revente.shotgun %} +

Le tirage au sort de cette revente a déjà été effectué !

+ +

Si personne n'était intéressé, elle est maintenant disponible + ici.

+ {% else %} +

Il n'est pas encore possible de s'inscrire à cette revente, réessaie dans quelque temps !

+ {% endif %} {% endblock %} diff --git a/bda/views.py b/bda/views.py index 25db608c..12c380db 100644 --- a/bda/views.py +++ b/bda/views.py @@ -369,9 +369,9 @@ def revente_interested(request, revente_id): revente = get_object_or_404(SpectacleRevente, id=revente_id) participant, created = Participant.objects.get_or_create( user=request.user, tirage=revente.attribution.spectacle.tirage) - if timezone.now() < revente.date + timedelta(hours=1) or revente.shotgun: - # TODO améliorer le message d'erreur - return render(request, "bda-wrongtime.html", {}) + if (timezone.now() < revente.date + timedelta(hours=1)) or revente.shotgun: + return render(request, "bda-wrongtime.html", + {"revente": revente}) revente.answered_mail.add(participant) return render(request, "bda-interested.html", From a63269a4ce177a2a577644d21b197033597f5987 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 14 Nov 2016 12:52:02 -0200 Subject: [PATCH 10/19] more coherent names --- bda/admin.py | 2 +- bda/management/commands/manage_reventes.py | 2 +- bda/models.py | 7 ++++--- bda/templates/mail-revente-new.txt | 2 +- bda/views.py | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bda/admin.py b/bda/admin.py index 163e50a0..e9bc29f2 100644 --- a/bda/admin.py +++ b/bda/admin.py @@ -225,7 +225,7 @@ class SpectacleReventeAdmin(admin.ModelAdmin): list_display = ("spectacle", "seller", "date", "soldTo") raw_id_fields = ("attribution",) - readonly_fields = ("expiration_time",) + readonly_fields = ("date_tirage",) search_fields = ['attribution__spectacle__title', 'seller__user__username', 'seller__user__first_name', diff --git a/bda/management/commands/manage_reventes.py b/bda/management/commands/manage_reventes.py index 45b9c91a..271b952e 100644 --- a/bda/management/commands/manage_reventes.py +++ b/bda/management/commands/manage_reventes.py @@ -31,7 +31,7 @@ class Command(BaseCommand): revente.send_notif() self.stdout.write("Mail d'inscription à une revente envoyé") # Check si tirage à faire - elif (now >= revente.expiration_time and + elif (now >= revente.date_tirage and not revente.tirage_done): self.stdout.write(str(now)) revente.tirage() diff --git a/bda/models.py b/bda/models.py index 9d7c0303..a44a3d65 100644 --- a/bda/models.py +++ b/bda/models.py @@ -242,7 +242,8 @@ class SpectacleRevente(models.Model): default=False) @property - def expiration_time(self): + def date_tirage(self): + """Renvoie la date du tirage au sort de la revente.""" # L'acheteur doit être connu au plus 12h avant le spectacle remaining_time = (self.attribution.spectacle.date - self.date - timedelta(hours=13)) @@ -251,8 +252,8 @@ class SpectacleRevente(models.Model): # Le vendeur a aussi 1h pour changer d'avis return self.date + delay + timedelta(hours=1) - def expiration_time_str(self): - return self.expiration_time \ + def date_tirage_str(self): + return self.date_tirage \ .astimezone(timezone.get_current_timezone()) \ .strftime('%d/%m/%y à %H:%M') diff --git a/bda/templates/mail-revente-new.txt b/bda/templates/mail-revente-new.txt index ffba3083..b4815e84 100644 --- a/bda/templates/mail-revente-new.txt +++ b/bda/templates/mail-revente-new.txt @@ -2,7 +2,7 @@ Bonjour {{ vendeur.first_name }}, Tu t’es bien inscrit-e pour la revente de {{ spectacle.title }}. -{% with revente.expiration_time as time %} +{% with revente.date_tirage as time %} Le tirage au sort entre tout-e-s les racheteuse-eur-s potentiel-le-s aura lieu le {{ time|date:"DATE_FORMAT" }} à {{ time|time:"TIME_FORMAT" }} (dans {{time|timeuntil }}). Si personne ne s’est inscrit pour racheter la place, celle-ci apparaitra parmi diff --git a/bda/views.py b/bda/views.py index 12c380db..da74c6aa 100644 --- a/bda/views.py +++ b/bda/views.py @@ -376,7 +376,7 @@ def revente_interested(request, revente_id): revente.answered_mail.add(participant) return render(request, "bda-interested.html", {"spectacle": revente.attribution.spectacle, - "date": revente.expiration_time}) + "date": revente.date_tirage}) @login_required From b15dcba8c9ff9b118a6b40730d72ca083f895b65 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 14 Nov 2016 12:52:16 -0200 Subject: [PATCH 11/19] mail formatting --- bda/templates/mail-revente.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bda/templates/mail-revente.txt b/bda/templates/mail-revente.txt index 899afe3b..172d8195 100644 --- a/bda/templates/mail-revente.txt +++ b/bda/templates/mail-revente.txt @@ -3,10 +3,12 @@ Bonjour {{ user.first_name }} Une place pour le spectacle {{ spectacle.title }} ({{ spectacle.date_no_seconds }}) a été postée sur BdA-Revente. +{% with revente.date_tirage as time %} Si ce spectacle t'intéresse toujours, merci de nous le signaler en cliquant sur ce lien : http://{{ domain }}{% url "bda-revente-interested" revente.id %}. Dans le cas où plusieurs personnes seraient intéressées, nous procèderons à -un tirage au sort le {{ revente.expiration_time_str }}. +un tirage au sort le {{ time|date:"DATE_FORMAT" }} à {{ time|time:"TIME_FORMAT" }} (dans {{time|timeuntil}}). +{% endwith %} Chaleureusement, Le BdA From 40f3cf60a032f595ad9950c4d8c8bfa4e84e67d3 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 14 Nov 2016 13:00:21 -0200 Subject: [PATCH 12/19] code mort --- bda/models.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/bda/models.py b/bda/models.py index 7d1c6bcf..a5a7abe2 100644 --- a/bda/models.py +++ b/bda/models.py @@ -249,11 +249,6 @@ class SpectacleRevente(models.Model): # Le vendeur a aussi 1h pour changer d'avis return self.date + delay + timedelta(hours=1) - def date_tirage_str(self): - return self.date_tirage \ - .astimezone(timezone.get_current_timezone()) \ - .strftime('%d/%m/%y à %H:%M') - def __str__(self): return "%s -- %s" % (self.seller, self.attribution.spectacle.title) From 330b45fb2cf24ee4d9eda0eef41892bb239e6247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Tue, 20 Dec 2016 22:24:07 +0100 Subject: [PATCH 13/19] Style + commentaires --- bda/views.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/bda/views.py b/bda/views.py index 4ffae2eb..378912a8 100644 --- a/bda/views.py +++ b/bda/views.py @@ -271,6 +271,7 @@ def revente(request, tirage_id): if not participant.paid: return render(request, "bda-notpaid.html", {}) if request.method == 'POST': + # On met en vente une place if 'resell' in request.POST: resellform = ResellForm(participant, request.POST, prefix='resell') annulform = AnnulForm(participant, prefix='annul') @@ -279,30 +280,35 @@ def revente(request, tirage_id): attributions = resellform.cleaned_data["attributions"] with transaction.atomic(): for attribution in attributions: - revente, created = SpectacleRevente.objects.get_or_create( - attribution=attribution, - defaults={'seller': participant}) + revente, created = \ + SpectacleRevente.objects.get_or_create( + attribution=attribution, + defaults={'seller': participant}) if not created: revente.seller = participant revente.date = timezone.now() revente.notif_sent = False revente.tirage_done = False revente.shotgun = False - mail_subject = "BdA-Revente : {:s}".format(attribution.spectacle.title) - mail_body = loader.render_to_string('bda/mails/revente-new.txt', { - 'vendeur': participant.user, - 'spectacle': attribution.spectacle, - 'revente': revente, - }) + mail_subject = "BdA-Revente : {:s}".format( + attribution.spectacle.title) + mail_body = loader.render_to_string( + 'bda/mails/revente-new.txt', + {'vendeur': participant.user, + 'spectacle': attribution.spectacle, + 'revente': revente} + ) mails.append(mail.EmailMessage( mail_subject, mail_body, from_email=settings.MAIL_DATA['revente']['FROM'], to=[participant.user.email], - reply_to=[settings.MAIL_DATA['revente']['REPLYTO']], + reply_to=[ + settings.MAIL_DATA['revente']['REPLYTO'] + ], )) revente.save() mail.get_connection().send_messages(mails) - + # On annule une revente elif 'annul' in request.POST: annulform = AnnulForm(participant, request.POST, prefix='annul') resellform = ResellForm(participant, prefix='resell') @@ -310,7 +316,8 @@ def revente(request, tirage_id): attributions = annulform.cleaned_data["attributions"] for attribution in attributions: attribution.revente.delete() - + # On confirme une vente en transférant la place à la personne qui a + # gagné le tirage elif 'transfer' in request.POST: resellform = ResellForm(participant, prefix='resell') annulform = AnnulForm(participant, prefix='annul') @@ -323,7 +330,9 @@ def revente(request, tirage_id): attrib = revente.attribution attrib.participant = revente.soldTo attrib.save() - + # On annule la revente après le tirage au sort (par exemple si + # la personne qui a gagné le tirage ne se manifeste pas). La place est + # alors remise en vente elif 'reinit' in request.POST: resellform = ResellForm(participant, prefix='resell') annulform = AnnulForm(participant, prefix='annul') From 28df0355c2e8c10d766ac723ceb5ca524ae5f44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Wed, 21 Dec 2016 02:15:50 +0100 Subject: [PATCH 14/19] =?UTF-8?q?Am=C3=A9liore=20l'algo=20d'inscription=20?= =?UTF-8?q?=C3=A0=20une=20revente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Au lieu d'inscrire les gens à la première revente qu'on trouve on les inscrit à celle qui a le moins de participants --- bda/views.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/bda/views.py b/bda/views.py index 378912a8..efd2e1cb 100644 --- a/bda/views.py +++ b/bda/views.py @@ -405,15 +405,23 @@ def list_revente(request, tirage_id): for spectacle in choices: qset = SpectacleRevente.objects.filter( attribution__spectacle=spectacle) - if qset.exists(): - # On l'inscrit à l'un des tirages au sort - for revente in qset.all(): - if revente.shotgun and not revente.soldTo: - deja_revente = True - else: - revente.answered_mail.add(participant) - revente.save() - break + if qset.filter(shotgun=True, soldTo__isnull=True).exists(): + # Une place est disponible au shotgun, on suggère à + # l'utilisateur d'aller la récupérer + deja_revente = True + else: + # La place n'est pas disponible au shotgun, si des reventes + # pour ce spectacle existent déjà, on inscrit la personne à + # la revente ayant le moins d'inscrits + min_resell = ( + qset.filter(shotgun=False) + .annotate(nb_subscribers=Count('answered_mail')) + .order_by('nb_subscribers') + .first() + ) + if min_resell is not None: + min_resell.answered_mail.add(participant) + min_resell.save() success = True else: form = InscriptionReventeForm( From 38dd220c23151c07f3f1fb2f130d5bd15385ad32 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 21 Dec 2016 00:35:05 -0200 Subject: [PATCH 15/19] modernize reventes_shotgun --- bda/views.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/bda/views.py b/bda/views.py index 4ffae2eb..58c54a01 100644 --- a/bda/views.py +++ b/bda/views.py @@ -468,14 +468,11 @@ def revente_shotgun(request, tirage_id): date__gte=timezone.now()) shotgun = [] for spectacle in spectacles: - revente_objects = SpectacleRevente.objects.filter( + reventes = SpectacleRevente.objects.filter( attribution__spectacle=spectacle, + shotgun=True, soldTo__isnull=True) - revente_count = 0 - for revente in revente_objects: - if revente.shotgun: - revente_count += 1 - if revente_count: + if reventes.exists(): shotgun.append(spectacle) return render(request, "bda-shotgun.html", From 07f920976fd0ac6d11b16559c363e5a78ee0228d Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 21 Dec 2016 00:45:30 -0200 Subject: [PATCH 16/19] change soldTo functioning --- bda/forms.py | 5 ++--- bda/views.py | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bda/forms.py b/bda/forms.py index fe20e565..352914e4 100644 --- a/bda/forms.py +++ b/bda/forms.py @@ -68,9 +68,8 @@ class AnnulForm(forms.Form): self.fields['attributions'].queryset = participant.attribution_set\ .filter(spectacle__date__gte=timezone.now(), revente__isnull=False, - revente__date__gt=timezone.now()-timedelta(hours=1))\ - .filter(Q(revente__soldTo__isnull=True) | - Q(revente__soldTo=participant)) + revente__date__gt=timezone.now()-timedelta(hours=1), + revente__soldTo__isnull=True) class InscriptionReventeForm(forms.Form): diff --git a/bda/views.py b/bda/views.py index 58c54a01..fbfd9bcd 100644 --- a/bda/views.py +++ b/bda/views.py @@ -285,6 +285,7 @@ def revente(request, tirage_id): if not created: revente.seller = participant revente.date = timezone.now() + revente.soldTo = None revente.notif_sent = False revente.tirage_done = False revente.shotgun = False @@ -337,6 +338,7 @@ def revente(request, tirage_id): revente.soldTo = None revente.notif_sent = False revente.tirage_done = False + revente.shotgun = False if revente.answered_mail: revente.answered_mail.clear() revente.save() From 9bbc9e934d5bd9d7d9de1442d70ef034aa6f4daa Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 21 Dec 2016 00:45:30 -0200 Subject: [PATCH 17/19] change soldTo functioning --- bda/forms.py | 5 ++--- bda/views.py | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bda/forms.py b/bda/forms.py index fe20e565..352914e4 100644 --- a/bda/forms.py +++ b/bda/forms.py @@ -68,9 +68,8 @@ class AnnulForm(forms.Form): self.fields['attributions'].queryset = participant.attribution_set\ .filter(spectacle__date__gte=timezone.now(), revente__isnull=False, - revente__date__gt=timezone.now()-timedelta(hours=1))\ - .filter(Q(revente__soldTo__isnull=True) | - Q(revente__soldTo=participant)) + revente__date__gt=timezone.now()-timedelta(hours=1), + revente__soldTo__isnull=True) class InscriptionReventeForm(forms.Form): diff --git a/bda/views.py b/bda/views.py index 58c54a01..1ff2be41 100644 --- a/bda/views.py +++ b/bda/views.py @@ -285,6 +285,7 @@ def revente(request, tirage_id): if not created: revente.seller = participant revente.date = timezone.now() + revente.soldTo = None revente.notif_sent = False revente.tirage_done = False revente.shotgun = False @@ -337,6 +338,7 @@ def revente(request, tirage_id): revente.soldTo = None revente.notif_sent = False revente.tirage_done = False + revente.shotgun = False if revente.answered_mail: revente.answered_mail.clear() revente.save() @@ -357,8 +359,7 @@ def revente(request, tirage_id): sold = participant.attribution_set.filter( spectacle__date__gte=timezone.now(), revente__isnull=False, - revente__soldTo__isnull=False).exclude( - revente__soldTo=participant) + revente__soldTo__isnull=False) return render(request, "bda-revente.html", {'tirage': tirage, 'overdue': overdue, "sold": sold, From e8be072e7899602a661e2e0dce106a66276d1324 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 21 Dec 2016 00:53:35 -0200 Subject: [PATCH 18/19] message si inscription a une revente en cours --- bda/templates/liste-reventes.html | 3 +++ bda/views.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bda/templates/liste-reventes.html b/bda/templates/liste-reventes.html index d08d4010..c0bf8ff0 100644 --- a/bda/templates/liste-reventes.html +++ b/bda/templates/liste-reventes.html @@ -8,7 +8,10 @@ {% endif %} {% if deja_revente %}

Des reventes existent déjà pour certains de ces spectacles ; vérifie les places disponibles sans tirage !

+ {% elif inscrit_revente %} +

Tu as été inscrit à une revente en cours pour ce spectacle !

{% endif %} +
{% csrf_token %}
diff --git a/bda/views.py b/bda/views.py index 1ff2be41..96060de2 100644 --- a/bda/views.py +++ b/bda/views.py @@ -388,6 +388,7 @@ def list_revente(request, tirage_id): user=request.user, tirage=tirage) deja_revente = False success = False + inscrit_revente = False if request.method == 'POST': form = InscriptionReventeForm(tirage, request.POST) if form.is_valid(): @@ -405,6 +406,7 @@ def list_revente(request, tirage_id): else: revente.answered_mail.add(participant) revente.save() + inscrit_revente = True break success = True else: @@ -414,7 +416,8 @@ def list_revente(request, tirage_id): return render(request, "liste-reventes.html", {"form": form, - "deja_revente": deja_revente, "success": success}) + "deja_revente": deja_revente, "success": success, + "inscrit_revente": inscrit_revente}) @login_required From 2f70dbf911fe4adf95b45ae899b01eba9f42ff8c Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 21 Dec 2016 01:05:04 -0200 Subject: [PATCH 19/19] default shotgun for existing rows --- bda/migrations/0010_spectaclerevente_shotgun.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bda/migrations/0010_spectaclerevente_shotgun.py b/bda/migrations/0010_spectaclerevente_shotgun.py index a4bf2abc..35b4da8a 100644 --- a/bda/migrations/0010_spectaclerevente_shotgun.py +++ b/bda/migrations/0010_spectaclerevente_shotgun.py @@ -2,6 +2,19 @@ from __future__ import unicode_literals from django.db import models, migrations +from django.utils import timezone +from datetime import timedelta + + +def forwards_func(apps, schema_editor): + SpectacleRevente = apps.get_model("bda", "SpectacleRevente") + + for revente in SpectacleRevente.objects.all(): + is_expired = timezone.now() > revente.date_tirage() + is_direct = (revente.attribution.spectacle.date >= revente.date and + timezone.now() > revente.date + timedelta(minutes=15)) + revente.shotgun = is_expired or is_direct + revente.save() class Migration(migrations.Migration): @@ -16,4 +29,5 @@ class Migration(migrations.Migration): name='shotgun', field=models.BooleanField(default=False, verbose_name='Disponible imm\xe9diatement'), ), + migrations.RunPython(forwards_func, migrations.RunPython.noop), ]