From 79da6b1a6b59adabaaaf4edfa39ed798ed5e89c4 Mon Sep 17 00:00:00 2001 From: Edmar <edmar@usp.br> Date: Mon, 8 May 2017 16:57:54 -0300 Subject: [PATCH] Added search by name in admin page --- helios/stats_views.py | 6 ++++-- helios/templates/stats_elections.html | 12 ++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/helios/stats_views.py b/helios/stats_views.py index 1d9bba1..f1a5847 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 bb4a232..24f5c14 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> -- GitLab