redirects.py 1.35 KB
Newer Older
1
2
# coding: utf-8

3
from django.core.urlresolvers import reverse
4
5
from django.views.generic.base import RedirectView

6
7
from representatives.models import Group

8
9
10
11
12

class RedirectGroupList(RedirectView):
    permanent = True
    query_string = True
    pattern_name = 'group-list'
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30


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)
31
32
33
34
35


class RedirectRepresentativeDetail(RedirectView):
    permanent = True
    pattern_name = 'representative-votes'
Nicolas Joyard's avatar
Nicolas Joyard committed
36
37
38
39
40


class RedirectThemeDetail(RedirectView):
    permanent = True
    pattern_name = 'theme-links'
Nicolas Joyard's avatar
Nicolas Joyard committed
41
42
43
44
45


class RedirectDossierDetail(RedirectView):
    permanent = True
    pattern_name = 'dossier-proposals'