use forms

This commit is contained in:
Ludovic Stephan 2016-07-25 23:03:33 +02:00
parent 90581af528
commit d12a21d44c
4 changed files with 21 additions and 44 deletions

View file

@ -26,7 +26,7 @@ from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\
Tirage, render_template, SpectacleRevente
from bda.algorithm import Algorithm
from bda.forms import BaseBdaFormSet, TokenForm
from bda.forms import BaseBdaFormSet, TokenForm, ResellForm
@cof_required
@ -303,23 +303,17 @@ def revente(request, tirage_id):
user=request.user, tirage=tirage)
if not participant.paid:
return render(request, "bda-notpaid.html", {})
if request.POST:
for attr_id in request.POST.getlist('resell'):
attribution = Attribution.objects.get(id=int(attr_id))
revente = SpectacleRevente(attribution=attribution)
revente.save()
if 'annul' in request.POST:
revente = SpectacleRevente.objects\
.get(attribution__pk=request.POST['annul'])
revente.delete()
attributions = participant.attribution_set.filter(
spectacle__date__gte=timezone.now)
resell = attributions.filter(revente__isnull=False)
no_resell = attributions.filter(revente__isnull=True)
if request.method == 'POST':
form = ResellForm(participant, request.POST)
if form.is_valid():
attributions = form.cleaned_data["attributions"]
for attribution in attributions:
revente = SpectacleRevente(attribution=attribution)
revente.save()
else:
form = ResellForm(participant)
return render(request, "bda-revente.html",
{"participant": participant, 'tirage': tirage,
"resell": resell, "no_resell": no_resell})
{'tirage': tirage, "form": form})
@login_required