diff --git a/helios/crypto/electionalgs.py b/helios/crypto/electionalgs.py index 4b5bb490af188935b84911f6dc6be8166587516f..4c2f2239ffcf4c296934dfbefe2760752eb96400 100644 --- a/helios/crypto/electionalgs.py +++ b/helios/crypto/electionalgs.py @@ -428,7 +428,7 @@ class Voter(HeliosObject): A voter in an election """ FIELDS = ['election_uuid', 'uuid', 'voter_type', 'voter_id', 'name', 'alias'] - JSON_FIELDS = ['election_uuid', 'uuid', 'voter_type', 'voter_id', 'name'] + JSON_FIELDS = ['election_uuid', 'uuid', 'voter_type', 'voter_id_hash', 'name'] # alternative, for when the voter is aliased ALIASED_VOTER_JSON_FIELDS = ['election_uuid', 'uuid', 'alias'] @@ -440,6 +440,10 @@ class Voter(HeliosObject): else: return super(Voter,self).toJSONDict() + @property + def voter_id_hash(self): + return utils.hash_b64(self.voter_id) + class Trustee(HeliosObject): """ a trustee diff --git a/helios/templates/stats.html b/helios/templates/stats.html index c60d93ed8de3061703af543953e4cbfa01ee9eea..498e2e4a97a1a7f29b49988a6c440b59bbe2477d 100644 --- a/helios/templates/stats.html +++ b/helios/templates/stats.html @@ -4,6 +4,18 @@ {% block content %} <h1>Statistics</h1> +<p> +{% if elections_page.has_previous %} +<a href="?page={{elections_page.previous_page_number}}&limit={{limit}}">previous {{limit}}</a> +{% endif %} + +Elections {{elections_page.start_index}} - {{elections_page.end_index}} + +{% if elections_page.has_next %} +<a href="?page={{elections_page.next_page_number}}&limit={{limit}}">next {{limit}}</a> +{% endif %} +</p> + {% for election in elections %} <p> <b><a href="{% url helios.views.one_election_view election.uuid %}">{{election.name}}</a></b> -- {{election.num_voters}} voters diff --git a/helios/views.py b/helios/views.py index 35fc4157ae2d0fa931770590c45af8b7099cd51a..135eb172f4653ba3c384079cb8991c6a5b6501a1 100644 --- a/helios/views.py +++ b/helios/views.py @@ -68,9 +68,15 @@ def stats(request): if not user or not user.admin_p: raise PermissionDenied() - elections = Election.objects.all().order_by('-created_at')[:25] + page = int(request.GET.get('page', 1)) + limit = int(request.GET.get('limit', 25)) + + elections = Election.objects.all().order_by('-created_at') + elections_paginator = Paginator(elections, limit) + elections_page = elections_paginator.page(page) - return render_template(request, "stats", {'elections' : elections}) + return render_template(request, "stats", {'elections' : elections_page.object_list, 'elections_page': elections_page + 'limit' : limit}) ## ## General election features