From d9402e105908c76c64a464123da73176ac77ae6a Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 16 Feb 2017 01:52:44 -0200 Subject: [PATCH 1/5] change resell and reinit forms --- bda/forms.py | 16 ++++++++ bda/templates/bda-revente.html | 68 ++++++++++++--------------------- bda/views.py | 69 ++++++++++++++-------------------- 3 files changed, 68 insertions(+), 85 deletions(-) diff --git a/bda/forms.py b/bda/forms.py index e2a1961b..3bdd7675 100644 --- a/bda/forms.py +++ b/bda/forms.py @@ -45,6 +45,7 @@ class AttributionModelMultipleChoiceField(forms.ModelMultipleChoiceField): class ResellForm(forms.Form): attributions = AttributionModelMultipleChoiceField( + label='', queryset=Attribution.objects.none(), widget=forms.CheckboxSelectMultiple, required=False) @@ -58,6 +59,7 @@ class ResellForm(forms.Form): class AnnulForm(forms.Form): attributions = AttributionModelMultipleChoiceField( + label='', queryset=Attribution.objects.none(), widget=forms.CheckboxSelectMultiple, required=False) @@ -81,3 +83,17 @@ class InscriptionReventeForm(forms.Form): super(InscriptionReventeForm, self).__init__(*args, **kwargs) self.fields['spectacles'].queryset = tirage.spectacle_set.filter( date__gte=timezone.now()) + + +class SoldForm(forms.Form): + attributions = AttributionModelMultipleChoiceField( + label='', + queryset=Attribution.objects.none(), + widget=forms.CheckboxSelectMultiple) + + def __init__(self, participant, *args, **kwargs): + super(SoldForm, self).__init__(*args, **kwargs) + self.fields['attributions'].queryset = participant.attribution_set\ + .filter(revente__isnull=False, + revente__soldTo__isnull=False)\ + .exclude(revente__soldTo=participant) diff --git a/bda/templates/bda-revente.html b/bda/templates/bda-revente.html index 569a3f3a..e61e7c8d 100644 --- a/bda/templates/bda-revente.html +++ b/bda/templates/bda-revente.html @@ -4,70 +4,50 @@ {% block realcontent %}

Revente de place

+{% if resellform.attributions %}

Places non revendues

{% csrf_token %} -
-
-
    - {% for box in resellform.attributions %} -
  • - {{box.tag}} - {{box.choice_label}} -
  • - {% endfor %} -
-
-
+ {{resellform|bootstrap}}
+{% endif %}
{% if annulform.attributions or overdue %}

Places en cours de revente

{% csrf_token %} -
-
+
+
    - {% for box in annulform.attributions %} -
  • - {{box.tag}} - {{box.choice_label}} -
  • - {% endfor %} - {% for attrib in overdue %} -
  • - - {{attrib.spectacle}} -
  • - {% endfor %} -
