[damned-lies] Modernized urls.py syntax
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Modernized urls.py syntax
- Date: Fri, 30 Oct 2015 16:54:41 +0000 (UTC)
commit 27f98bdd115fba4e2aa7505fab4e393e438610b1
Author: Claude Paroz <claude 2xlibre net>
Date: Fri Oct 30 17:50:04 2015 +0100
Modernized urls.py syntax
damnedlies/urls.py | 174 +++++++++++++++++++++++-----------------------------
feeds/urls.py | 7 +-
languages/urls.py | 55 ++++++++---------
people/urls.py | 42 ++++++-------
teams/urls.py | 30 +++++-----
vertimus/urls.py | 58 ++++++++---------
6 files changed, 168 insertions(+), 198 deletions(-)
---
diff --git a/damnedlies/urls.py b/damnedlies/urls.py
index 536bf2f..4aa56ca 100644
--- a/damnedlies/urls.py
+++ b/damnedlies/urls.py
@@ -1,58 +1,52 @@
# -*- coding: utf-8 -*-
-from django.conf.urls import include, patterns, url
+from django.conf.urls import include, url
from django.conf import settings
from django.contrib import admin
+from django.contrib.auth import views as auth_views
from django.views.generic import TemplateView
+from django.views.static import serve
-admin.autodiscover()
+from common import views as common_views
+from stats import views as stats_views
-urlpatterns = patterns('',
- url(
- regex = r'^$',
- view = 'common.views.index',
- name = 'home'),
- url(
- regex = r'^about/$',
- view = 'common.views.about',
- name = 'about'),
- url(
- regex = r'^login/$',
- view = 'common.views.site_login',
- name = 'login'),
- url(
- regex = r'^register/$',
- view = 'common.views.site_register',
- name = 'register'),
- url(
- regex = r'^help/(?P<topic>\w+)/$',
- view = 'common.views.help',
- name = 'help'),
- url(
- regex = r'^register/success$',
- view = TemplateView.as_view(template_name="registration/register_success.html"),
- name = 'register_success'),
- url(
- regex = r'^register/activate/(?P<key>\w+)$',
- view = 'common.views.activate_account',
- name = 'register_activation'),
- url(
- regex = r'^password_reset/$',
- view = 'django.contrib.auth.views.password_reset',
- kwargs = {'template_name':'registration/password_reset_form.html'},
+
+urlpatterns = [
+ url(r'^$',
+ common_views.index,
+ name='home'),
+ url(r'^about/$',
+ common_views.about,
+ name='about'),
+ url(r'^login/$',
+ common_views.site_login,
+ name='login'),
+ url(r'^register/$',
+ common_views.site_register,
+ name='register'),
+ url(r'^help/(?P<topic>\w+)/$',
+ common_views.help,
+ name='help'),
+ url(r'^register/success$',
+ TemplateView.as_view(template_name="registration/register_success.html"),
+ name='register_success'),
+ url(r'^register/activate/(?P<key>\w+)$',
+ common_views.activate_account,
+ name='register_activation'),
+ url(r'^password_reset/$',
+ auth_views.password_reset,
+ kwargs={'template_name':'registration/password_reset_form.html'},
name='password_reset'),
- url(
- regex = r'^password_reset/done/$',
- view = 'django.contrib.auth.views.password_reset_done',
- kwargs = {'template_name':'registration/password_reset_done.html'},
+ url(r'^password_reset/done/$',
+ auth_views.password_reset_done,
+ kwargs={'template_name':'registration/password_reset_done.html'},
name='password_reset_done'),
- url(
- regex = r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
- view = 'django.contrib.auth.views.password_reset_confirm',
+ url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
+ auth_views.password_reset_confirm,
name='password_reset_confirm'),
- url(
- regex = r'^reset/done/$',
- view = 'django.contrib.auth.views.password_reset_complete',
+ url(r'^reset/done/$',
+ auth_views.password_reset_complete,
name='password_reset_complete'),
+
url(r'^teams/', include('teams.urls')),
url(r'^people/', include('people.urls')),
url(# users is the hardcoded url in the contrib.auth User class, making it identical to /people
@@ -62,62 +56,50 @@ urlpatterns = patterns('',
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^admin/', include(admin.site.urls)),
url(r'^rss/', include('feeds.urls')),
-)
+]
-urlpatterns += patterns('stats.views',
- url(
- regex = r'^module/(?P<format>(html|json|xml))?/?$',
- view = 'modules',
- name = 'modules'),
- url(
- regex =
r'^module/po/(?P<module_name>[\w\-\+]+)/(?P<domain>[\w~\-]+)/(?P<branch_name>[\w\-\.]+)/(?P<filename>.*)$',
- view = 'dynamic_po',
- name = 'dynamic_po'),
- url(
- regex = r'^module/(?P<module_name>[\w\-\+]+)/$',
- view = 'module',
- name = 'module'),
- url(
- regex = r'^module/(?P<module_name>[\w\-\+]+)/edit/branches/$',
- view = 'module_edit_branches',
- name = 'module_edit_branches'),
- url(
- regex = r'^module/(?P<module_name>[\w\-\+]+)/branch/(?P<branch_name>[\w\-\.]+)/$',
- view = 'module_branch'),
- url(
- regex = r'^branch/(?P<branch_id>\d+)/refresh/$',
- view = 'branch_refresh',
- name = 'branch_refresh'),
- url(
- regex =
r'^module/(?P<module_name>[\w\-\+]+)/(?P<potbase>[\w~-]+)/(?P<branch_name>[\w\-\.]+)/(?P<langcode>[\w
]+)/images/$',
- view = 'docimages',
- name = 'docimages'),
- url(
- regex = r'^releases/(?P<format>(html|json|xml))?/?$',
- view = 'releases',
+urlpatterns += [
+ url(r'^module/(?P<format>(html|json|xml))?/?$',
+ stats_views.modules,
+ name='modules'),
+
url(r'^module/po/(?P<module_name>[\w\-\+]+)/(?P<domain>[\w~\-]+)/(?P<branch_name>[\w\-\.]+)/(?P<filename>.*)$',
+ stats_views.dynamic_po,
+ name='dynamic_po'),
+ url(r'^module/(?P<module_name>[\w\-\+]+)/$',
+ stats_views.module,
+ name='module'),
+ url(r'^module/(?P<module_name>[\w\-\+]+)/edit/branches/$',
+ stats_views.module_edit_branches,
+ name='module_edit_branches'),
+ url(r'^module/(?P<module_name>[\w\-\+]+)/branch/(?P<branch_name>[\w\-\.]+)/$',
+ stats_views.module_branch),
+ url(r'^branch/(?P<branch_id>\d+)/refresh/$',
+ stats_views.branch_refresh,
+ name='branch_refresh'),
+ url(
r'^module/(?P<module_name>[\w\-\+]+)/(?P<potbase>[\w~-]+)/(?P<branch_name>[\w\-\.]+)/(?P<langcode>[\w
]+)/images/$',
+ stats_views.docimages,
+ name='docimages'),
+ url(r'^releases/(?P<format>(html|json|xml))?/?$',
+ stats_views.releases,
name = 'releases'),
- url(
- regex = r'^releases/(?P<release_name>[\w-]+)/(?P<format>(html|xml))?/?$',
- view = 'release',
+ url(r'^releases/(?P<release_name>[\w-]+)/(?P<format>(html|xml))?/?$',
+ stats_views.release,
name = 'release'),
- url(
- regex = r'^releases/compare/(?P<dtype>\w+)/(?P<rels_to_compare>[/\w-]+)/$',
- view = 'compare_by_releases'),
-)
+ url(r'^releases/compare/(?P<dtype>\w+)/(?P<rels_to_compare>[/\w-]+)/$',
+ stats_views.compare_by_releases),
+]
if 'django_openid_auth' in settings.INSTALLED_APPS:
- urlpatterns += patterns('',
+ urlpatterns += [
(r'^openid/', include('django_openid_auth.urls')),
- )
+ ]
if settings.STATIC_SERVE:
- urlpatterns += patterns('',
- url(
- regex = r'^media/(?P<path>.*)$',
- view = 'django.views.static.serve',
- kwargs = {'document_root': settings.MEDIA_ROOT}),
- url(
- regex = r'^POT/(?P<path>.*)$',
- view = 'django.views.static.serve',
- kwargs = {'document_root': settings.POTDIR}),
- )
+ urlpatterns += [
+ url(r'^media/(?P<path>.*)$',
+ serve,
+ kwargs={'document_root': settings.MEDIA_ROOT}),
+ url(r'^POT/(?P<path>.*)$',
+ serve,
+ kwargs={'document_root': settings.POTDIR}),
+ ]
diff --git a/feeds/urls.py b/feeds/urls.py
index 9aecaf7..72cd282 100644
--- a/feeds/urls.py
+++ b/feeds/urls.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
-from django.conf.urls import patterns, url
+from django.conf.urls import url
from vertimus.feeds import LatestActionsByLanguage, LatestActionsByTeam
-urlpatterns = patterns('',
+
+urlpatterns = [
url(r'^languages/(?P<locale>.*)/$', LatestActionsByLanguage(), name='lang_feed'),
url(r'^teams/(?P<team_name>.*)/$', LatestActionsByTeam(), name='team_feed'),
-)
+]
diff --git a/languages/urls.py b/languages/urls.py
index f354c42..8fdca1f 100644
--- a/languages/urls.py
+++ b/languages/urls.py
@@ -1,31 +1,28 @@
# -*- coding: utf-8 -*-
-from django.conf.urls import patterns, url
+from django.conf.urls import url
-urlpatterns = patterns('',
- url(
- regex = r'^$',
- view = 'languages.views.languages',
- name = 'languages'),
- url(
- regex = r'^(?P<locale>[\w\- ]+)/all/(?P<dtype>(ui|ui-part|doc)+)/$',
- view = 'languages.views.language_all',
- name = 'language_all'),
- url(
- regex = r'^(?P<locale>[\w\- ]+)/rel-archives/$',
- view = 'languages.views.release_archives',
- name = 'language_release_archives'),
- url(
- regex = r'^(?P<locale>[\w\- ]+)/(?P<release_name>[\w-]+)/(?P<dtype>(ui|ui-part|doc)+)/$',
- view = 'languages.views.language_release',
- name = 'language_release'),
- url(
- regex = r'^(?P<locale>[\w\- ]+)/(?P<release_name>[\w-]+).xml$',
- view = 'languages.views.language_release_xml'),
- url(
- regex = r'^(?P<locale>[\w\- ]+)/(?P<release_name>[\w-]+)/(?P<dtype>(ui|ui-part|doc)+).tar.gz$',
- view = 'languages.views.language_release_tar',
- name = 'language_release_tar'),
- url(
- regex = r'^(?P<team_slug>[\w\- ]+)/$',
- view = 'teams.views.team'),
-)
+from languages import views
+from teams import views as team_views
+
+
+urlpatterns = [
+ url(r'^$',
+ views.languages,
+ name='languages'),
+ url(r'^(?P<locale>[\w\- ]+)/all/(?P<dtype>(ui|ui-part|doc)+)/$',
+ views.language_all,
+ name='language_all'),
+ url(r'^(?P<locale>[\w\- ]+)/rel-archives/$',
+ views.release_archives,
+ name='language_release_archives'),
+ url(r'^(?P<locale>[\w\- ]+)/(?P<release_name>[\w-]+)/(?P<dtype>(ui|ui-part|doc)+)/$',
+ views.language_release,
+ name='language_release'),
+ url(r'^(?P<locale>[\w\- ]+)/(?P<release_name>[\w-]+).xml$',
+ views.language_release_xml),
+ url(r'^(?P<locale>[\w\- ]+)/(?P<release_name>[\w-]+)/(?P<dtype>(ui|ui-part|doc)+).tar.gz$',
+ views.language_release_tar,
+ name='language_release_tar'),
+ url(r'^(?P<team_slug>[\w\- ]+)/$',
+ team_views.team),
+]
diff --git a/people/urls.py b/people/urls.py
index cb58ea3..fce4773 100644
--- a/people/urls.py
+++ b/people/urls.py
@@ -1,39 +1,33 @@
# -*- coding: utf-8 -*-
-from django.conf.urls import patterns, url
+from django.conf.urls import url
from django.contrib.auth.decorators import login_required
from people import views
# Regex order is really important here
-urlpatterns = patterns('people.views',
- url(
- r'^detail_change/$',
+urlpatterns = [
+ url(r'^detail_change/$',
login_required(views.PersonEditView.as_view()),
- name = 'person_detail_change'),
- url(
- regex = r'^password_change/$',
- view = 'person_password_change',
+ name='person_detail_change'),
+ url(r'^password_change/$',
+ views.person_password_change,
name='person_password_change'),
- url(
- regex = r'^team_join/$',
- view = 'person_team_join',
+ url(r'^team_join/$',
+ views.person_team_join,
name='person_team_join'),
- url(
- regex = r'^team_leave/(?P<team_slug>[\w\- ]+)/$',
- view = 'person_team_leave',
+ url(r'^team_leave/(?P<team_slug>[\w\- ]+)/$',
+ views.person_team_leave,
name='person_team_leave'),
- url(
- r'^(?P<pk>\d+)/$',
+ url(r'^(?P<pk>\d+)/$',
views.PersonDetailView.as_view(),
- name = 'person_detail_id'),
+ name='person_detail_id'),
# Equivalent to the previous, but using username instead of user pk
- url(
- r'^(?P<slug>[\w \ \-]+)/$',
+ url(r'^(?P<slug>[\w \ \-]+)/$',
views.PersonDetailView.as_view(),
- name = 'person_detail_username'),
-)
+ name='person_detail_username'),
-urlpatterns += patterns('',
- url(r'^$', views.PeopleListView.as_view(), name='people'),
-)
+ url(r'^$',
+ views.PeopleListView.as_view(),
+ name='people'),
+]
diff --git a/teams/urls.py b/teams/urls.py
index 2a68afb..e2e2b9a 100644
--- a/teams/urls.py
+++ b/teams/urls.py
@@ -1,17 +1,17 @@
# -*- coding: utf-8 -*-
-from django.conf.urls import patterns, url
+from django.conf.urls import url
-urlpatterns = patterns('teams.views',
- url(
- regex = r'^(?P<format>(xml|json))?/?$',
- view = 'teams',
- name = 'teams'),
- url(
- regex = r'^(?P<team_slug>[\w\- ]+)/$',
- view = 'team',
- name = 'team_slug'),
- url(
- regex = r'^(?P<team_slug>[\w\- ]+)/edit/',
- view = 'team_edit',
- name = 'team_edit'),
-)
+from teams import views
+
+
+urlpatterns = [
+ url(r'^(?P<format>(xml|json))?/?$',
+ views.teams,
+ name='teams'),
+ url(r'^(?P<team_slug>[\w\- ]+)/$',
+ views.team,
+ name='team_slug'),
+ url(r'^(?P<team_slug>[\w\- ]+)/edit/$',
+ views.team_edit,
+ name='team_edit'),
+]
diff --git a/vertimus/urls.py b/vertimus/urls.py
index 8dddd29..aae24da 100644
--- a/vertimus/urls.py
+++ b/vertimus/urls.py
@@ -1,33 +1,29 @@
# -*- coding: utf-8 -*-
-from django.conf.urls import patterns, url
+from django.conf.urls import url
-urlpatterns = patterns('vertimus.views',
- url(
- regex = r'^(?P<stats_id>\d+)/(?P<lang_id>\d+)$',
- view = 'vertimus_by_stats_id',
- name = 'vertimus_by_stats_id'),
- url(
- regex = r'^(?P<branch_id>\d+)/(?P<domain_id>\d+)/(?P<language_id>\d+)',
- view = 'vertimus_by_ids',
- name = 'vertimus_by_ids'),
- url(
- regex = r'^diff/(?P<action_id_1>\d+)/(?P<action_id_2>\d+)/(?P<level>\d+)/$',
- view = 'vertimus_diff',
- name = 'vertimus_diff'),
- url(
- regex =
r'^uploads/(?P<module_name>[\w\+\-\.]+)/(?P<branch_name>[\w\-\.]+)/(?P<domain_name>[\w~\-]+)/(?P<locale_name>[\w\-
]+)/latest/$',
- view = 'latest_uploaded_po',
- name = 'latest_uploaded_po'),
- url(
- regex =
'^(?P<module_name>[\w\+\-\.]+)/(?P<branch_name>[\w\-\.]+)/(?P<domain_name>[\w~\-]+)/(?P<locale_name>[\w\-
]+)/level(?P<level>\d+)/$',
- view = 'vertimus_by_names',
- name = 'vertimus_archives_by_names'),
- url(
- regex =
r'^(?P<module_name>[\w\+\-\.]+)/(?P<branch_name>[\w\-\.]+)/(?P<domain_name>[\w~\-]+)/(?P<locale_name>[\w\-
]+)',
- view = 'vertimus_by_names',
- name = 'vertimus_by_names'),
- url(
- regex = r'^(?P<locale>[\w\- ]+)/activity_summary/$',
- view = 'activity_by_language',
- name = 'activity_by_language'),
-)
+from vertimus import views
+
+
+urlpatterns = [
+ url(r'^(?P<stats_id>\d+)/(?P<lang_id>\d+)$',
+ views.vertimus_by_stats_id,
+ name='vertimus_by_stats_id'),
+ url(r'^(?P<branch_id>\d+)/(?P<domain_id>\d+)/(?P<language_id>\d+)',
+ views.vertimus_by_ids,
+ name='vertimus_by_ids'),
+ url(r'^diff/(?P<action_id_1>\d+)/(?P<action_id_2>\d+)/(?P<level>\d+)/$',
+ views.vertimus_diff,
+ name='vertimus_diff'),
+
url(r'^uploads/(?P<module_name>[\w\+\-\.]+)/(?P<branch_name>[\w\-\.]+)/(?P<domain_name>[\w~\-]+)/(?P<locale_name>[\w\-
]+)/latest/$',
+ views.latest_uploaded_po,
+ name='latest_uploaded_po'),
+
url('^(?P<module_name>[\w\+\-\.]+)/(?P<branch_name>[\w\-\.]+)/(?P<domain_name>[\w~\-]+)/(?P<locale_name>[\w\-
]+)/level(?P<level>\d+)/$',
+ views.vertimus_by_names,
+ name='vertimus_archives_by_names'),
+
url(r'^(?P<module_name>[\w\+\-\.]+)/(?P<branch_name>[\w\-\.]+)/(?P<domain_name>[\w~\-]+)/(?P<locale_name>[\w\-
]+)',
+ views.vertimus_by_names,
+ name='vertimus_by_names'),
+ url(r'^(?P<locale>[\w\- ]+)/activity_summary/$',
+ views.activity_by_language,
+ name='activity_by_language'),
+]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]