Commit 5514782b authored by njoyard's avatar njoyard Committed by GitHub

Merge pull request #92 from political-memory/filter-representatives

Add filters for representatives
parents 0cea299b 22d27829
Display :
- if active_only
current legislature only /
%a{'href': '?active_only=0'}
%a{'href': '?={queries.urlencode}&active_only=0'}
all data
- else
%a{'href': '?active_only=1'}
%a{'href': '?={queries.urlencode}&active_only=1'}
current legislature only
="/ all data"
\ No newline at end of file
%span.grid-list-selector
%a{:href => '?display=grid'}
%a{:href => '?={queries.urlencode}&display=grid'}
<i class="fa fa-th"></i>
%a{:href => '?display=list'}
%a{:href => '?={queries.urlencode}&display=list'}
<i class="fa fa-th-list"></i>
......@@ -47,7 +47,7 @@
{{ paginator.per_page }}
(
- for limit in pagination_limits
%a{'href': '?paginate_by={{ limit }}'}
%a{'href': '?={queries.urlencode}&paginate_by={{ limit }}'}
{{ limit }}
- if not forloop.last
\/
......
# coding: utf-8
from copy import copy
from django import http
import unicodecsv as csv
......@@ -33,7 +36,10 @@ class ActiveLegislatureMixin(object):
def get_active_only(self):
overriden = self.override_active_only()
if overriden is None:
return self.request.session['active_only']
if 'active_only' in self.request.session:
return self.request.session['active_only']
else:
return self.default_active_only
else:
return overriden
......@@ -77,6 +83,9 @@ class PaginationMixin(object):
c['pagination_limits'] = self.pagination_limits
c['paginate_by'] = self.request.session['paginate_by']
c['page_range'] = self.get_page_range(c['page_obj'])
c['queries'] = copy(self.request.GET)
if 'page' in c['queries']:
del c['queries']['page']
return c
......
# coding: utf-8
from dal.autocomplete import ModelSelect2
import datetime
from django.db.models import Q
from django.utils.text import slugify
from django_filters import FilterSet, MethodFilter, ModelChoiceFilter
from representatives.models import Chamber, Group, Representative
def chamber_filter(qs, value):
today = datetime.date.today()
return qs.filter(
Q(mandates__end_date__gte=today) | Q(mandates__end_date__isnull=True),
mandates__group__chamber=value
)
def group_filter(qs, value):
today = datetime.date.today()
return qs.filter(
Q(mandates__end_date__gte=today) | Q(mandates__end_date__isnull=True),
mandates__group=value
)
class RepresentativeFilter(FilterSet):
search = MethodFilter(action='search_filter')
chamber = ModelChoiceFilter(queryset=Chamber.objects.all(),
action=chamber_filter)
country = ModelChoiceFilter(queryset=Group.objects.filter(kind='country'),
action=group_filter)
group = ModelChoiceFilter(queryset=Group.objects.exclude(
kind__in=['chamber', 'country']),
action=group_filter,
widget=ModelSelect2(url='group-autocomplete'),
label='Party, committee or delegation')
class Meta:
model = Representative
fields = ['search', 'chamber', 'country']
def search_filter(self, qs, value):
if len(value) == 0:
return qs
return qs.filter(slug__icontains=slugify(value))
......@@ -10,7 +10,7 @@
- The Political Memory of </title>
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.c7d56d0a17c9.css" type="text/css" />
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.540ce621a9a1.css" type="text/css" />
<script type="text/javascript" src="/static/collected/libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/static/collected/libs/bootstrap/dist/js/bootstrap.js"></script>
......
......@@ -10,7 +10,7 @@
- The Political Memory of </title>
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.c7d56d0a17c9.css" type="text/css" />
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.540ce621a9a1.css" type="text/css" />
<script type="text/javascript" src="/static/collected/libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/static/collected/libs/bootstrap/dist/js/bootstrap.js"></script>
......@@ -126,28 +126,28 @@
12
(
<a href='?paginate_by=12'>
<a href='?&paginate_by=12'>
12
</a>
/
<a href='?paginate_by=24'>
<a href='?&paginate_by=24'>
24
</a>
/
<a href='?paginate_by=48'>
<a href='?&paginate_by=48'>
48
</a>
/
<a href='?paginate_by=96'>
<a href='?&paginate_by=96'>
96
</a>
......
......@@ -10,7 +10,7 @@
- The Political Memory of </title>
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.c7d56d0a17c9.css" type="text/css" />
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.540ce621a9a1.css" type="text/css" />
<script type="text/javascript" src="/static/collected/libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/static/collected/libs/bootstrap/dist/js/bootstrap.js"></script>
......@@ -130,7 +130,7 @@
Display :
current legislature only /
<a href='?active_only=0'>
<a href='?&active_only=0'>
all data
</a>
......@@ -142,28 +142,28 @@
12
(
<a href='?paginate_by=12'>
<a href='?&paginate_by=12'>
12
</a>
/
<a href='?paginate_by=24'>
<a href='?&paginate_by=24'>
24
</a>
/
<a href='?paginate_by=48'>
<a href='?&paginate_by=48'>
48
</a>
/
<a href='?paginate_by=96'>
<a href='?&paginate_by=96'>
96
</a>
......
......@@ -10,7 +10,7 @@
- The Political Memory of </title>
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.c7d56d0a17c9.css" type="text/css" />
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.540ce621a9a1.css" type="text/css" />
<script type="text/javascript" src="/static/collected/libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/static/collected/libs/bootstrap/dist/js/bootstrap.js"></script>
......@@ -152,7 +152,7 @@
Display :
current legislature only /
<a href='?active_only=0'>
<a href='?&active_only=0'>
all data
</a>
......@@ -164,28 +164,28 @@
12
(
<a href='?paginate_by=12'>
<a href='?&paginate_by=12'>
12
</a>
/
<a href='?paginate_by=24'>
<a href='?&paginate_by=24'>
24
</a>
/
<a href='?paginate_by=48'>
<a href='?&paginate_by=48'>
48
</a>
/
<a href='?paginate_by=96'>
<a href='?&paginate_by=96'>
96
</a>
......
......@@ -10,7 +10,7 @@
- The Political Memory of </title>
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.c7d56d0a17c9.css" type="text/css" />
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.540ce621a9a1.css" type="text/css" />
<script type="text/javascript" src="/static/collected/libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/static/collected/libs/bootstrap/dist/js/bootstrap.js"></script>
......@@ -130,7 +130,7 @@
Display :
current legislature only /
<a href='?active_only=0'>
<a href='?&active_only=0'>
all data
</a>
......@@ -142,28 +142,28 @@
12
(
<a href='?paginate_by=12'>
<a href='?&paginate_by=12'>
12
</a>
/
<a href='?paginate_by=24'>
<a href='?&paginate_by=24'>
24
</a>
/
<a href='?paginate_by=48'>
<a href='?&paginate_by=48'>
48
</a>
/
<a href='?paginate_by=96'>
<a href='?&paginate_by=96'>
96
</a>
......
......@@ -10,7 +10,7 @@
- The Political Memory of </title>
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.c7d56d0a17c9.css" type="text/css" />
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.540ce621a9a1.css" type="text/css" />
<script type="text/javascript" src="/static/collected/libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/static/collected/libs/bootstrap/dist/js/bootstrap.js"></script>
......@@ -129,7 +129,7 @@
<br />
Display :
<a href='?active_only=1'>
<a href='?&active_only=1'>
current legislature only
</a>
/ all data
......@@ -142,28 +142,28 @@
12
(
<a href='?paginate_by=12'>
<a href='?&paginate_by=12'>
12
</a>
/
<a href='?paginate_by=24'>
<a href='?&paginate_by=24'>
24
</a>
/
<a href='?paginate_by=48'>
<a href='?&paginate_by=48'>
48
</a>
/
<a href='?paginate_by=96'>
<a href='?&paginate_by=96'>
96
</a>
......
......@@ -10,7 +10,7 @@
- The Political Memory of </title>
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.c7d56d0a17c9.css" type="text/css" />
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.540ce621a9a1.css" type="text/css" />
<script type="text/javascript" src="/static/collected/libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/static/collected/libs/bootstrap/dist/js/bootstrap.js"></script>
......@@ -151,7 +151,7 @@
<br />
Display :
<a href='?active_only=1'>
<a href='?&active_only=1'>
current legislature only
</a>
/ all data
......@@ -164,28 +164,28 @@
12
(
<a href='?paginate_by=12'>
<a href='?&paginate_by=12'>
12
</a>
/
<a href='?paginate_by=24'>
<a href='?&paginate_by=24'>
24
</a>
/
<a href='?paginate_by=48'>
<a href='?&paginate_by=48'>
48
</a>
/
<a href='?paginate_by=96'>
<a href='?&paginate_by=96'>
96
</a>
......
......@@ -10,7 +10,7 @@
- The Political Memory of </title>
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.c7d56d0a17c9.css" type="text/css" />
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.540ce621a9a1.css" type="text/css" />
<script type="text/javascript" src="/static/collected/libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/static/collected/libs/bootstrap/dist/js/bootstrap.js"></script>
......@@ -140,7 +140,7 @@
<br />
Display :
<a href='?active_only=1'>
<a href='?&active_only=1'>
current legislature only
</a>
/ all data
......@@ -153,28 +153,28 @@
12
(
<a href='?paginate_by=12'>
<a href='?&paginate_by=12'>
12
</a>
/
<a href='?paginate_by=24'>
<a href='?&paginate_by=24'>
24
</a>
/
<a href='?paginate_by=48'>
<a href='?&paginate_by=48'>
48
</a>
/
<a href='?paginate_by=96'>
<a href='?&paginate_by=96'>
96
</a>
......
{"pagination": {"more": true}, "results": [{"text": "Committee on Agriculture and Rural Development", "id": 47}, {"text": "Committee on Budgetary Control", "id": 89}, {"text": "Committee on Budgets", "id": 34}, {"text": "Committee on Civil Liberties, Justice and Home Affairs", "id": 7}, {"text": "Committee on Constitutional Affairs", "id": 37}, {"text": "Committee on Culture and Education", "id": 20}, {"text": "Committee on Economic and Monetary Affairs", "id": 30}, {"text": "Committee on Employment and Social Affairs", "id": 3}, {"text": "Committee on Fisheries", "id": 55}, {"text": "Committee on Foreign Affairs", "id": 5}]}
\ No newline at end of file
{
"status_code": 200
}
\ No newline at end of file
{"pagination": {"more": false}, "results": [{"text": "Committee on Agriculture and Rural Development", "id": 47}, {"text": "Committee on Regional Development", "id": 24}]}
\ No newline at end of file
......@@ -10,7 +10,7 @@
- The Political Memory of </title>
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.c7d56d0a17c9.css" type="text/css" />
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.540ce621a9a1.css" type="text/css" />
<script type="text/javascript" src="/static/collected/libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/static/collected/libs/bootstrap/dist/js/bootstrap.js"></script>
......@@ -97,28 +97,28 @@
12
(
<a href='?paginate_by=12'>
<a href='?&paginate_by=12'>
12
</a>
/
<a href='?paginate_by=24'>
<a href='?&paginate_by=24'>
24
</a>
/
<a href='?paginate_by=48'>
<a href='?&paginate_by=48'>
48
</a>
/
<a href='?paginate_by=96'>
<a href='?&paginate_by=96'>
96
</a>
......
......@@ -10,7 +10,7 @@
- The Political Memory of </title>
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.c7d56d0a17c9.css" type="text/css" />
<link rel="stylesheet" href="/static/collected/libs/bootstrap/dist/css/bootstrap.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/fontawesome/css/font-awesome.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/libs/flag-icon-css/css/flag-icon.min.css" type="text/css" /><link rel="stylesheet" href="/static/collected/CACHE/css/base.540ce621a9a1.css" type="text/css" />
<script type="text/javascript" src="/static/collected/libs/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/static/collected/libs/bootstrap/dist/js/bootstrap.js"></script>
......@@ -142,28 +142,28 @@
12
(
<a href='?paginate_by=12'>
<a href='?&paginate_by=12'>
12
</a>
/
<a href='?paginate_by=24'>
<a href='?&paginate_by=24'>
24
</a>
/
<a href='?paginate_by=48'>
<a href='?&paginate_by=48'>
48
</a>
/
<a href='?paginate_by=96'>
<a href='?&paginate_by=96'>
96
</a>
......
<!DOCTYPE html>
<html class="no-js" lang="en"> <!--<![endif]-->