From f67933891072a91cecd8e9d918155ea5fd3befb2 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 19 Sep 2016 16:08:12 +0200 Subject: [PATCH] scrap buying many resells --- bda/forms.py | 8 -------- bda/models.py | 3 +-- bda/templates/revente-confirm.html | 7 ++++--- bda/views.py | 28 ++++++++++++---------------- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/bda/forms.py b/bda/forms.py index f50c496b..c2eec894 100644 --- a/bda/forms.py +++ b/bda/forms.py @@ -44,14 +44,6 @@ class AttributionModelMultipleChoiceField(forms.ModelMultipleChoiceField): return "%s" % obj.spectacle -class BuyResellForm(forms.Form): - num = forms.ChoiceField(choices=[]) - - def __init__(self, spectacle, *args, **kwargs): - super(BuyResellForm, self).__init__(*args, **kwargs) - self.fields['num'].choices = range(1, spectacle.revente.count()) - - class ResellForm(forms.Form): attributions = AttributionModelMultipleChoiceField( queryset=Attribution.objects.none(), diff --git a/bda/models.py b/bda/models.py index ad9df179..9b467f9c 100644 --- a/bda/models.py +++ b/bda/models.py @@ -272,8 +272,7 @@ class SpectacleRevente(models.Model): spectacle = self.attribution.spectacle seller = self.seller if inscrits.exists(): - idx = random.randint(0, inscrits.count() - 1) - winner = inscrits.all()[idx] + winner = random.choice(inscrits.all()) self.soldTo = winner mail_buyer = """Bonjour, diff --git a/bda/templates/revente-confirm.html b/bda/templates/revente-confirm.html index 60cac8b8..d7614c25 100644 --- a/bda/templates/revente-confirm.html +++ b/bda/templates/revente-confirm.html @@ -1,9 +1,11 @@ {% extends "base_title.html" %} {% load staticfiles %} + {%block realcontent %}

Rachat d'une place

-Note : ce mail sera envoyé à une personne au hasard revendant sa place. +
+{% csrf_token %}
 Bonjour !
 
@@ -12,8 +14,7 @@ Contacte-moi si tu es toujours intéressé-e !
 
 {{user.get_full_name}} ({{user.email}})
 
- -{% csrf_token %}
+

Note : ce mail sera envoyé à une personne au hasard revendant sa place.

{%endblock%} diff --git a/bda/views.py b/bda/views.py index 7b3b30e9..7ea26df4 100644 --- a/bda/views.py +++ b/bda/views.py @@ -28,7 +28,7 @@ from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\ from bda.algorithm import Algorithm from bda.forms import BaseBdaFormSet, TokenForm, ResellForm, AnnulForm,\ - InscriptionReventeForm, BuyResellForm + InscriptionReventeForm @cof_required @@ -435,14 +435,10 @@ def buy_revente(request, spectacle_id): return render(request, "bda-no-revente.html", {}) if request.POST: - form = BuyResellForm(spectacle, request.POST) - if form.is_valid(): - num = form.cleaned_data['num'] - reventes = random.sample(reventes.all(), num) - for revente in reventes: - revente.soldTo = participant - revente.save() - mail = """Bonjour ! + revente = random.choice(reventes.all(), 1) + revente.soldTo = participant + revente.save() + mail = """Bonjour ! Je souhaiterais racheter ta place pour %s le %s (%s) à %.02f€. Contacte-moi si tu es toujours intéressé·e ! @@ -450,13 +446,13 @@ Contacte-moi si tu es toujours intéressé·e ! %s (%s)""" % (spectacle.title, spectacle.date_no_seconds(), spectacle.location, spectacle.price, request.user.get_full_name(), request.user.email) - send_mail("BdA-Revente : %s" % spectacle.title, mail, - request.user.email, - [revente.seller.user.email], - fail_silently=False) - return render(request, "bda-success.html", - {"seller": revente.seller.user, - "spectacle": spectacle}) + send_mail("BdA-Revente : %s" % spectacle.title, mail, + request.user.email, + [revente.seller.user.email], + fail_silently=False) + return render(request, "bda-success.html", + {"seller": revente.participant.user, + "spectacle": spectacle}) return render(request, "revente-confirm.html", {"spectacle": spectacle,