Commit 94bdf553 authored by Claude Paroz's avatar Claude Paroz

Use the new path() syntax for URLs

parent d23f2e19
Pipeline #16666 passed with stage
in 5 minutes and 59 seconds
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.urls import include, path, re_path, register_converter
from django.urls.converters import StringConverter
from django.views.decorators.http import require_POST
from django.views.generic import TemplateView
from django.views.static import serve
......@@ -10,96 +11,108 @@ from common import views as common_views
from stats import views as stats_views
class LocaleConverter(StringConverter):
regex = '[-_a-zA-Z@]+'
class NameConverter(StringConverter):
regex = '[-~\w\+\.]+'
register_converter(LocaleConverter, 'locale')
register_converter(NameConverter, 'name')
module_branch_domain = '<name:module_name>/<name:branch_name>/<name:domain_name>'
urlpatterns = [
url(r'^$',
common_views.index,
name='home'),
url(r'^about/$',
common_views.about,
name='about'),
url(r'^login/$',
common_views.LoginView.as_view(template_name='login.html'),
name='login'),
url(r'^logout/$',
require_POST(auth_views.LogoutView.as_view()),
name='logout'),
url(r'^register/$',
common_views.site_register,
name='register'),
url(r'^help/(?P<topic>\w+)/(?P<modal>[0-1])?/?$',
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.PasswordResetView.as_view(template_name='registration/password_reset_form.html'),
name='password_reset'),
url(r'^password_reset/done/$',
auth_views.PasswordResetDoneView.as_view(template_name='registration/password_reset_done.html'),
name='password_reset_done'),
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.PasswordResetConfirmView.as_view(),
name='password_reset_confirm'),
url(r'^reset/done/$',
auth_views.PasswordResetCompleteView.as_view(),
name='password_reset_complete'),
path('',
common_views.index,
name='home'),
path('about/',
common_views.about,
name='about'),
path('login/',
common_views.LoginView.as_view(template_name='login.html'),
name='login'),
path('logout/',
require_POST(auth_views.LogoutView.as_view()),
name='logout'),
path('register/',
common_views.site_register,
name='register'),
re_path(r'^help/(?P<topic>\w+)/(?P<modal>[0-1])?/?$',
common_views.help,
name='help'),
path('register/success/',
TemplateView.as_view(template_name="registration/register_success.html"),
name='register_success'),
path('register/activate/<slug:key>',
common_views.activate_account,
name='register_activation'),
path('password_reset/',
auth_views.PasswordResetView.as_view(template_name='registration/password_reset_form.html'),
name='password_reset'),
path('password_reset/done/',
auth_views.PasswordResetDoneView.as_view(template_name='registration/password_reset_done.html'),
name='password_reset_done'),
path('reset/<slug:uidb64>/<slug:token>/',
auth_views.PasswordResetConfirmView.as_view(),
name='password_reset_confirm'),
path('reset/done/',
auth_views.PasswordResetCompleteView.as_view(),
name='password_reset_complete'),
# Webhook endpoint
url(r'^pull_code/$', common_views.pull_code),
path('pull_code/', common_views.pull_code),
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
r'^users/', include('people.urls')),
url(r'^languages/', include('languages.urls')),
url(r'^vertimus/', include('vertimus.urls')),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^admin/', admin.site.urls),
url(r'^rss/', include('feeds.urls')),
path('teams/', include('teams.urls')),
path('people/', include('people.urls')),
# users is the hardcoded url in the contrib.auth User class, making it identical to /people
path('users/', include('people.urls')),
path('languages/', include('languages.urls')),
path('vertimus/', include('vertimus.urls')),
path('i18n/', include('django.conf.urls.i18n')),
path('admin/', admin.site.urls),
path('rss/', include('feeds.urls')),
]
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,
name='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(r'^releases/(?P<release_name>[\w-]+)/(?P<format>(html|xml))?/?$',
stats_views.release,
name = 'release'),
url(r'^releases/compare/(?P<dtype>\w+)/(?P<rels_to_compare>[/\w-]+)/$',
stats_views.compare_by_releases),
re_path(r'^module/(?P<format>(html|json|xml))?/?$',
stats_views.modules,
name='modules'),
path('module/po/%s/<filename>' % module_branch_domain,
stats_views.dynamic_po,
name='dynamic_po'),
path('module/<name:module_name>/',
stats_views.module,
name='module'),
path('module/<name:module_name>/edit/branches/',
stats_views.module_edit_branches,
name='module_edit_branches'),
path('module/<name:module_name>/branch/<name:branch_name>/',
stats_views.module_branch,
name='module_branch'),
path('branch/<int:branch_id>/refresh/',
stats_views.branch_refresh,
name='branch_refresh'),
path('module/<name:module_name>/<name:potbase>/<name:branch_name>/<locale:langcode>/images/',
stats_views.docimages,
name='docimages'),
re_path(r'^releases/(?P<format>(html|json|xml))?/?$',
stats_views.releases,
name='releases'),
re_path(r'^releases/(?P<release_name>[\w-]+)/(?P<format>(html|xml))?/?$',
stats_views.release,
name='release'),
path('releases/compare/<dtype>/<path:rels_to_compare>/',
stats_views.compare_by_releases),
]
if settings.STATIC_SERVE:
urlpatterns += [
url(r'^media/(?P<path>.*)$',
serve,
kwargs={'document_root': settings.MEDIA_ROOT}),
url(r'^POT/(?P<path>.*)$',
serve,
kwargs={'document_root': settings.POTDIR}),
path('media/<path:path>',
serve,
kwargs={'document_root': settings.MEDIA_ROOT}),
path('POT/<path:path>',
serve,
kwargs={'document_root': settings.POTDIR}),
]
from django.conf.urls import url
from django.urls import path
from vertimus.feeds import LatestActionsByLanguage, LatestActionsByTeam
urlpatterns = [
url(r'^languages/(?P<locale>.*)/$', LatestActionsByLanguage(), name='lang_feed'),
url(r'^teams/(?P<team_name>.*)/$', LatestActionsByTeam(), name='team_feed'),
path('languages/<locale:locale>)/', LatestActionsByLanguage(), name='lang_feed'),
path('teams/<locale:team_name>/', LatestActionsByTeam(), name='team_feed'),
]
from django.conf.urls import url
from django.urls import path
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,
name='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),
path('',
views.languages,
name='languages'),
path('<locale:locale>/all/<slug:dtype>/',
views.language_all,
name='language_all'),
path('<locale:locale>/rel-archives/',
views.release_archives,
name='language_release_archives'),
path('<locale:locale>/<name:release_name>/<slug:dtype>/',
views.language_release,
name='language_release'),
path('<locale:locale>/<name:release_name>.xml',
views.language_release_xml,
name='language_release_xml'),
path('<locale:locale>)/<name:release_name>/<slug:dtype>.tar.gz',
views.language_release_tar,
name='language_release_tar'),
path('<locale:team_slug>/',
team_views.team),
]
from django.conf.urls import url
from django.contrib.auth.decorators import login_required
from django.urls import path
from people import views
# Regex order is really important here
urlpatterns = [
url(r'^detail_change/$',
login_required(views.PersonEditView.as_view()),
name='person_detail_change'),
url(r'^password_change/$',
views.person_password_change,
name='person_password_change'),
url(r'^team_join/$',
views.person_team_join,
name='person_team_join'),
url(r'^team_leave/(?P<team_slug>[\w\-@]+)/$',
views.person_team_leave,
name='person_team_leave'),
url(r'^(?P<pk>\d+)/$',
views.PersonDetailView.as_view(),
name='person_detail_id'),
path('detail_change/',
login_required(views.PersonEditView.as_view()),
name='person_detail_change'),
path('password_change/',
views.person_password_change,
name='person_password_change'),
path('team_join/',
views.person_team_join,
name='person_team_join'),
path('team_leave/<locale:team_slug>/',
views.person_team_leave,
name='person_team_leave'),
path('<int:pk>/',
views.PersonDetailView.as_view(),
name='person_detail_id'),
# Equivalent to the previous, but using username instead of user pk
url(r'^(?P<slug>[\w@\.\-]+)/$',
views.PersonDetailView.as_view(),
name='person_detail_username'),
path('<slug>/',
views.PersonDetailView.as_view(),
name='person_detail_username'),
url(r'^$',
views.PeopleListView.as_view(),
name='people'),
path('', views.PeopleListView.as_view(), name='people'),
]
......@@ -306,13 +306,13 @@ class ModuleTestCase(TestCase):
""" Test the creation of a blank po file for a new language """
Language.objects.create(name="Tamil", locale="ta")
self.branch.update_stats(force=False) # At least POT stats needed
response = self.client.get('/module/po/gnome-hello/po/master/ta.po')
response = self.client.get('/module/po/gnome-hello/master/po/ta.po')
self.assertContains(response, """# Tamil translation for gnome-hello.
# Copyright (C) %s gnome-hello's COPYRIGHT HOLDER
# This file is distributed under the same license as the gnome-hello package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.""" % date.today().year)
self.assertContains(response, "Language-Team: Tamil <ta@li.org>")
response = self.client.get('/module/po/gnome-hello/po/master/ta-reduced.po')
response = self.client.get('/module/po/gnome-hello/master/po/ta-reduced.po')
self.assertContains(response, """# Tamil translation for gnome-hello.""")
@test_scratchdir
......
......@@ -184,7 +184,7 @@ def docimages(request, module_name, potbase, branch_name, langcode):
}
return render(request, 'module_images.html', context)
def dynamic_po(request, module_name, domain, branch_name, filename):
def dynamic_po(request, module_name, branch_name, domain_name, filename):
""" Generates a dynamic po file from the POT file of a branch """
try:
locale, ext = filename.split(".")
......@@ -198,7 +198,7 @@ def dynamic_po(request, module_name, domain, branch_name, filename):
language = get_object_or_404(Language.objects.select_related('team'), locale=locale)
branch = get_object_or_404(Branch, module__name=module_name, name=branch_name)
try:
domain = branch.get_domains()[domain]
domain = branch.get_domains()[domain_name]
except KeyError:
raise Http404
potfile = get_object_or_404(Statistics, branch=branch, domain=domain, language=None)
......
from django.conf.urls import url
from django.urls import path, re_path
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'),
re_path(r'^(?P<format>(xml|json))?/?$',
views.teams,
name='teams'),
path('(<locale:team_slug>/',
views.team,
name='team_slug'),
path('<locale:team_slug>/edit/',
views.team_edit,
name='team_edit'),
]
......@@ -679,7 +679,7 @@ class VertimusTest(TeamsAndRolesTests):
)
self.assertEqual(
doc.getElementsByTagName('guid')[0].toxml(),
"""<guid>http://testserver/vertimus/gedit/gnome-2-24/po/fr#%d</guid>""" % action.pk
"""<guid>http://testserver/vertimus/gedit/gnome-2-24/po/fr/#%d</guid>""" % action.pk
)
response = self.client.get(reverse('team_feed', args=[self.l.team.name]))
......
from django.conf.urls import url
from django.urls import path
from damnedlies.urls import module_branch_domain
from vertimus import views
module_branch_domain = r'(?P<module_name>[\w\+\-\.]+)/(?P<branch_name>[\w\-\.]+)/(?P<domain_name>[\w~\-]+)'
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/%s/(?P<locale_name>[\w\-@]+)/latest/$' % module_branch_domain,
views.latest_uploaded_po,
name='latest_uploaded_po'),
url(r'^%s/(?P<locale_name>[\w\-@]+)/level(?P<level>\d+)/$' % module_branch_domain,
views.vertimus_by_names,
name='vertimus_archives_by_names'),
url(r'^%s/(?P<locale_name>[\w\-@]+)' % module_branch_domain,
views.vertimus_by_names,
name='vertimus_by_names'),
url(r'^(?P<locale>[\w\-@]+)/activity_summary/$',
views.activity_by_language,
name='activity_by_language'),
url(r'^action/(?P<pk>\d+)/qcheck/', views.quality_check, name='quality-check'),
path('<int:stats_id>/<int:lang_id>/',
views.vertimus_by_stats_id,
name='vertimus_by_stats_id'),
path('<int:branch_id>/<int:domain_id>/<int:language_id>/',
views.vertimus_by_ids,
name='vertimus_by_ids'),
path('diff/<int:action_id_1>/<int:action_id_2>/<int:level>/',
views.vertimus_diff,
name='vertimus_diff'),
path('uploads/%s/<locale:locale_name>)/latest/' % module_branch_domain,
views.latest_uploaded_po,
name='latest_uploaded_po'),
path('%s/<locale:locale_name>/level<int:level>/' % module_branch_domain,
views.vertimus_by_names,
name='vertimus_archives_by_names'),
path('%s/<locale:locale_name>/' % module_branch_domain,
views.vertimus_by_names,
name='vertimus_by_names'),
path('<locale:locale>/activity_summary/',
views.activity_by_language,
name='activity_by_language'),
path('action/<int:pk>/qcheck/', views.quality_check, name='quality-check'),
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment