Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Political Memory
memopol
Commits
2c1afc9b
Commit
2c1afc9b
authored
Jun 16, 2016
by
Nicolas Joyard
Browse files
Redirect group URLs to filtered representative list
parent
6f0867e6
Changes
3
Hide whitespace changes
Inline
Side-by-side
memopol/urls.py
View file @
2c1afc9b
...
...
@@ -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
(),
RedirectGroup
RepresentativeList
.
as_view
(),
name
=
'representative-list'
),
url
(
r
'^legislature/representative/(?P<group_kind>\w+)/(?P<group>.+)/$'
,
RepresentativeList
.
as_view
(),
RedirectGroup
RepresentativeList
.
as_view
(),
name
=
'representative-list'
),
url
(
...
...
memopol/views/redirects.py
View file @
2c1afc9b
# 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
)
memopol/views/representative_list.py
View file @
2c1afc9b
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment