Passe d'un enregistrement à un dictionnaire, trie les valeurs

This commit is contained in:
ludo 2016-06-15 19:34:10 +02:00
parent d535de177c
commit bf4cb4c9ee
2 changed files with 10 additions and 11 deletions

View file

@ -16,10 +16,10 @@
</thead>
{% for participant in participants %}
<tr>
<td>{{participant.user.get_full_name}}</td>
<td>{{participant.user.username}}</td>
<td>{{participant.name}}</td>
<td>{{participant.username}}</td>
<td>{{participant.nb_places}} place{{participant.nb_places|pluralize:",s"}}</td>
<td>{{participant.user.email}}</td>
<td>{{participant.email}}</td>
<td>
<div class={%if participant.paid %}"greenratio"{%else%}"redratio"{%endif%}>
{% if participant.paid %}Oui{% else %}Non{%endif%}
@ -36,14 +36,14 @@
</table>
<button type="button" onclick="toggle('export-mails')">Afficher/Cacher mails participants</button>
<pre id="export-mails" style="display:none">
{%for participant in participants %}{{participant.user.email}}, {%endfor%}
{%for participant in participants %}{{participant.email}}, {%endfor%}
</pre>
<br>
<button type="button" onclick="toggle('export-salle')">Afficher/Cacher liste noms</button>
{% spaceless %}
<pre id="export-salle" style="display:none">
{% for participant in participants %}{{participant.user.get_full_name}}{% if participant.nb_places == 2 %}
{{participant.user.get_full_name}}{%endif%}
{% for participant in participants %}{{participant.name}}{% if participant.nb_places == 2 %}
{{participant.name}}{%endif%}
{% endfor %}
</pre>
{%endspaceless%}

View file

@ -296,14 +296,13 @@ def spectacle(request, tirage_id, spectacle_id):
participants = {}
for attrib in attributions:
participant = attrib.participant
participant.given = attrib.given
participant_info = {'lastname':participant.user.last_name, 'name': participant.user.get_full_name, 'username':participant.user.username, 'email':participant.user.email, 'given':attrib.given, 'paid':participant.paid, 'nb_places':1}
if participant.id in participants:
participants[participant.id].nb_places = 2
participants[participant.id]['nb_places'] = 2
else:
participant.nb_places = 1
participants[participant.id] = participant
participants[participant.id] = participant_info
return render(request, "bda-participants.html", {"spectacle": spectacle, "participants": participants.values()})
return render(request, "bda-participants.html", {"spectacle": spectacle, "participants": sorted(participants.values(), key=lambda part: part['lastname'])})
class SpectacleListView(ListView):
model = Spectacle