diff --git a/memopol/urls.py b/memopol/urls.py index 2cf2f67848aac1dd58bdcb9e054fc163b28e1de8..848cb768ba9f5f24caf1faa7eba52e6571a14767 100644 --- a/memopol/urls.py +++ b/memopol/urls.py @@ -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( diff --git a/memopol/views/redirects.py b/memopol/views/redirects.py index 876c7eabd7c83503eb62f1b49b0b1f7ab4d059cb..fa65d39d1c41d97cfefafa6fdf6342183ac07477 100644 --- a/memopol/views/redirects.py +++ b/memopol/views/redirects.py @@ -1,9 +1,30 @@ # 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) diff --git a/memopol/views/representative_list.py b/memopol/views/representative_list.py index 9f700efa3ad87eeba48ae388f1dbebbd8b53e6cc..b5efe7232c3d65eee5a1482c0b8d16ebb0d72065 100644 --- a/memopol/views/representative_list.py +++ b/memopol/views/representative_list.py @@ -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