From 1b876a2726303a05e5ccf140f75a92fd7d4e761d Mon Sep 17 00:00:00 2001
From: Marco Ciotola <848222@stud.unive.it>
Date: Thu, 7 Mar 2019 19:16:22 +0100
Subject: [PATCH] [DJ1.10] Update stats_urls to have names and be reversed by
 name

---
 helios/stats_url_names.py             |  5 +++++
 helios/stats_urls.py                  | 11 ++++++-----
 helios/stats_views.py                 |  3 ++-
 helios/templates/stats.html           |  8 ++++----
 helios/templates/stats_elections.html |  2 +-
 server_ui/templates/base.html         |  2 +-
 6 files changed, 19 insertions(+), 12 deletions(-)
 create mode 100644 helios/stats_url_names.py

diff --git a/helios/stats_url_names.py b/helios/stats_url_names.py
new file mode 100644
index 0000000..2b8ffe2
--- /dev/null
+++ b/helios/stats_url_names.py
@@ -0,0 +1,5 @@
+STATS_HOME="stats@home"
+STATS_FORCE_QUEUE="stats@force-queue"
+STATS_ELECTIONS="stats@elections"
+STATS_ELECTIONS_PROBLEMS="stats@elections-problems"
+STATS_RECENT_VOTES="stats@recent-votes"
diff --git a/helios/stats_urls.py b/helios/stats_urls.py
index 9472b7a..ac3b143 100644
--- a/helios/stats_urls.py
+++ b/helios/stats_urls.py
@@ -7,11 +7,12 @@ Ben Adida (ben@adida.net)
 from django.conf.urls import url
 
 from helios.stats_views import (home, force_queue, elections, recent_problem_elections, recent_votes)
+import helios.stats_url_names as names
 
 urlpatterns = [
-    url(r'^$', home),
-    url(r'^force-queue$', force_queue),
-    url(r'^elections$', elections),
-    url(r'^problem-elections$', recent_problem_elections),
-    url(r'^recent-votes$', recent_votes),
+    url(r'^$', home, name=names.STATS_HOME),
+    url(r'^force-queue$', force_queue, name=names.STATS_FORCE_QUEUE),
+    url(r'^elections$', elections, name=names.STATS_ELECTIONS),
+    url(r'^problem-elections$', recent_problem_elections, name=names.STATS_ELECTIONS_PROBLEMS),
+    url(r'^recent-votes$', recent_votes, name=names.STATS_RECENT_VOTES),
 ]
diff --git a/helios/stats_views.py b/helios/stats_views.py
index 9c01a7f..5fc07e6 100644
--- a/helios/stats_views.py
+++ b/helios/stats_views.py
@@ -11,6 +11,7 @@ from django.http import HttpResponseRedirect
 
 from helios import tasks
 from helios.models import CastVote, Election
+from helios.stats_url_names import STATS_HOME
 from helios_auth.security import get_user
 from security import PermissionDenied
 from view_utils import render_template
@@ -34,7 +35,7 @@ def force_queue(request):
   for cv in votes_in_queue:
     tasks.cast_vote_verify_and_store.delay(cv.id)
 
-  return HttpResponseRedirect(reverse(home))
+  return HttpResponseRedirect(reverse(STATS_HOME))
 
 def elections(request):
   user = require_admin(request)
diff --git a/helios/templates/stats.html b/helios/templates/stats.html
index 37468b7..3f2bffe 100644
--- a/helios/templates/stats.html
+++ b/helios/templates/stats.html
@@ -5,11 +5,11 @@
 <h1>Admin</h1>
 
 <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>
+<li> <a href="{% url "stats@elections" %}">elections</a></li>
+<li> <a href="{% url "stats@recent-votes" %}">recent votes</a></li>
+<li> <a href="{% url "stats@elections-problems" %}">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>
+<p><b>{{num_votes_in_queue}}</b> votes in queue. {% if num_votes_in_queue %}[<a href="{% url "stats@force-queue" %}">force it</a>]{% endif %}</p>
 
 {% endblock %}
diff --git a/helios/templates/stats_elections.html b/helios/templates/stats_elections.html
index 7179698..215225b 100644
--- a/helios/templates/stats_elections.html
+++ b/helios/templates/stats_elections.html
@@ -5,7 +5,7 @@
 <h1>Elections</h1>
 
 <p>
-<form method="get" action="{% url "helios.stats_views.elections" %}">
+<form method="get" action="{% url "stats@elections" %}">
 <b>search</b>: <input type="text" name="q" value="{{q}}"/> 
 <input class="small button" type="submit" value="search" /> <a class="small button" href="?">clear search</a>
 </form>
diff --git a/server_ui/templates/base.html b/server_ui/templates/base.html
index ac5f2d1..08d769d 100644
--- a/server_ui/templates/base.html
+++ b/server_ui/templates/base.html
@@ -42,7 +42,7 @@
       <!-- Right Nav Section -->
       <ul class="right">
 	{% if user and user.admin_p %}
-	<li><a href="{% url "helios.stats_views.home" %}">Admin</a></li>
+	<li><a href="{% url "stats@home" %}">Admin</a></li>
 	<li class="divider"></li>
 	{% endif %}
 	{% if not settings.MASTER_HELIOS %}
-- 
GitLab