scrap buying many resells

This commit is contained in:
Ludovic Stephan 2016-09-19 16:08:12 +02:00
parent 7f2717c10c
commit f679338910
4 changed files with 17 additions and 29 deletions

View file

@ -44,14 +44,6 @@ class AttributionModelMultipleChoiceField(forms.ModelMultipleChoiceField):
return "%s" % obj.spectacle 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): class ResellForm(forms.Form):
attributions = AttributionModelMultipleChoiceField( attributions = AttributionModelMultipleChoiceField(
queryset=Attribution.objects.none(), queryset=Attribution.objects.none(),

View file

@ -272,8 +272,7 @@ class SpectacleRevente(models.Model):
spectacle = self.attribution.spectacle spectacle = self.attribution.spectacle
seller = self.seller seller = self.seller
if inscrits.exists(): if inscrits.exists():
idx = random.randint(0, inscrits.count() - 1) winner = random.choice(inscrits.all())
winner = inscrits.all()[idx]
self.soldTo = winner self.soldTo = winner
mail_buyer = """Bonjour, mail_buyer = """Bonjour,

View file

@ -1,9 +1,11 @@
{% extends "base_title.html" %} {% extends "base_title.html" %}
{% load staticfiles %} {% load staticfiles %}
{%block realcontent %} {%block realcontent %}
<h2>Rachat d'une place</h2> <h2>Rachat d'une place</h2>
Note : ce mail sera envoyé à une personne au hasard revendant sa place. <form action="" method="post">
{% csrf_token %}
<pre> <pre>
Bonjour ! Bonjour !
@ -12,8 +14,7 @@ Contacte-moi si tu es toujours intéressé-e !
{{user.get_full_name}} ({{user.email}}) {{user.get_full_name}} ({{user.email}})
</pre> </pre>
<form action="" method="post">
{% csrf_token %}
<input type="submit" class="btn btn-primary pull-right" value="Envoyer"> <input type="submit" class="btn btn-primary pull-right" value="Envoyer">
</form> </form>
<p class="bda-prix">Note : ce mail sera envoyé à une personne au hasard revendant sa place.</p>
{%endblock%} {%endblock%}

View file

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