Commit 04b00b9f authored by fred's avatar fred

add page to view vote result

parent 8c9bb862
from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect
from django.views.generic.base import TemplateView
from django.views.generic.list import ListView
from django.contrib import messages
from .models import Vote
......@@ -31,3 +32,20 @@ class VoteView(TemplateView):
return redirect('home')
vote = login_required(VoteView.as_view())
class ResultsView(ListView):
model = Vote
template_name = 'vote_results.html'
def get_queryset(self):
return Vote.objects.order_by('?')
def get_context_data(self, **kwargs):
context = super(ResultsView, self).get_context_data(**kwargs)
context['choice_1'] = self.get_queryset().filter(choice="1").count()
context['choice_2'] = self.get_queryset().filter(choice="2").count()
context['choice_3'] = self.get_queryset().filter(choice="3").count()
return context
vote_results = login_required(ResultsView.as_view())
{% extends "base.html" %}
{% block content %}
<h2>Résultats</h2>
{% for vote in object_list %}
<div style="padding: 1ex; border-bottom: 1px solid #888;">
{% if vote.choice == "1" %}<img src="/static/poll/Panik_2016_32.jpg" height="250" alt="logo 1"/>{% endif %}
{% if vote.choice == "2" %}<img src="/static/poll/Panik_2016_33.jpg" height="250" alt="logo 1"/>{% endif %}
{% if vote.choice == "3" %}<div style="display: table-cell; vertical-align: middle; height: 250px;">Abstention</div>{% endif %}
{% if vote.comment %}
<pre style="margin-top: 1em; font-family: sans-serif;">{{vote.comment}}</pre>
{% endif %}
</div>
{% endfor %}
<div style="border-top: 1px solid #888; padding: 1ex;">
Totaux :
<ul>
<li>1: {{choice_1}}</li>
<li>2: {{choice_2}}</li>
<li>3: {{choice_3}}</li>
</ul>
</div>
{% endblock %}
......@@ -69,7 +69,8 @@ urlpatterns = patterns('',
url(r'^combok/soundfiles/', 'panikombo.views.soundfiles'),
url(r'^combok/episodes/', 'panikombo.views.episodes'),
url(r'^vote/', 'panikdb.poll.views.vote', name='vote'),
url(r'^vote/$', 'panikdb.poll.views.vote', name='vote'),
url(r'^vote/results/$', 'panikdb.poll.views.vote_results', name='vote-results'),
url(r'^admin/', include(admin.site.urls)),
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment