From c478731837b63d7560ae92c70ec285fc67821406 Mon Sep 17 00:00:00 2001 From: Ben Adida <ben@adida.net> Date: Wed, 6 Oct 2021 16:39:45 +0000 Subject: [PATCH] allow viewing a vote by full hash so we don't do quite as many DB queries. --- helios/templates/voters_list.html | 2 +- helios/url_names.py | 3 ++- helios/urls.py | 3 +++ helios/views.py | 8 ++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/helios/templates/voters_list.html b/helios/templates/voters_list.html index 3b345a0..88145e1 100644 --- a/helios/templates/voters_list.html +++ b/helios/templates/voters_list.html @@ -143,7 +143,7 @@ Voters {{voters_page.start_index}} - {{voters_page.end_index}} (of {{total_voter {% if election.use_voter_aliases %} <td>{{voter.alias}}</td> {% endif %} -<td><tt style="font-size: 1.4em;">{% if voter.vote_hash %}{{voter.vote_hash}} <span style="font-size:0.8em;">[<a href="{% url "shortcut@vote" vote_tinyhash=voter.vote_tinyhash %}">view</a>]</span>{% else %}—{% endif %}</tt></td> +<td><tt style="font-size: 1.4em;">{% if voter.vote_hash %}{{voter.vote_hash}} <span style="font-size:0.8em;">[<a href="{% url "shortcut-fullhash@vote" vote_hash=voter.vote_hash %}">view</a>]</span>{% else %}—{% endif %}</tt></td> </tr> {% endfor %} </table> diff --git a/helios/url_names.py b/helios/url_names.py index 319a9be..1b0caac 100644 --- a/helios/url_names.py +++ b/helios/url_names.py @@ -3,7 +3,7 @@ from helios import election_url_names as election, stats_url_names as stats __all__ = [ "election", "stats", "COOKIE_TEST", "COOKIE_TEST_2", "COOKIE_NO", - "ELECTION_SHORTCUT", "ELECTION_SHORTCUT_VOTE", "CAST_VOTE_SHORTCUT", + "ELECTION_SHORTCUT", "ELECTION_SHORTCUT_VOTE", "CAST_VOTE_SHORTCUT", "CAST_VOTE_FULLHASH_SHORTCUT", "TRUSTEE_LOGIN", "ELECTIONS_PARAMS", "ELECTIONS_VERIFIER", "ELECTIONS_VERIFIER_SINGLE_BALLOT", "ELECTIONS_NEW", "ELECTIONS_ADMINISTERED", "ELECTIONS_VOTED", @@ -16,6 +16,7 @@ COOKIE_NO="cookie@no" ELECTION_SHORTCUT="shortcut@election" ELECTION_SHORTCUT_VOTE="shortcut@election@vote" CAST_VOTE_SHORTCUT="shortcut@vote" +CAST_VOTE_FULLHASH_SHORTCUT="shortcut-fullhash@vote" TRUSTEE_LOGIN="trustee@login" diff --git a/helios/urls.py b/helios/urls.py index 9183eed..f03c4a7 100644 --- a/helios/urls.py +++ b/helios/urls.py @@ -16,6 +16,9 @@ urlpatterns = [ # vote shortcut url(r'^v/(?P<vote_tinyhash>[^/]+)$', views.castvote_shortcut, name=names.CAST_VOTE_SHORTCUT), + + # vote by hash + url(r'^vh/(?P<vote_hash>[^/]+)$', views.castvote_fullhash_shortcut, name=names.CAST_VOTE_FULLHASH_SHORTCUT), # trustee login url(r'^t/(?P<election_short_name>[^/]+)/(?P<trustee_email>[^/]+)/(?P<trustee_secret>[^/]+)$', views.trustee_login, diff --git a/helios/views.py b/helios/views.py index 9be3a31..f054ecd 100644 --- a/helios/views.py +++ b/helios/views.py @@ -147,6 +147,14 @@ def castvote_shortcut(request, vote_tinyhash): return _castvote_shortcut_by_election(request, election_uuid = cast_vote.voter.election.uuid, cast_vote=cast_vote) +def castvote_fullhash_shortcut(request, vote_hash): + try: + cast_vote = CastVote.objects.get(vote_hash = vote_hash) + except CastVote.DoesNotExist: + raise Http404 + + return _castvote_shortcut_by_election(request, election_uuid = cast_vote.voter.election.uuid, cast_vote=cast_vote) + @trustee_check def trustee_keygenerator(request, election, trustee): """ -- GitLab