Commit c5a7e29e authored by chimekkoo's avatar chimekkoo
Browse files

Restricted statistics view during voting (krasnal's changes)

parent 448ca0ee
Loading
Loading
Loading
Loading
+6 −1
Changes for stats/admin.py: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
from django.contrib import admin
from django.contrib import admin, messages
from django.shortcuts import render, get_object_or_404
from django.db.models import Count, Q
from django.contrib.admin.views.decorators import staff_member_required
@@ -6,6 +6,7 @@ from django.urls import reverse
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.urls import path
from django.http import HttpResponseRedirect

from elections.models import Election
from vote.models import Participation
@@ -61,6 +62,10 @@ class ElectionStatsAdmin(admin.ModelAdmin):
        election = get_object_or_404(Election, id=election_id)
        context = admin.site.each_context(request)

        if election.is_active:
            messages.error(request, 'Statystyki są wyłączone w czasie trwania głosowania.')
            return HttpResponseRedirect(reverse('admin:live_results', args=[election.id]))

        total_eligible = Voter.objects.count()
        total_participated = Participation.objects.filter(election=election).count()