legacy_urls.py 2.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
from django.conf.urls import url
from django.core.urlresolvers import reverse
from django.views.generic.base import RedirectView


class TabRedirectView(RedirectView):
    permanent = True

    def get_redirect_url(self, *args, **kwargs):
        if 'tab' in kwargs:
            tab = kwargs.pop('tab')
            return reverse('%s-%s' % (self.pattern_base, tab), args=args,
                           kwargs=kwargs)
        else:
            return reverse('%s-detail' % self.pattern_base, args=args,
                           kwargs=kwargs)


class RepresentativeListRedirect(RedirectView):
    permanent = True
    query_string = True
    pattern_name = 'representative-list'


class RepresentativeDetailRedirect(TabRedirectView):
    pattern_base = 'representative'


class DossierListRedirect(RedirectView):
    permanent = True
    query_string = True
    pattern_name = 'dossier-list'


class DossierDetailRedirect(TabRedirectView):
    pattern_base = 'dossier'


class ThemeListRedirect(RedirectView):
    permanent = True
    query_string = True
    pattern_name = 'theme-list'


class ThemeDetailRedirect(RedirectView):
    permanent = True
    pattern_name = 'theme-detail'


urlpatterns = [
    # Representative list

    url(
        r'^legislature/representative/$',
        RepresentativeListRedirect.as_view(),
        name='legacy-representative-list'
    ),

    # Representative detail

    url(
        r'^legislature/representative/(?P<slug>[-\w]+)/$',
        RepresentativeDetailRedirect.as_view(),
        name='legacy-representative-detail'
    ),

    url(
        r'^legislature/representative/(?P<slug>[-\w]+)/(?P<tab>\w+)/$',
        RepresentativeDetailRedirect.as_view(),
        name='legacy-representative-detail'
    ),

    # Dossier list

    url(
        r'^votes/dossier/$',
        DossierListRedirect.as_view(),
        name='legacy-dossier-list'
    ),

    # Dossier detail

    url(
        r'^votes/dossier/(?P<pk>\d+)/$',
        DossierDetailRedirect.as_view(),
        name='legacy-dossier-detail'
    ),

    url(
        r'^votes/dossier/(?P<pk>\d+)/(?P<tab>\w+)/$',
        DossierDetailRedirect.as_view(),
        name='legacy-dossier-detail'
    ),

    # Theme list

    url(
        r'^theme/$',
        ThemeListRedirect.as_view(),
        name='legacy-theme-list'
    ),

    # Theme detail

    url(
        r'^theme/(?P<slug>[-\w]+)/$',
        ThemeDetailRedirect.as_view(),
        name='legacy-theme-detail'
    ),
]