diff --git a/core/views.py b/core/views.py index 5a0a86053199203c1c503fa38671d63b01abf92f..051c31f41a8abc7a1136877be7c93a85e4d4c940 100644 --- a/core/views.py +++ b/core/views.py @@ -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 diff --git a/memopol/tests/response_fixtures/GroupListTest.test_autocomplete.content b/memopol/tests/response_fixtures/GroupListTest.test_autocomplete.content index f9d90437e888883f4e131ab4325e9b670c2b283a..84f648bdb135367dd7e49247385a46bac95e3b12 100644 --- a/memopol/tests/response_fixtures/GroupListTest.test_autocomplete.content +++ b/memopol/tests/response_fixtures/GroupListTest.test_autocomplete.content @@ -1 +1 @@ -{"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 diff --git a/memopol/tests/response_fixtures/GroupListTest.test_autocomplete_query.content b/memopol/tests/response_fixtures/GroupListTest.test_autocomplete_query.content index 60cbd8c42b2494ce67199be8bbf5dca43432efe4..ecdf253bb5745ad8d8055f108ddcba13d899c58a 100644 --- a/memopol/tests/response_fixtures/GroupListTest.test_autocomplete_query.content +++ b/memopol/tests/response_fixtures/GroupListTest.test_autocomplete_query.content @@ -1 +1 @@ -{"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 diff --git a/memopol/tests/test_group_list.py b/memopol/tests/test_group_list.py index 4372cb70f2a2f4a74c4e3258f2942420da504820..cb1d686b61614c7f0f01bcf4035ff66e7d801f0c 100644 --- a/memopol/tests/test_group_list.py +++ b/memopol/tests/test_group_list.py @@ -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) diff --git a/memopol/views/group_ac.py b/memopol/views/group_ac.py index 9e231b21a13f96a4387ec0e8f27f6dda157cda13..9d7abc58e413d5b20c0d681684b87cafe89d3d3f 100644 --- a/memopol/views/group_ac.py +++ b/memopol/views/group_ac.py @@ -1,15 +1,26 @@ # 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(