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): ...@@ -15,6 +15,14 @@ class ActiveLegislatureMixin(object):
self.set_active_only() self.set_active_only()
return super(ActiveLegislatureMixin, self).get(*args, **kwargs) 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): def set_active_only(self):
if 'active_only' in self.request.GET: if 'active_only' in self.request.GET:
self.request.session['active_only'] = \ self.request.session['active_only'] = \
...@@ -23,10 +31,15 @@ class ActiveLegislatureMixin(object): ...@@ -23,10 +31,15 @@ class ActiveLegislatureMixin(object):
self.request.session['active_only'] = self.default_active_only self.request.session['active_only'] = self.default_active_only
def get_active_only(self): def get_active_only(self):
overriden = self.override_active_only()
if overriden is None:
return self.request.session['active_only'] return self.request.session['active_only']
else:
return overriden
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
c = super(ActiveLegislatureMixin, self).get_context_data(**kwargs) c = super(ActiveLegislatureMixin, self).get_context_data(**kwargs)
if self.override_active_only() is None:
c['active_only'] = self.get_active_only() c['active_only'] = self.get_active_only()
return c return c
......
...@@ -12,6 +12,14 @@ from representatives.models import Group ...@@ -12,6 +12,14 @@ from representatives.models import Group
class GroupList(PaginationMixin, ActiveLegislatureMixin, generic.ListView): 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): def get_queryset(self):
qs = Group.objects.all() qs = Group.objects.all()
......
Supports Markdown
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