Commit 2f68ba52 authored by Nicolas Joyard's avatar Nicolas Joyard

Add related chambers + fix end_date null tests

parent 122f28aa
......@@ -43,7 +43,8 @@ class RepresentativeViewMixin(object):
if m.constituency.country_id and not representative.country:
representative.country = m.constituency.country
if (m.end_date > today and m.group.kind == 'group' and
if ((m.end_date is None or m.end_date > today) and
m.group.kind == 'group' and
not representative.main_mandate):
representative.main_mandate = m
......@@ -74,20 +75,23 @@ class RepresentativeList(RepresentativeViewMixin, generic.ListView):
def group_filter(self, qs):
group_kind = self.kwargs.get('group_kind', None)
group = self.kwargs.get('group', None)
today = datetime.date.today()
if group_kind and group:
if group.isnumeric():
# Search group based on pk
qs = qs.filter(
models.Q(mandates__end_date__gte=today) |
models.Q(mandates__end_date__isnull=True),
mandates__group_id=int(group),
mandates__end_date__gte=datetime.now()
)
else:
# Search group based on abbreviation
qs = qs.filter(
models.Q(mandates__end_date__gte=today) |
models.Q(mandates__end_date__isnull=True),
mandates__group__name=group,
mandates__group__kind=group_kind,
mandates__end_date__gte=datetime.date.today()
)
return qs
......@@ -121,11 +125,13 @@ class RepresentativeDetail(RepresentativeViewMixin, generic.DetailView):
class GroupList(generic.ListView):
def get_queryset(self):
qs = Group.objects.filter(
mandates__end_date__gte=datetime.date.today()
models.Q(mandates__end_date__gte=datetime.date.today()) |
models.Q(mandates__end_date__isnull=True)
)
kind = self.kwargs.get('kind', None)
if kind:
qs = qs.filter(kind=kind).distinct()
return qs
return qs.select_related('chamber')
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