From 7c3984c6fcfdc3a47a673d79e3df4f36f83c32f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Wed, 1 Jun 2016 16:09:09 +0200 Subject: [PATCH] Modification des vues --- bda/algorithm.py | 7 +------ bda/views.py | 46 +++++++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/bda/algorithm.py b/bda/algorithm.py index 623f9756..bce41282 100644 --- a/bda/algorithm.py +++ b/bda/algorithm.py @@ -59,12 +59,6 @@ class Algorithm(object): self.origranks[member][show], self.choices[member][show].double)) - """ - Pour les 2 Walkyries: c'est Sandefer - - Pour les 4 places pour l'Oratorio c'est Maxence Arutkin - """ - def __call__(self, seed): random.seed(seed) results = [] @@ -102,3 +96,4 @@ class Algorithm(object): self.IncrementRanks(member, i) results.append((show,winners,losers)) return results + diff --git a/bda/views.py b/bda/views.py index 78ac0c83..1971686d 100644 --- a/bda/views.py +++ b/bda/views.py @@ -39,9 +39,10 @@ class BaseBdaFormSet(BaseInlineFormSet): spectacles.append(spectacle) @cof_required -def etat_places(request): - spectacles1 = ChoixSpectacle.objects.filter(double_choice = "1").all().values('spectacle','spectacle__title').annotate(total = models.Count('spectacle')) - spectacles2 = ChoixSpectacle.objects.exclude(double_choice = "1").all().values('spectacle','spectacle__title').annotate(total = models.Count('spectacle')) +def etat_places(request, tirage): + all_spectacles = ChoixSpectacle.objects.filter(tirage = tirage) + spectacles1 = all_spectacles.filter(double_choice = "1").all().values('spectacle','spectacle__title').annotate(total = models.Count('spectacle')) + spectacles2 = all_spectacles.exclude(double_choice = "1").all().values('spectacle','spectacle__title').annotate(total = models.Count('spectacle')) spectacles = Spectacle.objects.all() spectacles_dict = {} total = 0 @@ -66,9 +67,9 @@ def _hash_queryset(queryset): return hasher.hexdigest() @cof_required -def places(request): +def places(request, tirage): participant, created = Participant.objects.get_or_create(user = request.user) - places = participant.attribution_set.order_by("spectacle__date", "spectacle").all() + places = participant.attribution_set.filter(tirage = tirage).order_by("spectacle__date", "spectacle").all() total = sum([place.spectacle.price for place in places]) filtered_places = [] places_dict = {} @@ -95,9 +96,9 @@ def places(request): "warning": warning}) @cof_required -def places_ics(request): +def places_ics(request, tirage): participant, created = Participant.objects.get_or_create(user = request.user) - places = participant.attribution_set.order_by("spectacle__date", "spectacle").all() + places = participant.attribution_set.filter(tirage=tirage).order_by("spectacle__date", "spectacle").all() filtered_places = [] places_dict = {} spectacles = [] @@ -116,12 +117,13 @@ def places_ics(request): "places": filtered_places}, content_type="text/calendar") @cof_required -def inscription(request): - if datetime.now() > datetime(2015, 10, 4, 12, 00) and request.user.username != "seguin": +def inscription(request, tirage): + if datetime.now() > datetime(2025, 10, 4, 12, 00): participant, created = Participant.objects.get_or_create(user = request.user) choices = participant.choixspectacle_set.order_by("priority").all() return render(request, "resume_inscription.html", {"error_title": "C'est fini !", "error_description": u"Tirage au sort dans la journée !", "choices": choices}) - BdaFormSet = inlineformset_factory(Participant, ChoixSpectacle, fields = ("spectacle","double_choice","priority",), formset = BaseBdaFormSet) + BdaFormSet = inlineformset_factory(Participant, ChoixSpectacle, fields = + ("spectacle","double_choice","priority"), formset = BaseBdaFormSet) participant, created = Participant.objects.get_or_create(user = request.user) success = False stateerror = False @@ -133,20 +135,22 @@ def inscription(request): else: formset = BdaFormSet(request.POST, instance = participant) if formset.is_valid(): - #ChoixSpectacle.objects.filter(participant = participant).delete() - formset.save() + choix = formset.save(commit=False) + for c in choix: + c.tirage = tirage + c.save() success = True formset = BdaFormSet(instance = participant) else: - formset = BdaFormSet(instance = participant) + formset = BdaFormSet(instance = participant, ) dbstate = _hash_queryset(participant.choixspectacle_set.all()) total_price = 0 - for choice in participant.choixspectacle_set.all(): + for choice in participant.choixspectacle_set.filter(tirage=tirage).all(): total_price += choice.spectacle.price if choice.double: total_price += choice.spectacle.price return render(request, "inscription-bda.html", {"formset": formset, "success": success, "total_price": total_price, "dbstate": dbstate, "stateerror": stateerror}) -def do_tirage(request): +def do_tirage(request, tirage): form = TokenForm(request.POST) if not form.is_valid(): return tirage(request) @@ -154,7 +158,7 @@ def do_tirage(request): data = {} shows = Spectacle.objects.select_related().all() members = Participant.objects.all() - choices = ChoixSpectacle.objects.order_by('participant', 'priority').select_related().all() + choices = ChoixSpectacle.objects.filter(tirage=tirage).order_by('participant', 'priority').select_related().all() algo = Algorithm(shows, members, choices) results = algo(form.cleaned_data["token"]) total_slots = 0 @@ -211,11 +215,11 @@ class TokenForm(forms.Form): token = forms.CharField(widget = forms.widgets.Textarea()) @login_required -def tirage(request): +def tirage(request, tirage): if request.POST: form = TokenForm(request.POST) if form.is_valid(): - return do_tirage(request) + return do_tirage(request, tirage) else: form = TokenForm() return render(request, "bda-token.html", {"form": form}) @@ -282,9 +286,9 @@ def unpaid(request): return render(request, "bda-unpaid.html", {"unpaid": Participant.objects.filter(paid = False).all()}) @buro_required -def liste_spectacles_ics(request): - spectacles = Spectacle.objects.order_by("date").all() +def liste_spectacles_ics(request, tirage): + spectacles = Spectacle.objects.filter(tirage=tirage).order_by("date").all() for spectacle in spectacles: spectacle.dtend = spectacle.date + timedelta(seconds=7200) return render(request, "liste_spectacles.ics", - {"spectacles": spectacles}, content_type="text/calendar") \ No newline at end of file + {"spectacles": spectacles}, content_type="text/calendar")