Commit 75d85817 authored by Nicolas Joyard's avatar Nicolas Joyard
Browse files

Enable filtering dossiers by chamber

parent 70f1a330
......@@ -13,7 +13,7 @@ from representatives.models import Chamber, Group, Representative
from representatives_votes.models import Dossier
def chamber_filter(qs, value):
def rep_chamber_filter(qs, value):
today = datetime.date.today()
return qs.filter(
Q(mandates__end_date__gte=today) | Q(mandates__end_date__isnull=True),
......@@ -21,6 +21,10 @@ def chamber_filter(qs, value):
)
def dossier_chamber_filter(qs, value):
return qs.filter(documents__chamber=value)
def group_filter(qs, value):
today = datetime.date.today()
return qs.filter(
......@@ -34,7 +38,7 @@ class RepresentativeFilter(FilterSet):
search = MethodFilter(action='search_filter')
chamber = ModelChoiceFilter(queryset=Chamber.objects.all(),
action=chamber_filter)
action=rep_chamber_filter)
country = ModelChoiceFilter(queryset=Group.objects.filter(kind='country'),
action=group_filter)
......@@ -60,9 +64,12 @@ class DossierFilter(FilterSet):
search = MethodFilter(action='search_filter')
chamber = ModelChoiceFilter(queryset=Chamber.objects.all(),
action=dossier_chamber_filter)
class Meta:
model = Dossier
fields = ['search']
fields = ['search', 'chamber']
def search_filter(self, qs, value):
if len(value) == 0:
......
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