From e4ecd0b8dc58cb7080c2f3dd87189efd74e3ac19 Mon Sep 17 00:00:00 2001
From: Ben Adida <ben@adida.net>
Date: Sun, 20 Mar 2011 18:58:47 -0700
Subject: [PATCH] fixed a bug where election URL was not displayed, and made
 sure emailed link is direct to go vote

---
 helios/__init__.py |  3 +++
 helios/models.py   |  4 ++--
 helios/urls.py     |  1 +
 helios/views.py    | 19 ++++++++++++++++---
 4 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/helios/__init__.py b/helios/__init__.py
index 18371b7..06f0514 100644
--- a/helios/__init__.py
+++ b/helios/__init__.py
@@ -1,5 +1,7 @@
 
 from django.conf import settings
+from django.core.urlresolvers import reverse
+from helios.views import election_shortcut
 
 TEMPLATE_BASE = settings.HELIOS_TEMPLATE_BASE or "helios/templates/base.html"
 
@@ -12,3 +14,4 @@ VOTERS_UPLOAD = settings.HELIOS_VOTERS_UPLOAD
 # allow emailing of voters?
 VOTERS_EMAIL = settings.HELIOS_VOTERS_EMAIL
 
+
diff --git a/helios/models.py b/helios/models.py
index af83572..2ddc440 100644
--- a/helios/models.py
+++ b/helios/models.py
@@ -15,7 +15,7 @@ import datetime, logging, uuid, random
 
 from crypto import electionalgs, algs, utils
 from helios import utils as heliosutils
-import helios
+import helios.views
 
 from helios import datatypes
 
@@ -460,7 +460,7 @@ class Election(HeliosModel):
 
   @property
   def url(self):
-    return helios.get_election_url(self)
+    return helios.views.get_election_url(self)
 
   def init_tally(self):
     # FIXME: create the right kind of tally
diff --git a/helios/urls.py b/helios/urls.py
index b08550c..6b19f88 100644
--- a/helios/urls.py
+++ b/helios/urls.py
@@ -18,6 +18,7 @@ urlpatterns = patterns('',
 
   # election shortcut by shortname
   (r'^e/(?P<election_short_name>[^/]+)$', election_shortcut),
+  (r'^e/(?P<election_short_name>[^/]+)/vote$', election_vote_shortcut),
 
   # vote shortcut
   (r'^v/(?P<vote_tinyhash>[^/]+)$', castvote_shortcut),
diff --git a/helios/views.py b/helios/views.py
index 80c5497..1ae48d3 100644
--- a/helios/views.py
+++ b/helios/views.py
@@ -49,10 +49,12 @@ ELGAMAL_PARAMS_LD_OBJECT = datatypes.LDObject.instantiate(ELGAMAL_PARAMS, dataty
 # single election server? Load the single electionfrom models import Election
 from django.conf import settings
 
-# a helper function
 def get_election_url(election):
   return settings.URL_HOST + reverse(election_shortcut, args=[election.short_name])  
 
+def get_election_govote_url(election):
+  return settings.URL_HOST + reverse(election_vote_shortcut, args=[election.short_name])  
+
 def get_castvote_url(cast_vote):
   return settings.URL_HOST + reverse(castvote_shortcut, args=[cast_vote.vote_tinyhash])
 
@@ -137,6 +139,17 @@ def election_shortcut(request, election_short_name):
   else:
     raise Http404
 
+def election_vote_shortcut(request, election_short_name):
+  election = Election.get_by_short_name(election_short_name)
+  if election:
+    vote_url = "%s/booth/vote.html?%s" % (settings.SECURE_URL_HOST, urllib.urlencode({'election_url' : reverse(one_election, args=[election.uuid])}))
+
+    test_cookie_url = "%s?%s" % (reverse(test_cookie), urllib.urlencode({'continue_url' : vote_url}))
+
+    return HttpResponseRedirect(test_cookie_url)
+  else:
+    raise Http404
+
 def castvote_shortcut(request, vote_tinyhash):
   try:
     cast_vote = CastVote.objects.get(vote_tinyhash = vote_tinyhash)
@@ -311,7 +324,7 @@ def one_election_view(request, election):
           }))
 
   trustees = Trustee.get_by_election(election)
-    
+
   return render_template(request, 'election_view',
                          {'election' : election, 'trustees': trustees, 'admin_p': admin_p, 'user': user,
                           'voter': voter, 'votes': votes, 'notregistered': notregistered, 'eligible_p': eligible_p,
@@ -1165,7 +1178,7 @@ def voters_email(request, election):
       extra_vars = {
         'custom_subject' : email_form.cleaned_data['subject'],
         'custom_message' : email_form.cleaned_data['body'],
-        'election_url' : get_election_url(election),
+        'election_url' : get_election_govote_url(election),
         'election' : election
         }
         
-- 
GitLab