Commit 202c4051 authored by Nicolas Joyard's avatar Nicolas Joyard
Browse files

Enable choosing active legislature/all data on rep list

parent 1f7ddd61
Display :
- if active_only
current legislature only /
%a{'href': '?active_only=0'}
all data
- else
%a{'href': '?active_only=1'}
current legislature only
="/ all data"
\ No newline at end of file
......@@ -37,6 +37,11 @@
%div.count
Number of results : {{ paginator.count }}
- if active_only != None
%br
- include 'core/blocks/active-filter.html'
%br
Number of displayed results :
{{ paginator.per_page }}
......
......@@ -4,6 +4,33 @@ from django import http
import unicodecsv as csv
class ActiveLegislatureMixin(object):
"""
Mixin for views that can switch between active legislature and all data
"""
default_active_only = True
def get(self, *args, **kwargs):
self.set_active_only()
return super(ActiveLegislatureMixin, self).get(*args, **kwargs)
def set_active_only(self):
if 'active_only' in self.request.GET:
self.request.session['active_only'] = \
self.request.GET['active_only'] == '1'
elif 'active_only' not in self.request.session:
self.request.session['active_only'] = self.default_active_only
def get_active_only(self):
return self.request.session['active_only']
def get_context_data(self, **kwargs):
c = super(ActiveLegislatureMixin, self).get_context_data(**kwargs)
c['active_only'] = self.get_active_only()
return c
class PaginationMixin(object):
pagination_limits = (12, 24, 48, 96)
......
# coding: utf-8
from core.views import GridListMixin, PaginationMixin, CSVDownloadMixin
from core.views import GridListMixin, PaginationMixin, CSVDownloadMixin, \
ActiveLegislatureMixin
import datetime
......@@ -14,11 +15,11 @@ from .representative_mixin import RepresentativeViewMixin
class RepresentativeList(CSVDownloadMixin, GridListMixin, PaginationMixin,
RepresentativeViewMixin, generic.ListView):
RepresentativeViewMixin, ActiveLegislatureMixin,
generic.ListView):
csv_name = 'meps.csv'
queryset = Representative.objects.filter(
active=True).select_related('score')
queryset = Representative.objects.select_related('score')
def get_context_data(self, **kwargs):
c = super(RepresentativeList, self).get_context_data(**kwargs)
......@@ -66,6 +67,8 @@ class RepresentativeList(CSVDownloadMixin, GridListMixin, PaginationMixin,
def get_queryset(self):
qs = super(RepresentativeList, self).get_queryset()
if self.get_active_only():
qs = qs.filter(active=True)
qs = self.group_filter(qs)
qs = self.search_filter(qs)
qs = self.prefetch_for_representative_country_and_main_mandate(qs)
......
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