Commit 25ce832d authored by Arnaud Fabre's avatar Arnaud Fabre

Adds grid view and filters to representatives

parent 825e5013
%span.grid-list-selector
%a{:href => '?display=grid'}
<i class="fa fa-th"></i>
%a{:href => '?display=list'}
<i class="fa fa-th-list"></i>
......@@ -43,3 +43,4 @@
- if not forloop.last
\/
)
- include 'core/blocks/grid-list.html'
# coding: utf-8
# This file is part of mempol.
#
# mempol is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or any later version.
#
# mempol is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Affero Public
# License along with django-representatives.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
from __future__ import absolute_import
import django_filters
from .models import MemopolRepresentative
class RepresentativeFilter(django_filters.FilterSet):
class Meta:
model = MemopolRepresentative
# fields = ['full_name', 'country', 'score']
fields = {
'full_name': ['icontains', 'exact'],
'slug': ['exact'],
'remote_id': ['exact'],
'gender': ['exact'],
'active': ['exact'],
'country__name': ['exact'],
'country__code': ['exact']
}
order_by = ['score', 'full_name']
{% extends "base.html" %}
{% block content %}
<form action="" method="get">
{{ filter.form.as_p }}
<input type="submit" />
</form>
{% for obj in filter %}
{{ obj.name }} - ${{ obj.price }}<br />
{% endfor %}
{% endblock %}
- extends 'base.html'
- load representatives_extras
- block content
- include 'legislature/search.html'
- include "core/blocks/pagination.html"
.representative_grid
- for representative in object_list
.representative_item
%p.photo
%a{'href': "{% url 'legislature:representative-detail' name=representative.slug %}"}
%img{'src': '={representative.photo}', 'width': '80'}/
%ul
%li.name
%a{'href': "{% url 'legislature:representative-detail' name=representative.slug %}"}
= representative.full_name
%li.country
%a{'href': "{% url 'legislature:representative-index' group_kind='country' group=representative.country.code %}"}
= representative.country|country_flag
%li.mandate
%a{'href': "{{ representative.main_mandate|by_group_url }}"}
= representative.main_mandate.group.abbreviation
%li.score
= representative.score|score_label
- include "core/blocks/pagination.html"
......@@ -5,7 +5,7 @@
- block content
- include 'legislature/search.html'
- include "core/blocks/pagination.html"
- include 'core/blocks/pagination.html'
%table.table
%tr
......
......@@ -26,11 +26,13 @@ from django.db.models import Q
from django.http import Http404
from ..models import MemopolRepresentative
from ..filters import RepresentativeFilter
from core.utils import render_paginate_list
from positions.forms import PositionForm
def index(request, group_kind=None, group=None):
# Fetch active representatives
representative_list = MemopolRepresentative.objects.select_related(
'country',
......@@ -39,6 +41,7 @@ def index(request, group_kind=None, group=None):
).filter(
active=True
)
# Filter the list by group if group information is provided
if group_kind:
if group.isnumeric():
......@@ -61,11 +64,20 @@ def index(request, group_kind=None, group=None):
representative_list
).order_by('-score', 'last_name')
# Grid or list
if request.GET.get('display') in ('grid', 'list'):
request.session['display'] = request.GET.get('display')
if not 'display' in request.session:
request.session['display'] = 'grid'
# representative_list = RepresentativeFilter(request.GET, queryset=representative_list)
# Render the paginated template
return render_paginate_list(
request,
representative_list,
'legislature/representative_list.html'
'legislature/representative_{}.html'.format(
request.session['display']
)
)
def detail(request, pk=None, name=None):
......
......@@ -13,4 +13,8 @@ table.detail-view {
.icon-cell {
text-align: center;
}
.grid-list-selector {
// text-align: right;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment