Modification des vues

This commit is contained in:
Martin Pépin 2016-06-01 16:09:09 +02:00
parent 4858fe0fb7
commit 7c3984c6fc
2 changed files with 26 additions and 27 deletions

View file

@ -59,12 +59,6 @@ class Algorithm(object):
self.origranks[member][show], self.origranks[member][show],
self.choices[member][show].double)) 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): def __call__(self, seed):
random.seed(seed) random.seed(seed)
results = [] results = []
@ -102,3 +96,4 @@ class Algorithm(object):
self.IncrementRanks(member, i) self.IncrementRanks(member, i)
results.append((show,winners,losers)) results.append((show,winners,losers))
return results return results

View file

@ -39,9 +39,10 @@ class BaseBdaFormSet(BaseInlineFormSet):
spectacles.append(spectacle) spectacles.append(spectacle)
@cof_required @cof_required
def etat_places(request): def etat_places(request, tirage):
spectacles1 = ChoixSpectacle.objects.filter(double_choice = "1").all().values('spectacle','spectacle__title').annotate(total = models.Count('spectacle')) all_spectacles = ChoixSpectacle.objects.filter(tirage = tirage)
spectacles2 = ChoixSpectacle.objects.exclude(double_choice = "1").all().values('spectacle','spectacle__title').annotate(total = models.Count('spectacle')) 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 = Spectacle.objects.all()
spectacles_dict = {} spectacles_dict = {}
total = 0 total = 0
@ -66,9 +67,9 @@ def _hash_queryset(queryset):
return hasher.hexdigest() return hasher.hexdigest()
@cof_required @cof_required
def places(request): def places(request, tirage):
participant, created = Participant.objects.get_or_create(user = request.user) 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]) total = sum([place.spectacle.price for place in places])
filtered_places = [] filtered_places = []
places_dict = {} places_dict = {}
@ -95,9 +96,9 @@ def places(request):
"warning": warning}) "warning": warning})
@cof_required @cof_required
def places_ics(request): def places_ics(request, tirage):
participant, created = Participant.objects.get_or_create(user = request.user) 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 = [] filtered_places = []
places_dict = {} places_dict = {}
spectacles = [] spectacles = []
@ -116,12 +117,13 @@ def places_ics(request):
"places": filtered_places}, content_type="text/calendar") "places": filtered_places}, content_type="text/calendar")
@cof_required @cof_required
def inscription(request): def inscription(request, tirage):
if datetime.now() > datetime(2015, 10, 4, 12, 00) and request.user.username != "seguin": if datetime.now() > datetime(2025, 10, 4, 12, 00):
participant, created = Participant.objects.get_or_create(user = request.user) participant, created = Participant.objects.get_or_create(user = request.user)
choices = participant.choixspectacle_set.order_by("priority").all() 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}) 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) participant, created = Participant.objects.get_or_create(user = request.user)
success = False success = False
stateerror = False stateerror = False
@ -133,20 +135,22 @@ def inscription(request):
else: else:
formset = BdaFormSet(request.POST, instance = participant) formset = BdaFormSet(request.POST, instance = participant)
if formset.is_valid(): if formset.is_valid():
#ChoixSpectacle.objects.filter(participant = participant).delete() choix = formset.save(commit=False)
formset.save() for c in choix:
c.tirage = tirage
c.save()
success = True success = True
formset = BdaFormSet(instance = participant) formset = BdaFormSet(instance = participant)
else: else:
formset = BdaFormSet(instance = participant) formset = BdaFormSet(instance = participant, )
dbstate = _hash_queryset(participant.choixspectacle_set.all()) dbstate = _hash_queryset(participant.choixspectacle_set.all())
total_price = 0 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 total_price += choice.spectacle.price
if choice.double: 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}) 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) form = TokenForm(request.POST)
if not form.is_valid(): if not form.is_valid():
return tirage(request) return tirage(request)
@ -154,7 +158,7 @@ def do_tirage(request):
data = {} data = {}
shows = Spectacle.objects.select_related().all() shows = Spectacle.objects.select_related().all()
members = Participant.objects.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) algo = Algorithm(shows, members, choices)
results = algo(form.cleaned_data["token"]) results = algo(form.cleaned_data["token"])
total_slots = 0 total_slots = 0
@ -211,11 +215,11 @@ class TokenForm(forms.Form):
token = forms.CharField(widget = forms.widgets.Textarea()) token = forms.CharField(widget = forms.widgets.Textarea())
@login_required @login_required
def tirage(request): def tirage(request, tirage):
if request.POST: if request.POST:
form = TokenForm(request.POST) form = TokenForm(request.POST)
if form.is_valid(): if form.is_valid():
return do_tirage(request) return do_tirage(request, tirage)
else: else:
form = TokenForm() form = TokenForm()
return render(request, "bda-token.html", {"form": form}) return render(request, "bda-token.html", {"form": form})
@ -282,8 +286,8 @@ def unpaid(request):
return render(request, "bda-unpaid.html", {"unpaid": Participant.objects.filter(paid = False).all()}) return render(request, "bda-unpaid.html", {"unpaid": Participant.objects.filter(paid = False).all()})
@buro_required @buro_required
def liste_spectacles_ics(request): def liste_spectacles_ics(request, tirage):
spectacles = Spectacle.objects.order_by("date").all() spectacles = Spectacle.objects.filter(tirage=tirage).order_by("date").all()
for spectacle in spectacles: for spectacle in spectacles:
spectacle.dtend = spectacle.date + timedelta(seconds=7200) spectacle.dtend = spectacle.date + timedelta(seconds=7200)
return render(request, "liste_spectacles.ics", return render(request, "liste_spectacles.ics",