From 383f0102ff227e2e28a127bc755e655989e3b5f7 Mon Sep 17 00:00:00 2001
From: Ben Adida <ben@adida.net>
Date: Mon, 11 Oct 2010 21:23:58 -0700
Subject: [PATCH] efficiency fixes, UTC indication

---
 auth/security/__init__.py           | 2 +-
 helios/models.py                    | 4 ++--
 helios/templates/election_view.html | 6 +++---
 helios/views.py                     | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/auth/security/__init__.py b/auth/security/__init__.py
index 1b3911c..28aa6fa 100644
--- a/auth/security/__init__.py
+++ b/auth/security/__init__.py
@@ -92,7 +92,7 @@ def admin_required(func):
 # get the user
 def get_user(request):
   # push the expiration of the session back
-  request.session.set_expiry(settings.SESSION_COOKIE_AGE)
+  # request.session.set_expiry(settings.SESSION_COOKIE_AGE)
   
   # set up CSRF protection if needed
   if not request.session.has_key('csrf_token') or type(request.session['csrf_token']) != str:
diff --git a/helios/models.py b/helios/models.py
index c315635..c241cfa 100644
--- a/helios/models.py
+++ b/helios/models.py
@@ -152,7 +152,7 @@ class Election(models.Model, electionalgs.Election):
   @classmethod
   def get_by_uuid(cls, uuid):
     try:
-      return cls.objects.get(uuid=uuid)
+      return cls.objects.select_related().get(uuid=uuid)
     except cls.DoesNotExist:
       return None
   
@@ -599,7 +599,7 @@ class Voter(models.Model, electionalgs.Voter):
 
   @classmethod
   def get_by_user(cls, user):
-    return cls.objects.filter(voter_type = user.user_type, voter_id = user.user_id).order_by('-cast_at')
+    return cls.objects.select_related().filter(voter_type = user.user_type, voter_id = user.user_id).order_by('-cast_at')
 
   @property
   def user(self):
diff --git a/helios/templates/election_view.html b/helios/templates/election_view.html
index 65b16a8..7570d49 100644
--- a/helios/templates/election_view.html
+++ b/helios/templates/election_view.html
@@ -165,12 +165,12 @@ For your privacy, you'll be asked to log in only once your ballot is encrypted.
 {% endif %}
 {% if election.voting_extended_until %}
 <br />
-This election was initially scheduled to end at {{election.voting_ends_at}},<br />
-but has been extended until {{ election.voting_extended_until }}.
+This election was initially scheduled to end at {{election.voting_ends_at}} (UTC),<br />
+but has been extended until {{ election.voting_extended_until }} (UTC).
 {% else %}
 {% if election.voting_ends_at %}
 <br />
-This election is scheduled to end at {{election.voting_ends_at}}.
+This election is scheduled to end at {{election.voting_ends_at}} (UTC).
 {% else %}
 <br />
 This election ends at the administrator's discretion.
diff --git a/helios/views.py b/helios/views.py
index 4760474..b26b171 100644
--- a/helios/views.py
+++ b/helios/views.py
@@ -898,10 +898,10 @@ def voters_list_pretty(request, election):
     else:
       voters = voters.filter(name__icontains = q)
 
-  total_voters = voters.count()
-
   voter_paginator = Paginator(voters, limit)
   voters_page = voter_paginator.page(page)
+
+  total_voters = voter_paginator.count
     
   return render_template(request, 'voters_list', {'election': election, 'voters_page': voters_page,
                                                   'voters': voters_page.object_list, 'admin_p': admin_p, 
-- 
GitLab