Commit 2f475d37 authored by Nicolas Joyard's avatar Nicolas Joyard
Browse files

Disable active filter for countries and chambers

parent c9101d25
......@@ -15,6 +15,14 @@ class ActiveLegislatureMixin(object):
self.set_active_only()
return super(ActiveLegislatureMixin, self).get(*args, **kwargs)
def override_active_only(self):
"""
Redefine this method to override active legislature selection
- return None to enable user choice
- return True or False to disable user choice and set active state
"""
return None
def set_active_only(self):
if 'active_only' in self.request.GET:
self.request.session['active_only'] = \
......@@ -23,11 +31,16 @@ class ActiveLegislatureMixin(object):
self.request.session['active_only'] = self.default_active_only
def get_active_only(self):
return self.request.session['active_only']
overriden = self.override_active_only()
if overriden is None:
return self.request.session['active_only']
else:
return overriden
def get_context_data(self, **kwargs):
c = super(ActiveLegislatureMixin, self).get_context_data(**kwargs)
c['active_only'] = self.get_active_only()
if self.override_active_only() is None:
c['active_only'] = self.get_active_only()
return c
......
......@@ -12,14 +12,22 @@ from representatives.models import Group
class GroupList(PaginationMixin, ActiveLegislatureMixin, generic.ListView):
def override_active_only(self):
kind = self.kwargs.get('kind')
if kind == 'chamber' or kind == 'country':
return False
else:
return None
def get_queryset(self):
qs = Group.objects.all()
if self.get_active_only():
qs = qs.filter(
models.Q(mandates__end_date__gte=datetime.date.today()) |
models.Q(mandates__end_date__isnull=True)
)
if self.get_active_only():
qs = qs.filter(
models.Q(mandates__end_date__gte=datetime.date.today()) |
models.Q(mandates__end_date__isnull=True)
)
kind = self.kwargs.get('kind', None)
if kind:
......
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