Commit 1473e217 authored by okhin's avatar okhin

Ok, let's get more readable

parent 4b979839
Pipeline #746 failed with stage
in 10 minutes
from datetime import datetime 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 .models import Mandate from .models import Mandate
class ActiveMandateQueryFilterBackend(BaseFilterBackend): class ActiveMandateQueryFilterBackend(BaseFilterBackend):
""" """
A filter which check if a mandate is active for a reprensentative A filter which check if a mandate is active for a reprensentative
...@@ -21,6 +23,8 @@ class ActiveMandateQueryFilterBackend(BaseFilterBackend): ...@@ -21,6 +23,8 @@ class ActiveMandateQueryFilterBackend(BaseFilterBackend):
if self.query_param in request.GET: if self.query_param in request.GET:
if len(request.GET[self.query_param]): if len(request.GET[self.query_param]):
qs = qs.filter(mandates__in=Mandate.objects.filter(Q(end_date__gte=datetime.today)|Q(end_date__isnull=True)).filter(Q(group__name=request.GET[self.query_param])|Q(group__abbreviation=request.GET[self.query_param]))).distinct() qs = qs.filter(mandates__in=Mandate.objects.filter(Q(end_date__gte=datetime.today)
| Q(end_date__isnull=True)).filter(Q(group__name=request.GET[self.query_param])
| Q(group__abbreviation=request.GET[self.query_param]))).distinct()
return qs return qs
return qs return qs
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