Commit bceac605 authored by Nicolas Joyard's avatar Nicolas Joyard

Handle chambers in group queries/urls

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