Commit bceac605 authored by Nicolas Joyard's avatar Nicolas Joyard

Handle chambers in group queries/urls

parent ca935fd8
...@@ -197,8 +197,13 @@ class Group(HashableModel, TimeStampedModel): ...@@ -197,8 +197,13 @@ class Group(HashableModel, TimeStampedModel):
ordering = ('name',) ordering = ('name',)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('representatives:representative-list', if self.chamber:
kwargs=dict(group_kind=self.kind, group=self.name)) return reverse('representatives:representative-list',
kwargs=dict(group_kind=self.kind, chamber=self.chamber.name,
group=self.name))
else:
return reverse('representatives:representative-list',
kwargs=dict(group_kind=self.kind, group=self.name))
class Constituency(HashableModel, TimeStampedModel): class Constituency(HashableModel, TimeStampedModel):
......
...@@ -4,6 +4,11 @@ from . import views ...@@ -4,6 +4,11 @@ from . import views
urlpatterns = [ urlpatterns = [
url(
r'^representative/(?P<group_kind>\w+)/(?P<chamber>.+)/(?P<group>.+)/$',
views.RepresentativeList.as_view(),
name='representative-list'
),
url( url(
r'^representative/(?P<group_kind>\w+)/(?P<group>.+)/$', r'^representative/(?P<group_kind>\w+)/(?P<group>.+)/$',
views.RepresentativeList.as_view(), views.RepresentativeList.as_view(),
...@@ -28,5 +33,5 @@ urlpatterns = [ ...@@ -28,5 +33,5 @@ urlpatterns = [
r'^groups/(?P<kind>\w+)/$', r'^groups/(?P<kind>\w+)/$',
views.GroupList.as_view(), views.GroupList.as_view(),
name='group-list' name='group-list'
), )
] ]
...@@ -74,6 +74,7 @@ class RepresentativeList(RepresentativeViewMixin, generic.ListView): ...@@ -74,6 +74,7 @@ class RepresentativeList(RepresentativeViewMixin, generic.ListView):
def group_filter(self, qs): def group_filter(self, qs):
group_kind = self.kwargs.get('group_kind', None) group_kind = self.kwargs.get('group_kind', None)
chamber = self.kwargs.get('chamber', None)
group = self.kwargs.get('group', None) group = self.kwargs.get('group', None)
today = datetime.date.today() today = datetime.date.today()
...@@ -93,6 +94,10 @@ class RepresentativeList(RepresentativeViewMixin, generic.ListView): ...@@ -93,6 +94,10 @@ class RepresentativeList(RepresentativeViewMixin, generic.ListView):
mandates__group__name=group, mandates__group__name=group,
mandates__group__kind=group_kind, mandates__group__kind=group_kind,
) )
if chamber:
qs = qs.filter(mandates__group__chamber__name=chamber)
return qs return qs
def get_queryset(self): def get_queryset(self):
...@@ -134,4 +139,3 @@ class GroupList(generic.ListView): ...@@ -134,4 +139,3 @@ class GroupList(generic.ListView):
qs = qs.filter(kind=kind).distinct() qs = qs.filter(kind=kind).distinct()
return qs.select_related('chamber') 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