Commit 22d27829 authored by Nicolas Joyard's avatar Nicolas Joyard
Browse files

Group autocomplete: abide by active_only session parameter

parent 890f515d
......@@ -36,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
......
{"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 Development", "id": 8}, {"text": "Committee on Economic and Monetary Affairs", "id": 30}, {"text": "Committee on Employment and Social Affairs", "id": 3}, {"text": "Committee on Fisheries", "id": 55}]}
\ No newline at end of file
{"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
{"pagination": {"more": false}, "results": [{"text": "Committee on Agriculture and Rural Development", "id": 47}, {"text": "Committee on Development", "id": 8}, {"text": "Committee on Regional Development", "id": 24}]}
\ 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
......@@ -60,10 +60,10 @@ class GroupListTest(ResponseDiffMixin, TestCase):
if q:
url = '/legislature/autocomplete/group/?q=%s' % q
else:
url = '/legislature/autocomplete/group/'
url = '/legislature/autocomplete/group/?'
# setup session variables
self.client.get(url)
self.client.get('%s&active_only=0' % url)
self.responsediff_test(url, numQueries)
......
# coding: utf-8
from core.views import ActiveLegislatureMixin
from dal.autocomplete import Select2QuerySetView
import datetime
from django.db.models import Q
from representatives.models import Group
class GroupAutocomplete(Select2QuerySetView):
class GroupAutocomplete(Select2QuerySetView, ActiveLegislatureMixin):
def get_queryset(self):
qs = Group.objects.exclude(kind__in=['chamber', 'country'])
qs = Group.objects.distinct().exclude(kind__in=['chamber', 'country'])
if self.get_active_only():
qs = qs.filter(
Q(mandates__end_date__gte=datetime.date.today()) |
Q(mandates__end_date__isnull=True)
)
if self.q:
qs = qs.filter(
......
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