diff --git a/helios/stats_views.py b/helios/stats_views.py index 1d9bba1759427c26a2b5cd2c800a7a8f1a2217aa..f1a5847bb91c553b2f49dc3f0da2fb80d24f9b78 100644 --- a/helios/stats_views.py +++ b/helios/stats_views.py @@ -40,13 +40,15 @@ def elections(request): page = int(request.GET.get('page', 1)) limit = int(request.GET.get('limit', 25)) + q = request.GET.get('q','') - elections = Election.objects.all().order_by('-created_at') + elections = Election.objects.filter(name__icontains = q) + elections.all().order_by('-created_at') elections_paginator = Paginator(elections, limit) elections_page = elections_paginator.page(page) return render_template(request, "stats_elections", {'elections' : elections_page.object_list, 'elections_page': elections_page, - 'limit' : limit}) + 'limit' : limit, 'q': q}) def recent_votes(request): user = require_admin(request) diff --git a/helios/templates/stats_elections.html b/helios/templates/stats_elections.html index bb4a232f359701d87a117314023a7104d4ac3775..24f5c145084c41ad4325a06f3fa277710f644f43 100644 --- a/helios/templates/stats_elections.html +++ b/helios/templates/stats_elections.html @@ -4,15 +4,23 @@ {% block content %} <h1>Elections</h1> +<p> +<form method="get" action="{% url "helios.stats_views.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> +</p> + + <p> {% if elections_page.has_previous %} -<a href="?page={{elections_page.previous_page_number}}&limit={{limit}}">previous {{limit}}</a> +<a href="?page={{elections_page.previous_page_number}}&limit={{limit}}&q={{q}}">previous {{limit}}</a> {% endif %} Elections {{elections_page.start_index}} - {{elections_page.end_index}} {% if elections_page.has_next %} -<a href="?page={{elections_page.next_page_number}}&limit={{limit}}">next {{limit}}</a> +<a href="?page={{elections_page.next_page_number}}&limit={{limit}}&q={{q}}">next {{limit}}</a> {% endif %} </p>