-
-
+ {% for attrib in annulform.attributions %} +
  • {{attrib.tag}} {{attrib.choice_label}}
  • + {% endfor %} + {% for attrib in overdue %} +
  • + + {{attrib.spectacle}} +
  • + {% endfor %} {% if annulform.attributions %} {% endif %} {% endif %}
    -{% if sold %} +{% if soldform.attributions %}

    Places revendues

    - - {% for attrib in sold %} - - + {% csrf_token %} - - - - - - - {% endfor %} -
    {{attrib.spectacle}}{{attrib.revente.soldTo.user.get_full_name}}
    + {{soldform|bootstrap}} + + + {% endif %} +{% if not resellform.attributions and not soldform.attributions and not overdue and not annulform.attributions %} +

    Plus de reventes possibles !

    +{% endif %} + {% endblock %} diff --git a/bda/views.py b/bda/views.py index 29067430..a07a6a4f 100644 --- a/bda/views.py +++ b/bda/views.py @@ -26,7 +26,7 @@ from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\ Tirage, SpectacleRevente from bda.algorithm import Algorithm from bda.forms import BaseBdaFormSet, TokenForm, ResellForm, AnnulForm,\ - InscriptionReventeForm + InscriptionReventeForm, SoldForm @cof_required @@ -316,13 +316,18 @@ def 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) + if not participant.paid: return render(request, "bda-notpaid.html", {}) + + resellform = ResellForm(participant, prefix='resell') + annulform = AnnulForm(participant, prefix='annul') + soldform = SoldForm(participant, prefix='sold') + 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') if resellform.is_valid(): datatuple = [] attributions = resellform.cleaned_data["attributions"] @@ -354,7 +359,6 @@ def revente(request, tirage_id): # On annule une revente elif 'annul' in request.POST: annulform = AnnulForm(participant, request.POST, prefix='annul') - resellform = ResellForm(participant, prefix='resell') if annulform.is_valid(): attributions = annulform.cleaned_data["attributions"] for attribution in attributions: @@ -362,44 +366,31 @@ def revente(request, tirage_id): # 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') + soldform = SoldForm(participant, request.POST, prefix='sold') + if soldform.is_valid(): + attributions = soldform.cleaned_data['attributions'] + for attribution in attributions: + attribution.participant = attribution.revente.soldTo + attribution.save() - revente_id = request.POST['transfer'][0] - rev = SpectacleRevente.objects.filter(soldTo__isnull=False, - id=revente_id) - if rev.exists(): - revente = rev.get() - 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') - revente_id = request.POST['reinit'][0] - rev = SpectacleRevente.objects.filter(soldTo__isnull=False, - id=revente_id) - if rev.exists(): - revente = rev.get() - if revente.attribution.spectacle.date > timezone.now(): - revente.date = timezone.now() - timedelta(hours=1) - revente.soldTo = None - revente.notif_sent = False - revente.tirage_done = False - revente.shotgun = False - if revente.answered_mail: - revente.answered_mail.clear() - revente.save() - - else: - resellform = ResellForm(participant, prefix='resell') - annulform = AnnulForm(participant, prefix='annul') - else: - resellform = ResellForm(participant, prefix='resell') - annulform = AnnulForm(participant, prefix='annul') + soldform = SoldForm(participant, request.POST, prefix='sold') + if soldform.is_valid(): + attributions = soldform.cleaned_data['attributions'] + for attribution in attributions: + if attribution.spectacle.date > timezone.now(): + revente = attribution.revente + revente.date = timezone.now() - timedelta(minutes=65) + revente.soldTo = None + revente.notif_sent = False + revente.tirage_done = False + revente.shotgun = False + if revente.answered_mail: + revente.answered_mail.clear() + revente.save() overdue = participant.attribution_set.filter( spectacle__date__gte=timezone.now(), @@ -407,13 +398,9 @@ def revente(request, tirage_id): revente__seller=participant, revente__date__lte=timezone.now()-timedelta(hours=1)).filter( Q(revente__soldTo__isnull=True) | Q(revente__soldTo=participant)) - sold = participant.attribution_set.filter( - spectacle__date__gte=timezone.now(), - revente__isnull=False, - revente__soldTo__isnull=False) return render(request, "bda-revente.html", - {'tirage': tirage, 'overdue': overdue, "sold": sold, + {'tirage': tirage, 'overdue': overdue, "soldform": soldform, "annulform": annulform, "resellform": resellform}) From d524d9286fa4d3ce7a37ae48716da27cfd4a41a3 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 16 Feb 2017 02:28:57 -0200 Subject: [PATCH 2/5] better annulation check --- bda/forms.py | 4 +--- bda/views.py | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/bda/forms.py b/bda/forms.py index 3bdd7675..37d5fc62 100644 --- a/bda/forms.py +++ b/bda/forms.py @@ -4,8 +4,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -from datetime import timedelta - from django import forms from django.forms.models import BaseInlineFormSet from django.utils import timezone @@ -69,7 +67,7 @@ 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), + revente__notif_sent=False, revente__soldTo__isnull=True) diff --git a/bda/views.py b/bda/views.py index a07a6a4f..6ec8bbdb 100644 --- a/bda/views.py +++ b/bda/views.py @@ -396,7 +396,8 @@ def revente(request, tirage_id): spectacle__date__gte=timezone.now(), revente__isnull=False, revente__seller=participant, - revente__date__lte=timezone.now()-timedelta(hours=1)).filter( + revente__notif_sent=True)\ + .filter( Q(revente__soldTo__isnull=True) | Q(revente__soldTo=participant)) return render(request, "bda-revente.html", From 8953d3de0705a89f13a944f38428d7279143a1b6 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 16 Feb 2017 09:22:15 -0200 Subject: [PATCH 3/5] remove immediate mail --- bda/views.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/bda/views.py b/bda/views.py index 6ec8bbdb..d82c6e4a 100644 --- a/bda/views.py +++ b/bda/views.py @@ -329,7 +329,6 @@ def revente(request, tirage_id): if 'resell' in request.POST: resellform = ResellForm(participant, request.POST, prefix='resell') if resellform.is_valid(): - datatuple = [] attributions = resellform.cleaned_data["attributions"] with transaction.atomic(): for attribution in attributions: @@ -344,18 +343,6 @@ def revente(request, tirage_id): revente.notif_sent = False revente.tirage_done = False revente.shotgun = False - context = { - 'vendeur': participant.user, - 'show': attribution.spectacle, - 'revente': revente - } - datatuple.append(( - 'bda-revente-new', context, - settings.MAIL_DATA['revente']['FROM'], - [participant.user.email] - )) - revente.save() - send_mass_custom_mail(datatuple) # On annule une revente elif 'annul' in request.POST: annulform = AnnulForm(participant, request.POST, prefix='annul') From d96f4ead87b933afae496d33822c5d94a30994d7 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 16 Feb 2017 09:55:19 -0200 Subject: [PATCH 4/5] Revert "remove immediate mail" This reverts commit 8953d3de0705a89f13a944f38428d7279143a1b6. --- bda/views.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bda/views.py b/bda/views.py index d82c6e4a..6ec8bbdb 100644 --- a/bda/views.py +++ b/bda/views.py @@ -329,6 +329,7 @@ def revente(request, tirage_id): if 'resell' in request.POST: resellform = ResellForm(participant, request.POST, prefix='resell') if resellform.is_valid(): + datatuple = [] attributions = resellform.cleaned_data["attributions"] with transaction.atomic(): for attribution in attributions: @@ -343,6 +344,18 @@ def revente(request, tirage_id): revente.notif_sent = False revente.tirage_done = False revente.shotgun = False + context = { + 'vendeur': participant.user, + 'show': attribution.spectacle, + 'revente': revente + } + datatuple.append(( + 'bda-revente-new', context, + settings.MAIL_DATA['revente']['FROM'], + [participant.user.email] + )) + revente.save() + send_mass_custom_mail(datatuple) # On annule une revente elif 'annul' in request.POST: annulform = AnnulForm(participant, request.POST, prefix='annul') From 42a93027d38665c0ac9ae2f99927d7d96f8de812 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 21 Feb 2017 19:49:29 -0300 Subject: [PATCH 5/5] fix pep8 + move template --- bda/forms.py | 10 ++++++---- bda/templates/{bda-revente.html => bda/reventes.html} | 0 bda/views.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) rename bda/templates/{bda-revente.html => bda/reventes.html} (100%) diff --git a/bda/forms.py b/bda/forms.py index 37d5fc62..2029645b 100644 --- a/bda/forms.py +++ b/bda/forms.py @@ -91,7 +91,9 @@ class SoldForm(forms.Form): def __init__(self, participant, *args, **kwargs): super(SoldForm, self).__init__(*args, **kwargs) - self.fields['attributions'].queryset = participant.attribution_set\ - .filter(revente__isnull=False, - revente__soldTo__isnull=False)\ - .exclude(revente__soldTo=participant) + self.fields['attributions'].queryset = ( + participant.attribution_set + .filter(revente__isnull=False, + revente__soldTo__isnull=False) + .exclude(revente__soldTo=participant) + ) diff --git a/bda/templates/bda-revente.html b/bda/templates/bda/reventes.html similarity index 100% rename from bda/templates/bda-revente.html rename to bda/templates/bda/reventes.html diff --git a/bda/views.py b/bda/views.py index 6ec8bbdb..096aacf5 100644 --- a/bda/views.py +++ b/bda/views.py @@ -400,7 +400,7 @@ def revente(request, tirage_id): .filter( Q(revente__soldTo__isnull=True) | Q(revente__soldTo=participant)) - return render(request, "bda-revente.html", + return render(request, "bda/reventes.html", {'tirage': tirage, 'overdue': overdue, "soldform": soldform, "annulform": annulform, "resellform": resellform})