Added a new UI feature which now shows all of the event results (once decrypted) in a basic but easy to read table which can be enhanced at a later point

This commit is contained in:
vince0656 2018-07-17 12:15:24 +01:00
parent 0ff10474c4
commit 33398b9993
8 changed files with 79 additions and 25 deletions

View file

@ -11,9 +11,9 @@ urlpatterns = [
url(r'^(?P<pk>[0-9a-f-]+)/$', login_required(views.EventDetailView.as_view()), name='view-event'),
url(r'^(?P<pk>[0-9a-f-]+)/polls/$', login_required(views.EventDetailPollsView.as_view()), name='event-polls'),
url(r'^(?P<pk>[0-9a-f-]+)/entities/$', login_required(views.EventDetailEntitiesView.as_view()), name='event-entities'),
url(r'^(?P<pk>[0-9a-f-]+)/results/$', login_required(views.EventDetailResultsView.as_view()), name='event-results'),
url(r'^(?P<pk>[0-9a-f-]+)/advanced/$', login_required(views.EventDetailAdvancedView.as_view()), name='event-advanced'),
url(r'^(?P<event_id>[0-9a-f-]+)/end/$', login_required(views.event_end), name='end-event'),
url(r'^(?P<event_id>[0-9a-f-]+)/results/$', login_required(views.results), name='event-results'),
url(r'^(?P<event_id>[0-9a-f-]+)/edit/$', login_required(views.edit_event), name='edit-event'),
url(r'^(?P<event_id>[0-9a-f-]+)/delete/$', login_required(views.del_event), name='del-event'),
url(r'^(?P<event_id>[0-9a-f-]+)/decrypt/$', views.event_trustee_decrypt, name='decrypt-event'),

View file

@ -38,6 +38,21 @@ class EventDetailView(generic.DetailView):
context['is_organiser'] = (not self.request.user.is_anonymous()) and (self.object.users_organisers.filter(email=self.request.user.email).exists())
context['decrypted'] = self.object.status() == "Decrypted"
# Get the results for all polls
polls = self.object.polls.all()
results = list()
for poll in polls:
result_json = poll.result_json
if result_json[len(result_json)-1] == ',':
result_json = result_json[0:len(result_json)-1]
result_json = json.loads(result_json)
results.append(result_json)
context['event_results'] = results
return context
@ -63,6 +78,10 @@ class PollDetailView(generic.View):
return context
class EventDetailResultsView(EventDetailView):
template_name = "polls/event_results.html"
def util_get_poll_by_event_index(event, poll_id):
return event.polls.get(uuid=poll_id)
@ -248,21 +267,6 @@ def event_end(request, event_id):
return HttpResponseRedirect(reverse('polls:view-event', args=[event_id]))
# Returns a JSONed version of the results
def results(request, event_id):
event = get_object_or_404(Event, pk=event_id)
polls = event.polls.all()
results = ""
results += "{\"polls\":["
for poll in polls:
results += poll.result_json
results += "]}"
return HttpResponse(results)
def event_trustee_decrypt(request, event_id):
event = get_object_or_404(Event, pk=event_id)
access_key = request.GET.get('key', None)

View file

@ -1 +1 @@
&copy; 2014-2015 See LICENSE
&copy; DĒMOS 2, Lancaster University 2014-2018.

View file

@ -44,17 +44,32 @@
<br/>
<ul class="nav nav-tabs">
<li class="{% block event_nav_details %}{% endblock %}">
<a href="{% url 'polls:view-event' event.uuid %}"><strong>Summary</strong></a>
<a href="{% url 'polls:view-event' event.uuid %}">
<span class="glyphicon glyphicon-dashboard"></span> <strong>Summary</strong>
</a>
</li>
<li class="{% block event_nav_polls %}{% endblock %}">
<a href="{% url 'polls:event-polls' event.uuid %}"><strong>Polls ({{ object.polls.count }})</strong></a>
<a href="{% url 'polls:event-polls' event.uuid %}">
<span class="glyphicon glyphicon-list-alt"></span> <strong>Polls ({{ object.polls.count }})</strong>
</a>
</li>
<li class="{% block event_nav_organisers %}{% endblock %}">
<a href="{% url 'polls:event-entities' event.uuid %}"><strong>Entities</strong></a>
<a href="{% url 'polls:event-entities' event.uuid %}">
<span class="glyphicon glyphicon-user"></span> <strong>Entities</strong>
</a>
</li>
{% if decrypted == True and object.ended == True %}
<li class="{% block event_nav_results %}{% endblock %}">
<a href="{% url 'polls:event-results' event.uuid %}">
<span class="glyphicon glyphicon-stats"></span> <strong>Results</strong>
</a>
</li>
{% endif %}
{% if is_organiser %}
<li class="{% block event_nav_launch %}{% endblock %}">
<a href="{% url 'polls:event-advanced' event.uuid %}"><strong>Advanced</strong></a>
<a href="{% url 'polls:event-advanced' event.uuid %}">
<span class="glyphicon glyphicon-info-sign"></span> <strong>Advanced</strong>
</a>
</li>
{% endif %}
</ul>

View file

@ -4,7 +4,7 @@
{% block event_nav_organisers %}active{% endblock %}
{% block event_content %}
<h2>Event Organisers</h2>
<h2>Event Organisers ({{ object.users_organisers.all.count }})</h2>
<hr/>
{% if object.users_organisers.all %}
<ul class="list-group">
@ -16,7 +16,7 @@
<p>No organisers for this Event.</p>
{% endif %}
<hr/>
<h2>Event Trustees</h2>
<h2>Event Trustees ({{ object.users_trustees.all.count }})</h2>
<hr/>
{% if object.users_trustees.all %}
<ul class="list-group">
@ -28,7 +28,7 @@
<p>No trustees for this Event.</p>
{% endif %}
<hr/>
<h2>Voters</h2>
<h2>Voters ({{ object.voters.all.count }})</h2>
<hr/>
{% if object.voters.all %}
<ul class="list-group">

View file

@ -27,7 +27,6 @@
<th class="text-center">No. Polls</th>
<th class="text-center">Actions</th>
<th class="text-center">Status</th>
<!-- Could also add a delete column to easily remove an event -->
</tr>
</thead>
<tbody>

View file

@ -0,0 +1,28 @@
{% extends "polls/event_detail_base.html" %}
{% load staticfiles %}
{% load bootstrap3 %}
{% block event_nav_results %}active{% endblock %}
{% block event_content %}
{% for poll_result in event_results %}
<div class="form-group">
<h3 class="marginTopResultTable">{{ poll_result.name }}</h3>
<table id="results-table-{{ forloop.counter }}" class="table table-hover">
<thead>
<tr>
<th class="resultsCol text-center">Option</th>
<th class="resultsCol text-center">Votes</th>
</tr>
</thead>
<tbody>
{% for option in poll_result.options %}
<tr>
<td class="resultsCol text-center">{{ option.option }}</td>
<td class="resultsCol text-center">{{ option.votes }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endfor %}
{% endblock %}

View file

@ -180,6 +180,14 @@ input[type="file"] {
padding-left: 16px;
}
.resultsCol {
width: 50%
}
.marginTopResultTable {
margin-top: 1.25em;
}
/* Voting page */
.big-checkbox {
width: 30px !important; height: 30px;