diff --git a/allauthdemo/polls/urls.py b/allauthdemo/polls/urls.py index 8304719..23deeff 100755 --- a/allauthdemo/polls/urls.py +++ b/allauthdemo/polls/urls.py @@ -11,9 +11,9 @@ urlpatterns = [ url(r'^(?P[0-9a-f-]+)/$', login_required(views.EventDetailView.as_view()), name='view-event'), url(r'^(?P[0-9a-f-]+)/polls/$', login_required(views.EventDetailPollsView.as_view()), name='event-polls'), url(r'^(?P[0-9a-f-]+)/entities/$', login_required(views.EventDetailEntitiesView.as_view()), name='event-entities'), + url(r'^(?P[0-9a-f-]+)/results/$', login_required(views.EventDetailResultsView.as_view()), name='event-results'), url(r'^(?P[0-9a-f-]+)/advanced/$', login_required(views.EventDetailAdvancedView.as_view()), name='event-advanced'), url(r'^(?P[0-9a-f-]+)/end/$', login_required(views.event_end), name='end-event'), - url(r'^(?P[0-9a-f-]+)/results/$', login_required(views.results), name='event-results'), url(r'^(?P[0-9a-f-]+)/edit/$', login_required(views.edit_event), name='edit-event'), url(r'^(?P[0-9a-f-]+)/delete/$', login_required(views.del_event), name='del-event'), url(r'^(?P[0-9a-f-]+)/decrypt/$', views.event_trustee_decrypt, name='decrypt-event'), diff --git a/allauthdemo/polls/views.py b/allauthdemo/polls/views.py index a6c8235..a09e6c2 100755 --- a/allauthdemo/polls/views.py +++ b/allauthdemo/polls/views.py @@ -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) @@ -334,7 +338,7 @@ def event_trustee_decrypt(request, event_id): # TODO: Combine partial decryptions and gen results combine_decryptions_and_tally.delay(event) - messages.add_message(request, messages.SUCCESS, 'Your secret key has been successfully submitted') + messages.add_message(request, messages.SUCCESS, 'Your partial decryptions have been successfully submitted') return HttpResponseRedirect(reverse("user_home")) # Without an access key, the client does not have permission to access this page diff --git a/allauthdemo/templates/copyright.html b/allauthdemo/templates/copyright.html index 7c5eb57..131eff1 100755 --- a/allauthdemo/templates/copyright.html +++ b/allauthdemo/templates/copyright.html @@ -1 +1 @@ -© 2014-2015 See LICENSE +© DÄ’MOS 2, Lancaster University 2014-2018. diff --git a/allauthdemo/templates/polls/event_detail_base.html b/allauthdemo/templates/polls/event_detail_base.html index e4bca8f..0f907d7 100755 --- a/allauthdemo/templates/polls/event_detail_base.html +++ b/allauthdemo/templates/polls/event_detail_base.html @@ -44,17 +44,32 @@
diff --git a/allauthdemo/templates/polls/event_detail_entities.html b/allauthdemo/templates/polls/event_detail_entities.html index 2d937af..dc8de85 100755 --- a/allauthdemo/templates/polls/event_detail_entities.html +++ b/allauthdemo/templates/polls/event_detail_entities.html @@ -4,7 +4,7 @@ {% block event_nav_organisers %}active{% endblock %} {% block event_content %} -

Event Organisers

+

Event Organisers ({{ object.users_organisers.all.count }})


{% if object.users_organisers.all %}
    @@ -16,7 +16,7 @@

    No organisers for this Event.

    {% endif %}
    -

    Event Trustees

    +

    Event Trustees ({{ object.users_trustees.all.count }})


    {% if object.users_trustees.all %}
      @@ -28,7 +28,7 @@

      No trustees for this Event.

      {% endif %}
      -

      Voters

      +

      Voters ({{ object.voters.all.count }})


      {% if object.voters.all %}
        diff --git a/allauthdemo/templates/polls/event_list.html b/allauthdemo/templates/polls/event_list.html index 9973fb6..1d66e0c 100755 --- a/allauthdemo/templates/polls/event_list.html +++ b/allauthdemo/templates/polls/event_list.html @@ -27,7 +27,6 @@ No. Polls Actions Status - diff --git a/allauthdemo/templates/polls/event_results.html b/allauthdemo/templates/polls/event_results.html new file mode 100644 index 0000000..1c2059e --- /dev/null +++ b/allauthdemo/templates/polls/event_results.html @@ -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 %} +
        +

        {{ poll_result.name }}

        + + + + + + + + + {% for option in poll_result.options %} + + + + + {% endfor %} + +
        OptionVotes
        {{ option.option }}{{ option.votes }}
        +
        + {% endfor %} +{% endblock %} diff --git a/allauthdemo/templates/polls/event_vote.html b/allauthdemo/templates/polls/event_vote.html index 6fa1c6c..d186ad3 100755 --- a/allauthdemo/templates/polls/event_vote.html +++ b/allauthdemo/templates/polls/event_vote.html @@ -111,9 +111,17 @@