From 759893f72831e8204f48d98171caa1de77be0be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Mon, 6 Jun 2016 11:19:27 +0200 Subject: [PATCH] Fusion BdA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Les tirages ont un champ `active` pour indiquer si le tirage doit être affiché ou considéré comme archivé. - La page d'accueil n'affiche que les tirages actifs. - Le formulaire d'inscription ne propose plus que les spectacles du tirage concerné. --- bda/models.py | 1 + bda/views.py | 10 ++++++++-- gestioncof/templates/home.html | 18 ++++++++++-------- gestioncof/views.py | 11 +++++++---- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/bda/models.py b/bda/models.py index 9fc66075..2926bb80 100644 --- a/bda/models.py +++ b/bda/models.py @@ -12,6 +12,7 @@ class Tirage(models.Model): ouverture = models.DateTimeField("Date et heure d'ouverture du tirage") fermeture = models.DateTimeField("Date et heure de fermerture du tirage") token = models.TextField("Graine du tirage", blank=True) + active = models.BooleanField("Tirage actif", default=True) def date_no_seconds(self): return self.fermeture.strftime('%d %b %Y %H:%M') diff --git a/bda/views.py b/bda/views.py index a14380d8..9a901cfb 100644 --- a/bda/views.py +++ b/bda/views.py @@ -133,10 +133,16 @@ def inscription(request, tirage_id): { "error_title": "C'est fini !", "error_description": u"Tirage au sort dans la journée !", "choices": choices}) - BdaFormSet = inlineformset_factory(Participant, + def formfield_callback(f, **kwargs): + if f.name == "spectacle": + kwargs['queryset'] = Spectacle.objects.filter(tirage=tirage) + return f.formfield(**kwargs) + BdaFormSet = inlineformset_factory( + Participant, ChoixSpectacle, fields=("spectacle","double_choice","priority"), - formset=BaseBdaFormSet) + formset=BaseBdaFormSet, + formfield_callback=formfield_callback) participant, created = Participant.objects.get_or_create( user=request.user, tirage=tirage) success = False diff --git a/gestioncof/templates/home.html b/gestioncof/templates/home.html index fe713f61..f0aecebc 100644 --- a/gestioncof/templates/home.html +++ b/gestioncof/templates/home.html @@ -24,17 +24,19 @@ {% if user.profile.is_cof %} -

BdA

+ {% if open_tirages %} +

Tirages du BdA

+ {% for tirage in open_tirages %} + {% endfor %} + {% endif %} {% endif %}

Divers

diff --git a/gestioncof/views.py b/gestioncof/views.py index 97abfd7c..b90b5842 100644 --- a/gestioncof/views.py +++ b/gestioncof/views.py @@ -20,14 +20,17 @@ from gestioncof.forms import UserProfileForm, EventStatusFilterForm, \ SurveyForm, SurveyStatusFilterForm, RegistrationUserForm, \ RegistrationProfileForm, AdminEventForm, EventForm +from bda.models import Tirage + import re @login_required def home(request): - data = {"surveys": Survey.objects.filter(old = False).all(), - "events": Event.objects.filter(old = False).all(), - "open_surveys": Survey.objects.filter(survey_open = True, old = False).all(), - "open_events": Event.objects.filter(registration_open = True, old = False).all()} + data = {"surveys": Survey.objects.filter(old=False).all(), + "events": Event.objects.filter(old=False).all(), + "open_surveys": Survey.objects.filter(survey_open=True, old=False).all(), + "open_events": Event.objects.filter(registration_open=True, old=False).all(), + "open_tirages": Tirage.objects.filter(active=True).all()} return render(request, "home.html", data) def login(request):