Merge branch 'Kerl/fix_choices_count' into 'master'

Rend la page état des demandes/ratios cohérente

- Le nombre total de demandes affiché est désormais le nombre de places
  demandées et non le nombre de personnes ayant fait des demandes. Ainsi
  ce nombre correspond à la somme des totaux par spectacle affiché

- Au passage, on déplace le template de cette vue dans un dossier plus
  adéquat et on ajoute une docstring sur la vue.

Fixes #106

See merge request !145
This commit is contained in:
Martin Pepin 2017-01-07 16:49:21 +01:00
commit 6aa237c4bc
3 changed files with 24 additions and 20 deletions

View file

@ -1,9 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import calendar import calendar
import random import random
from datetime import timedelta from datetime import timedelta
@ -53,7 +49,6 @@ class CategorieSpectacle(models.Model):
verbose_name = "Catégorie" verbose_name = "Catégorie"
@python_2_unicode_compatible
class Spectacle(models.Model): class Spectacle(models.Model):
title = models.CharField("Titre", max_length=300) title = models.CharField("Titre", max_length=300)
category = models.ForeignKey(CategorieSpectacle, blank=True, null=True) category = models.ForeignKey(CategorieSpectacle, blank=True, null=True)

View file

@ -38,7 +38,10 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<span class="bda-prix">Total : {{ total }} demandes</span> <span class="bda-prix">
Total&nbsp;: {{ total }} place{{ total|pluralize }} demandée{{ total|pluralize }}
sur {{ proposed }} place{{ proposed|pluralize }} proposée{{ proposed|pluralize }}
</span>
<script type="text/javascript" <script type="text/javascript"
src="{% static "js/jquery.min.js" %}"></script> src="{% static "js/jquery.min.js" %}"></script>
<script type="text/javascript" <script type="text/javascript"

View file

@ -1,41 +1,42 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import random import random
import hashlib
import time
from datetime import timedelta
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.db import models, transaction from django.db import models, transaction
from django.db.models import Count, Q from django.db.models import Count, Q, Sum
from django.core import serializers, mail from django.core import serializers, mail
from django.forms.models import inlineformset_factory from django.forms.models import inlineformset_factory
from django.http import HttpResponseBadRequest, HttpResponseRedirect from django.http import HttpResponseBadRequest, HttpResponseRedirect
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.conf import settings from django.conf import settings
import hashlib
from django.core.mail import send_mail from django.core.mail import send_mail
from django.template import loader from django.template import loader
from django.utils import timezone from django.utils import timezone
from django.views.generic.list import ListView from django.views.generic.list import ListView
import time
from datetime import timedelta
from gestioncof.decorators import cof_required, buro_required from gestioncof.decorators import cof_required, buro_required
from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\ from bda.models import Spectacle, Participant, ChoixSpectacle, Attribution,\
Tirage, SpectacleRevente Tirage, SpectacleRevente
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 InscriptionReventeForm
@cof_required @cof_required
def etat_places(request, tirage_id): def etat_places(request, tirage_id):
"""
Résumé des spectacles d'un tirage avec pour chaque spectacle :
- Le nombre de places en jeu
- Le nombre de demandes
- Le ratio demandes/places
Et le total de toutes les demandes
"""
tirage = get_object_or_404(Tirage, id=tirage_id) tirage = get_object_or_404(Tirage, id=tirage_id)
spectacles1 = ChoixSpectacle.objects \ spectacles1 = ChoixSpectacle.objects \
.filter(spectacle__tirage=tirage) \ .filter(spectacle__tirage=tirage) \
@ -67,9 +68,14 @@ def etat_places(request, tirage_id):
spectacles_dict[spectacle["spectacle"]].ratio = \ spectacles_dict[spectacle["spectacle"]].ratio = \
spectacles_dict[spectacle["spectacle"]].total / \ spectacles_dict[spectacle["spectacle"]].total / \
spectacles_dict[spectacle["spectacle"]].slots spectacles_dict[spectacle["spectacle"]].slots
total += spectacle["total"] total += 2*spectacle["total"]
return render(request, "etat-places.html", context = {
{"spectacles": spectacles, "total": total, 'tirage': tirage}) "proposed": tirage.spectacle_set.aggregate(Sum('slots'))['slots__sum'],
"spectacles": spectacles,
"total": total,
'tirage': tirage
}
return render(request, "bda/etat-places.html", context)
def _hash_queryset(queryset): def _hash_queryset(queryset):