number of each instrument on the event view
This commit is contained in:
parent
1a935523c6
commit
116c41709c
2 changed files with 36 additions and 1 deletions
|
@ -67,4 +67,22 @@
|
|||
<p><a href="{% url 'calendrier:reponse' event.id %}">Répondre à l'événement</a></p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if instrument_count %}
|
||||
<table>
|
||||
<tr>
|
||||
<th>Instrument</th>
|
||||
<th>Oui</th>
|
||||
<th>Peut-être</th>
|
||||
</tr>
|
||||
{% for instrument, sure, maybe in instrument_count %}
|
||||
<tr>
|
||||
<td>{{ instrument }}</td>
|
||||
<td>{{ sure }}</td>
|
||||
<td>{{ maybe }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
from collections import defaultdict
|
||||
from datetime import date, datetime
|
||||
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.contrib.sites.shortcuts import get_current_site
|
||||
from django.db.models import Count
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.views.generic import UpdateView, DeleteView
|
||||
from django.urls import reverse, reverse_lazy
|
||||
|
@ -71,14 +73,29 @@ def calendar(request, pYear, pMonth):
|
|||
|
||||
def view_event(request, id):
|
||||
event = get_object_or_404(Event, id=id)
|
||||
participants = event.participants_set.all()
|
||||
|
||||
# Restricted event, only erneso users can see it
|
||||
if not request.user.is_authenticated and not event.calendrier:
|
||||
return redirect(reverse('calendrier:home'))
|
||||
|
||||
participants = event.participants_set.all()
|
||||
# Count the number of occurences of each instrument
|
||||
instrument_count = defaultdict(lambda: (0, 0))
|
||||
for participant in participants:
|
||||
instrument = participant.participant.instru
|
||||
sure, maybe = instrument_count[instrument]
|
||||
if participant.reponse == "oui":
|
||||
instrument_count[instrument] = (sure + 1, maybe)
|
||||
elif participant.reponse == "pe":
|
||||
instrument_count[instrument] = (sure, maybe + 1)
|
||||
instrument_count = [
|
||||
(instrument, sure, maybe)
|
||||
for instrument, (sure, maybe) in instrument_count.items()
|
||||
]
|
||||
|
||||
context = {
|
||||
"event": event,
|
||||
"instrument_count": instrument_count,
|
||||
"participants": participants,
|
||||
"nboui": len(participants.filter(reponse="oui")),
|
||||
"nbpe": len(participants.filter(reponse="pe")),
|
||||
|
|
Loading…
Reference in a new issue