Commit 6ac7727a authored by okhin's avatar okhin 🚴
Browse files

Merge branch '186-add-a-query-filter-to-sort-meps-by-active-constituency' into 'master'

Resolve "Add a query filter to sort meps by active constituency"

Closes #186

See merge request !189
parents 953a7a7c b34ef760
before_script: variables:
- export PIP_CACHE_DIR="pip-cache" PIP_CACHE_DIR: "$CI_PROJECT_DIR/pip-cache"
cache: cache:
paths: paths:
- pip-cache - "$CI_PROJECT_DIR/pip-cache"
key: "$CI_PROJECT_ID"
job test: job test:
script: script:
- tox - tox
......
...@@ -4,6 +4,7 @@ from datetime import datetime ...@@ -4,6 +4,7 @@ from datetime import datetime
from rest_framework.filters import BaseFilterBackend from rest_framework.filters import BaseFilterBackend
from django.db.models import Q from django.db.models import Q
from django.conf import settings from django.conf import settings
from django.utils.http import urlunquote
from .models import Mandate from .models import Mandate
...@@ -49,7 +50,7 @@ class ActiveConstituencyFilterBackend(BaseFilterBackend): ...@@ -49,7 +50,7 @@ class ActiveConstituencyFilterBackend(BaseFilterBackend):
if self.query_param in request.GET: if self.query_param in request.GET:
if len(request.GET[self.query_params]): if len(request.GET[self.query_params]):
mandates = request.GET[self.query_param].split(',') mandates = urlunquote(request.GET[self.query_param]).split(',')
qs = qs.filter(mandates__in=Mandate.objects.filter( qs = qs.filter(mandates__in=Mandate.objects.filter(
Q(end_date__gte=datetime.today) | Q(end_date__gte=datetime.today) |
Q(end_date__isnull=True)).filter( Q(end_date__isnull=True)).filter(
......
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