From a6d50005eca070af555e200cdd176d42b3f77913 Mon Sep 17 00:00:00 2001
From: Ben Adida <ben@adida.net>
Date: Wed, 9 Mar 2011 16:20:00 -0800
Subject: [PATCH] added report for viewing elections that have been unfrozen
 for too long

---
 helios/stats_urls.py        | 1 +
 helios/stats_views.py       | 8 ++++++++
 helios/templates/stats.html | 1 +
 helios/views.py             | 2 +-
 4 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/helios/stats_urls.py b/helios/stats_urls.py
index 606ee80..53bae6e 100644
--- a/helios/stats_urls.py
+++ b/helios/stats_urls.py
@@ -13,5 +13,6 @@ urlpatterns = patterns(
     (r'^$', home),
     (r'^force-queue$', force_queue),
     (r'^elections$', elections),
+    (r'^problem-elections$', recent_problem_elections),
     (r'^recent-votes$', recent_votes),
 )
diff --git a/helios/stats_views.py b/helios/stats_views.py
index 1affcbb..456b12a 100644
--- a/helios/stats_views.py
+++ b/helios/stats_views.py
@@ -56,3 +56,11 @@ def recent_votes(request):
   elections_with_votes_in_24hours = Election.objects.filter(voter__castvote__cast_at__gt= datetime.datetime.utcnow() - datetime.timedelta(days=1)).annotate(last_cast_vote = Max('voter__castvote__cast_at'), num_recent_cast_votes = Count('voter__castvote')).order_by('-last_cast_vote')
 
   return render_template(request, "stats_recent_votes", {'elections' : elections_with_votes_in_24hours})
+
+def recent_problem_elections(request):
+  user = require_admin(request)
+
+  # elections left unfrozen older than 1 day old (and younger than 10 days old, so we don't go back too far)
+  elections_with_problems = Election.objects.filter(frozen_at = None, created_at__gt = datetime.datetime.utcnow() - datetime.timedelta(days=10), created_at__lt = datetime.datetime.utcnow() - datetime.timedelta(days=1) )
+
+  return render_template(request, "stats_problem_elections", {'elections' : elections_with_problems})
diff --git a/helios/templates/stats.html b/helios/templates/stats.html
index 9c48e9f..f9ae1f7 100644
--- a/helios/templates/stats.html
+++ b/helios/templates/stats.html
@@ -7,6 +7,7 @@
 <ul>
 <li> <a href="{% url helios.stats_views.elections %}">elections</a></li>
 <li> <a href="{% url helios.stats_views.recent_votes %}">recent votes</a></li>
+<li> <a href="{% url helios.stats_views.recent_problem_elections %}">recent problem elections</a></li>
 </ul>
 
 <p><b>{{num_votes_in_queue}}</b> votes in queue. {% if num_votes_in_queue %}[<a href="{% url helios.stats_views.force_queue %}">force it</a>]{% endif %}</p>
diff --git a/helios/views.py b/helios/views.py
index 20e2181..5176134 100644
--- a/helios/views.py
+++ b/helios/views.py
@@ -105,7 +105,7 @@ def admin_autologin(request):
   
   users = User.objects.filter(admin_p=True)
   if len(users) == 0:
-    users = User.objects.all()
+    return HttpResponse("no admin users!")
 
   if len(users) == 0:
     return HttpResponse("no users!")
-- 
GitLab