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
f45ae46a
Commit
f45ae46a
authored
Sep 04, 2016
by
Nicolas Joyard
Browse files
Cleanup URLs and move legacy redirects to a separate module
parent
84a13889
Changes
4
Hide whitespace changes
Inline
Side-by-side
memopol/legacy_urls.py
0 → 100644
View file @
f45ae46a
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'
),
]
memopol/templatetags/memopol_tags.py
View file @
f45ae46a
...
...
@@ -5,9 +5,8 @@ import re
from
django
import
template
from
django.contrib.humanize.templatetags.humanize
import
naturalday
from
django.contrib.staticfiles.templatetags.staticfiles
import
static
from
django.core.urlresolvers
import
reverse
from
django.utils.safestring
import
mark_safe
from
django.utils.html
import
escape
register
=
template
.
Library
()
link
=
u
'<a class="{network}-link" href="{url}" target="_blank">{label}</a>'
...
...
@@ -17,42 +16,6 @@ def cssify(string):
return
re
.
sub
(
'[^a-z_-]'
,
''
,
string
.
lower
())
def
fix_url
(
url
):
# Ensure we have a usable URL
return
re
.
sub
(
'^(https?://)?'
,
'https://'
,
url
.
strip
())
@
register
.
simple_tag
def
group_url
(
group
):
if
group
.
kind
==
'chamber'
or
group
.
chamber
is
None
:
return
escape
(
reverse
(
'representative-list'
,
kwargs
=
{
'group_kind'
:
group
.
kind
,
'group'
:
group
.
name
}))
else
:
return
escape
(
reverse
(
'representative-list'
,
kwargs
=
{
'group_kind'
:
group
.
kind
,
'chamber'
:
group
.
chamber
.
name
,
'group'
:
group
.
name
}))
@
register
.
simple_tag
def
chamber_url
(
chamber
):
return
escape
(
reverse
(
'representative-list'
,
kwargs
=
{
'group_kind'
:
'chamber'
,
'group'
:
chamber
.
name
}))
@
register
.
simple_tag
def
country_url
(
country
):
return
escape
(
reverse
(
'representative-list'
,
kwargs
=
{
'group_kind'
:
'country'
,
'group'
:
country
.
name
}))
@
register
.
filter
def
country_flag
(
country
,
tplace
=
'bottom'
):
# Enable using groups instead of countries
...
...
memopol/urls.py
View file @
f45ae46a
# coding: utf-8
from
django.conf.urls
import
include
,
url
from
django.contrib
import
admin
...
...
@@ -32,130 +33,167 @@ from views.theme_detail_proposals import ThemeDetailProposals
from
views.theme_detail_positions
import
ThemeDetailPositions
from
views.theme_list
import
ThemeList
from
.legacy_urls
import
urlpatterns
as
legacy_patterns
import
api
admin
.
autodiscover
()
urlpatterns
=
[
# Imported URLs
url
(
r
'^admin/'
,
include
(
admin
.
site
.
urls
)),
url
(
r
'^api/'
,
include
(
api
.
router
.
urls
)),
# Homepage
url
(
r
'^$'
,
HomeView
.
as_view
(),
name
=
'home'
),
# Representative list
url
(
r
'^legislature/representative/(?P<group_kind>\w+)/(?P<chamber>.+)/'
+
r
'(?P<group>.+)/$'
,
RedirectGroupRepresentativeList
.
as_view
(),
name
=
'representative-list'
),
url
(
r
'^legislature/representative/(?P<group_kind>\w+)/(?P<group>.+)/$'
,
RepresentativeList
.
as_view
(),
name
=
'representative-list'
),
url
(
r
'^legislature/representative/$'
,
r
'^representatives/$'
,
RepresentativeList
.
as_view
(),
name
=
'representative-list'
),
# Representative detail
url
(
r
'^
legislature/
representative/(?P<slug>[-\w]+)/$'
,
r
'^representative
s
/(?P<slug>[-\w]+)/$'
,
RedirectRepresentativeDetail
.
as_view
(),
name
=
'representative-detail'
),
# URL used for testing only
url
(
r
'^legislature/representative/(?P<slug>[-\w]+)/none/$'
,
RepresentativeDetailBase
.
as_view
(),
name
=
'representative-none'
),
url
(
r
'^
legislature/
representative/(?P<slug>[-\w]+)/votes/$'
,
r
'^representative
s
/(?P<slug>[-\w]+)/votes/$'
,
RepresentativeDetailVotes
.
as_view
(),
name
=
'representative-votes'
),
url
(
r
'^
legislature/
representative/(?P<slug>[-\w]+)/mandates/$'
,
r
'^representative
s
/(?P<slug>[-\w]+)/mandates/$'
,
RepresentativeDetailMandates
.
as_view
(),
name
=
'representative-mandates'
),
url
(
r
'^
legislature/
representative/(?P<slug>[-\w]+)/positions/$'
,
r
'^representative
s
/(?P<slug>[-\w]+)/positions/$'
,
RepresentativeDetailPositions
.
as_view
(),
name
=
'representative-positions'
),
# Dossier list
url
(
r
'^legislature/groups/(?P<kind>\w+)/$'
,
RedirectGroupList
.
as_view
(),
name
=
'group-list-redirect'
),
url
(
r
'^votes/dossier/$'
,
r
'^dossiers/$'
,
DossierList
.
as_view
(),
name
=
'dossier-list'
),
# Dossier detail
url
(
r
'^
votes/
dossier/(?P<pk>\d+)/$'
,
r
'^dossier
s
/(?P<pk>\d+)/$'
,
RedirectDossierDetail
.
as_view
(),
name
=
'dossier-detail'
),
url
(
r
'^votes/dossier/(?P<pk>\d+)/none/$'
,
DossierDetailBase
.
as_view
(),
name
=
'dossier-none'
),
url
(
r
'^votes/dossier/(?P<pk>\d+)/recommendations/$'
,
r
'^dossiers/(?P<pk>\d+)/recommendations/$'
,
DossierDetailRecommendations
.
as_view
(),
name
=
'dossier-recommendations'
),
url
(
r
'^
votes/
dossier/(?P<pk>\d+)/proposals/$'
,
r
'^dossier
s
/(?P<pk>\d+)/proposals/$'
,
DossierDetailProposals
.
as_view
(),
name
=
'dossier-proposals'
),
url
(
r
'^
votes/
dossier/(?P<pk>\d+)/documents/$'
,
r
'^dossier
s
/(?P<pk>\d+)/documents/$'
,
DossierDetailDocuments
.
as_view
(),
name
=
'dossier-documents'
),
# Dossier autocomplete for admin
url
(
r
'^
votes/
autocomplete/proposal/$'
,
r
'^autocomplete/proposal/$'
,
ProposalAutocomplete
.
as_view
(),
name
=
'proposal-autocomplete'
,
),
# Theme list
url
(
r
'^theme/$'
,
r
'^theme
s
/$'
,
ThemeList
.
as_view
(),
name
=
'theme-list'
),
# Theme detail
url
(
r
'^theme/(?P<slug>[-\w]+)/$'
,
r
'^theme
s
/(?P<slug>[-\w]+)/$'
,
RedirectThemeDetail
.
as_view
(),
name
=
'theme-detail'
),
url
(
r
'^theme/(?P<slug>[-\w]+)/none/$'
,
ThemeDetailBase
.
as_view
(),
name
=
'theme-none'
),
url
(
r
'^theme/(?P<slug>[-\w]+)/links/$'
,
r
'^themes/(?P<slug>[-\w]+)/links/$'
,
ThemeDetailLinks
.
as_view
(),
name
=
'theme-links'
),
url
(
r
'^theme/(?P<slug>[-\w]+)/dossiers/$'
,
r
'^theme
s
/(?P<slug>[-\w]+)/dossiers/$'
,
ThemeDetailDossiers
.
as_view
(),
name
=
'theme-dossiers'
),
url
(
r
'^theme/(?P<slug>[-\w]+)/proposals/$'
,
r
'^theme
s
/(?P<slug>[-\w]+)/proposals/$'
,
ThemeDetailProposals
.
as_view
(),
name
=
'theme-proposals'
),
url
(
r
'^theme/(?P<slug>[-\w]+)/positions/$'
,
r
'^theme
s
/(?P<slug>[-\w]+)/positions/$'
,
ThemeDetailPositions
.
as_view
(),
name
=
'theme-positions'
),
url
(
r
'^admin/'
,
include
(
admin
.
site
.
urls
)),
url
(
r
'^api/'
,
include
(
api
.
router
.
urls
)),
url
(
r
'^$'
,
HomeView
.
as_view
(),
name
=
'home'
),
]
# Group URLs
url
(
r
'^groups/(?P<group_kind>[-\w]+)/(?P<group>[^/]+)/$'
,
RedirectGroupRepresentativeList
.
as_view
(),
name
=
'redirect-group-representative-list'
),
# Testing URLs
url
(
r
'^representatives/(?P<slug>[-\w]+)/none/$'
,
RepresentativeDetailBase
.
as_view
(),
name
=
'representative-none'
),
url
(
r
'^dossiers/(?P<pk>\d+)/none/$'
,
DossierDetailBase
.
as_view
(),
name
=
'dossier-none'
),
url
(
r
'^themes/(?P<slug>[-\w]+)/none/$'
,
ThemeDetailBase
.
as_view
(),
name
=
'theme-none'
),
]
+
legacy_patterns
templates/representatives/representative_grid.html
View file @
f45ae46a
...
...
@@ -40,13 +40,13 @@
<p
class=
"text-center"
>
<br>
{% if representative.country %}
<a
class=
"icon-badge"
href=
"{% country_url representative.country %}"
title=
"{{ representative.country.name }}"
>
{{ representative.country|country_flag }}
</a>
{{ representative.country|country_flag }}
{% endif %}
{% if representative.chamber %}
<a
class=
"icon-badge"
href=
"{% chamber_url representative.chamber %}"
title=
"{{ representative.chamber.name }}"
>
{{ representative.chamber|chamber_icon }}
</a>
{{ representative.chamber|chamber_icon }}
{% endif %}
{% if representative.main_mandate.group %}
<a
class=
"icon-badge"
href=
"{% group_url representative.main_mandate.group %}"
title=
"{{ representative.main_mandate.group.name }}"
>
{{ representative.main_mandate.group|group_icon }}
</a>
{{ representative.main_mandate.group|group_icon }}
{% endif %}
</p>
<p
class=
"text-right"
>
{{ representative.score.score|score_badge }}
</p>
...
...
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