From 33c28b26185eaf2d61af2dbc8b7cbb0fec287d68 Mon Sep 17 00:00:00 2001 From: Mindiell <thomas.bouchet@sourismaline.fr> Date: Mon, 16 Mar 2015 15:43:55 +0100 Subject: [PATCH] Added a 'committee' view and modified MEP view --- .../memopol_representatives/view.html | 31 ++++++-------- memopol_representatives/urls.py | 1 + memopol_representatives/views.py | 40 ++++++++++++++++++- 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/memopol_representatives/templates/memopol_representatives/view.html b/memopol_representatives/templates/memopol_representatives/view.html index 13a8d241..a9ba5edc 100644 --- a/memopol_representatives/templates/memopol_representatives/view.html +++ b/memopol_representatives/templates/memopol_representatives/view.html @@ -10,27 +10,20 @@ <h1>{{ representative.full_name }}</h1> -<p> - {{ representative.country.name }} {{ representative.gender }} <br> - Born in {{ representative.birth_place }} the {{ representative.birth_date }} <br> -</p> +{% for mandate in representative.mandate_set.all %} +{% if mandate.group.kind == "group" %} +<h3>{{ mandate.role }} of {{ mandate.group.name }}</h3> +{% endif %} +{% endfor %} + +<p>Born in {{ representative.birth_place }} the {{ representative.birth_date }} ({{ representative.get_gender_display }})</p> +<p>{{ representative.country.name }}</p> -<h2 style="clear: both">Mandates</h2> +<h2 style="clear: both">Committees</h2> {% for mandate in representative.mandate_set.all %} -<div class="mandate"> - <h3> - {{ mandate.group.name }} - <small> - {{ mandate.role }} - </small> - </h3> - <p> - {{ mandate.begin_date }} to {{ mandate.end_date }} <br> - <strong>{{ mandate.group.kind }}</strong> : <em>{{ mandate.group.name }} ({{ mandate.group.abbreviation }})</em> <br> - Constituency : {{ mandate.constituency.name }} <br> - </p> -</div> -<hr> +{% if mandate.group.kind == "committee" %} + <p>{{ mandate.role }} of {{ mandate.group.name }} ({{ mandate.group.abbreviation }}) +{% endif %} {% endfor %} {% endblock %} diff --git a/memopol_representatives/urls.py b/memopol_representatives/urls.py index 53be2454..82933f63 100644 --- a/memopol_representatives/urls.py +++ b/memopol_representatives/urls.py @@ -5,5 +5,6 @@ from memopol_representatives import views urlpatterns = patterns( '', url(r'^$', views.index, name='index'), + url(r'^committee/(?P<committee>\w{4})$', views.committee, name='committee'), url(r'^view/(?P<num>\d+)$', views.view, name='view'), ) diff --git a/memopol_representatives/views.py b/memopol_representatives/views.py index af8a34bf..04e5e9af 100644 --- a/memopol_representatives/views.py +++ b/memopol_representatives/views.py @@ -19,7 +19,45 @@ def index(request): else: representative_list = Representative.objects.all() - paginator = Paginator(representative_list, 5) + paginator = Paginator(representative_list, 50) + + page = request.GET.get('page') + try: + representatives = paginator.page(page) + except PageNotAnInteger: + representatives = paginator.page(1) + except EmptyPage: + representatives = paginator.page(paginator.num_pages) + + context['representatives'] = representatives + return render( + request, + 'memopol_representatives/list.html', + context + ) + + +def committee(request, committee): + context = {} + if request.GET.get('search'): + search = request.GET.get('search') + representative_list = Representative.objects.filter( + mandate__group__kind='committee', + mandate__group__abbreviation=committee + ).filter( + Q(full_name__icontains=search) + ) + queries_without_page = request.GET.copy() + if 'page' in queries_without_page: + del queries_without_page['page'] + context['queries'] = queries_without_page + else: + representative_list = list(set(Representative.objects.filter( + mandate__group__kind='committee', + mandate__group__abbreviation=committee + ).all())) + + paginator = Paginator(representative_list, 50) page = request.GET.get('page') try: -- GitLab