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

Redirect group URLs to filtered representative list

parent 6f0867e6
......@@ -10,7 +10,7 @@ from views.group_ac import GroupAutocomplete
from views.group_list import GroupList
from views.representative_detail import RepresentativeDetail
from views.representative_list import RepresentativeList
from views.redirects import RedirectGroupList
from views.redirects import RedirectGroupList, RedirectGroupRepresentativeList
import api
......@@ -21,12 +21,12 @@ urlpatterns = [
url(
r'^legislature/representative/(?P<group_kind>\w+)/(?P<chamber>.+)/' +
r'(?P<group>.+)/$',
RepresentativeList.as_view(),
RedirectGroupRepresentativeList.as_view(),
name='representative-list'
),
url(
r'^legislature/representative/(?P<group_kind>\w+)/(?P<group>.+)/$',
RepresentativeList.as_view(),
RedirectGroupRepresentativeList.as_view(),
name='representative-list'
),
url(
......
# coding: utf-8
from django.core.urlresolvers import reverse
from django.views.generic.base import RedirectView
from representatives.models import Group
class RedirectGroupList(RedirectView):
permanent = True
query_string = True
pattern_name = 'group-list'
class RedirectGroupRepresentativeList(RedirectView):
permanent = True
def get_redirect_url(self, *args, **kwargs):
if kwargs['group_kind'] == 'chamber':
chamber = Group.objects.get(kind='chamber', name=kwargs['group'])
return '%s?chamber=%s' % (reverse('representative-list'),
chamber.pk)
elif kwargs['group_kind'] == 'country':
country = Group.objects.get(kind='country', name=kwargs['group'])
return '%s?country=%s' % (reverse('representative-list'),
country.pk)
else:
group = Group.objects.get(kind=kwargs['group_kind'],
name=kwargs['group'])
return '%s?group=%s' % (reverse('representative-list'), group.pk)
......@@ -3,13 +3,9 @@
from core.views import GridListMixin, PaginationMixin, CSVDownloadMixin, \
ActiveLegislatureMixin
import datetime
from django.db import models
from django.utils.text import slugify
from django.views import generic
from representatives.models import Group, Representative
from representatives.models import Representative
from ..filters import RepresentativeFilter
from .representative_mixin import RepresentativeViewMixin
......
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