From 24debb57218de2edfa6eefdb81dceef70acfcd32 Mon Sep 17 00:00:00 2001 From: Andrew Donnellan Date: Fri, 28 Aug 2020 00:14:03 +1000 Subject: urls: Update url pattern functions Django 3.1 deprecates django.conf.urls.url() as an alias for django.urls.re_path(). Also switch to using django.urls.include() rather than django.conf.urls.include(). Signed-off-by: Andrew Donnellan Signed-off-by: Stephen Finucane --- patchwork/urls.py | 405 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 255 insertions(+), 150 deletions(-) diff --git a/patchwork/urls.py b/patchwork/urls.py index 7d888d4..79268e4 100644 --- a/patchwork/urls.py +++ b/patchwork/urls.py @@ -4,10 +4,9 @@ # SPDX-License-Identifier: GPL-2.0-or-later from django.conf import settings -from django.conf.urls import url, include from django.contrib import admin from django.contrib.auth import views as auth_views -from django.urls import reverse_lazy +from django.urls import include, re_path, reverse_lazy from patchwork.views import about as about_views from patchwork.views import api as api_views @@ -27,16 +26,23 @@ from patchwork.views import xmlrpc as xmlrpc_views admin.autodiscover() urlpatterns = [ - url(r'^admin/', admin.site.urls), - - url(r'^$', project_views.project_list, name='project-list'), - url(r'^project/(?P[^/]+)/list/$', patch_views.patch_list, - name='patch-list'), - url(r'^project/(?P[^/]+)/bundles/$', bundle_views.bundle_list, - name='bundle-list'), - url(r'^project/(?P[^/]+)/$', project_views.project_detail, - name='project-detail'), - + re_path(r'^admin/', admin.site.urls), + re_path(r'^$', project_views.project_list, name='project-list'), + re_path( + r'^project/(?P[^/]+)/list/$', + patch_views.patch_list, + name='patch-list', + ), + re_path( + r'^project/(?P[^/]+)/bundles/$', + bundle_views.bundle_list, + name='bundle-list', + ), + re_path( + r'^project/(?P[^/]+)/$', + project_views.project_detail, + name='project-detail', + ), # patch views # NOTE(dja): Per the RFC, msgids can contain slashes. There doesn't seem # to be an easy way to tell Django to urlencode the slash when generating @@ -49,134 +55,187 @@ urlpatterns = [ # work, but it is RECOMMENDED by the RFC that the right hand side of the @ # contains a domain, so I think breaking on messages that have "domains" # ending in /raw/ or /mbox/ is good enough. - url(r'^project/(?P[^/]+)/patch/(?P.+)/raw/$', - patch_views.patch_raw, name='patch-raw'), - url(r'^project/(?P[^/]+)/patch/(?P.+)/mbox/$', - patch_views.patch_mbox, name='patch-mbox'), - url(r'^project/(?P[^/]+)/patch/(?P.+)/$', - patch_views.patch_detail, name='patch-detail'), + re_path( + r'^project/(?P[^/]+)/patch/(?P.+)/raw/$', + patch_views.patch_raw, + name='patch-raw', + ), + re_path( + r'^project/(?P[^/]+)/patch/(?P.+)/mbox/$', + patch_views.patch_mbox, + name='patch-mbox', + ), + re_path( + r'^project/(?P[^/]+)/patch/(?P.+)/$', + patch_views.patch_detail, + name='patch-detail', + ), # ... old-style /patch/N/* urls - url(r'^patch/(?P\d+)/raw/$', patch_views.patch_raw_by_id, - name='patch-raw-redirect'), - url(r'^patch/(?P\d+)/mbox/$', patch_views.patch_mbox_by_id, - name='patch-mbox-redirect'), - url(r'^patch/(?P\d+)/$', patch_views.patch_by_id, - name='patch-id-redirect'), - + re_path( + r'^patch/(?P\d+)/raw/$', + patch_views.patch_raw_by_id, + name='patch-raw-redirect', + ), + re_path( + r'^patch/(?P\d+)/mbox/$', + patch_views.patch_mbox_by_id, + name='patch-mbox-redirect', + ), + re_path( + r'^patch/(?P\d+)/$', + patch_views.patch_by_id, + name='patch-id-redirect', + ), # cover views - url(r'^project/(?P[^/]+)/cover/(?P.+)/mbox/$', - cover_views.cover_mbox, name='cover-mbox'), - url(r'^project/(?P[^/]+)/cover/(?P.+)/$', - cover_views.cover_detail, name='cover-detail'), + re_path( + r'^project/(?P[^/]+)/cover/(?P.+)/mbox/$', + cover_views.cover_mbox, + name='cover-mbox', + ), + re_path( + r'^project/(?P[^/]+)/cover/(?P.+)/$', + cover_views.cover_detail, + name='cover-detail', + ), # ... old-style /cover/N/* urls - url(r'^cover/(?P\d+)/mbox/$', cover_views.cover_mbox_by_id, - name='cover-mbox-redirect'), - url(r'^cover/(?P\d+)/$', cover_views.cover_by_id, - name='cover-id-redirect'), - + re_path( + r'^cover/(?P\d+)/mbox/$', + cover_views.cover_mbox_by_id, + name='cover-mbox-redirect', + ), + re_path( + r'^cover/(?P\d+)/$', + cover_views.cover_by_id, + name='cover-id-redirect', + ), # comment views - url(r'^comment/(?P\d+)/$', comment_views.comment, - name='comment-redirect'), - + re_path( + r'^comment/(?P\d+)/$', + comment_views.comment, + name='comment-redirect', + ), # series views - url(r'^series/(?P\d+)/mbox/$', series_views.series_mbox, - name='series-mbox'), - + re_path( + r'^series/(?P\d+)/mbox/$', + series_views.series_mbox, + name='series-mbox', + ), # logged-in user stuff - url(r'^user/$', user_views.profile, name='user-profile'), - url(r'^user/todo/$', user_views.todo_lists, - name='user-todos'), - url(r'^user/todo/(?P[^/]+)/$', user_views.todo_list, - name='user-todo'), - url(r'^user/bundles/$', bundle_views.bundle_list, - name='user-bundles'), - - url(r'^user/link/$', user_views.link, - name='user-link'), - url(r'^user/unlink/(?P[^/]+)/$', user_views.unlink, - name='user-unlink'), - + re_path(r'^user/$', user_views.profile, name='user-profile'), + re_path(r'^user/todo/$', user_views.todo_lists, name='user-todos'), + re_path( + r'^user/todo/(?P[^/]+)/$', + user_views.todo_list, + name='user-todo', + ), + re_path(r'^user/bundles/$', bundle_views.bundle_list, name='user-bundles'), + re_path(r'^user/link/$', user_views.link, name='user-link'), + re_path( + r'^user/unlink/(?P[^/]+)/$', + user_views.unlink, + name='user-unlink', + ), # password change - url(r'^user/password-change/$', + re_path( + r'^user/password-change/$', auth_views.PasswordChangeView.as_view(), - name='password_change'), - url(r'^user/password-change/done/$', + name='password_change', + ), + re_path( + r'^user/password-change/done/$', auth_views.PasswordChangeDoneView.as_view(), - name='password_change_done'), - url(r'^user/password-reset/$', + name='password_change_done', + ), + re_path( + r'^user/password-reset/$', auth_views.PasswordResetView.as_view(), - name='password_reset'), - url(r'^user/password-reset/mail-sent/$', + name='password_reset', + ), + re_path( + r'^user/password-reset/mail-sent/$', auth_views.PasswordResetDoneView.as_view(), - name='password_reset_done'), - url(r'^user/password-reset/(?P[0-9A-Za-z_\-]+)/' + name='password_reset_done', + ), + re_path( + r'^user/password-reset/(?P[0-9A-Za-z_\-]+)/' r'(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', auth_views.PasswordResetConfirmView.as_view(), - name='password_reset_confirm'), - url(r'^user/password-reset/complete/$', + name='password_reset_confirm', + ), + re_path( + r'^user/password-reset/complete/$', auth_views.PasswordResetCompleteView.as_view(), - name='password_reset_complete'), - + name='password_reset_complete', + ), # login/logout - url(r'^user/login/$', auth_views.LoginView.as_view( - template_name='patchwork/login.html'), - name='auth_login'), - url(r'^user/logout/$', auth_views.LogoutView.as_view( - next_page=reverse_lazy('project-list')), - name='auth_logout'), - + re_path( + r'^user/login/$', + auth_views.LoginView.as_view(template_name='patchwork/login.html'), + name='auth_login', + ), + re_path( + r'^user/logout/$', + auth_views.LogoutView.as_view(next_page=reverse_lazy('project-list')), + name='auth_logout', + ), # registration - url(r'^register/', user_views.register, name='user-register'), - + re_path(r'^register/', user_views.register, name='user-register'), # public view for bundles - url(r'^bundle/(?P[^/]*)/(?P[^/]*)/$', + re_path( + r'^bundle/(?P[^/]*)/(?P[^/]*)/$', bundle_views.bundle_detail, - name='bundle-detail'), - url(r'^bundle/(?P[^/]*)/(?P[^/]*)/mbox/$', + name='bundle-detail', + ), + re_path( + r'^bundle/(?P[^/]*)/(?P[^/]*)/mbox/$', bundle_views.bundle_mbox, - name='bundle-mbox'), - - url(r'^confirm/(?P[0-9a-f]+)/$', notification_views.confirm, - name='confirm'), - + name='bundle-mbox', + ), + re_path( + r'^confirm/(?P[0-9a-f]+)/$', + notification_views.confirm, + name='confirm', + ), # submitter autocomplete - url(r'^submitter/$', api_views.submitters, name='api-submitters'), - url(r'^delegate/$', api_views.delegates, name='api-delegates'), - + re_path(r'^submitter/$', api_views.submitters, name='api-submitters'), + re_path(r'^delegate/$', api_views.delegates, name='api-delegates'), # email setup - url(r'^mail/$', mail_views.settings, name='mail-settings'), - url(r'^mail/optout/$', mail_views.optout, name='mail-optout'), - url(r'^mail/optin/$', mail_views.optin, name='mail-optin'), - + re_path(r'^mail/$', mail_views.settings, name='mail-settings'), + re_path(r'^mail/optout/$', mail_views.optout, name='mail-optout'), + re_path(r'^mail/optin/$', mail_views.optin, name='mail-optin'), # about - url(r'^about/$', about_views.about, name='about'), - + re_path(r'^about/$', about_views.about, name='about'), # legacy redirects - url(r'^help/$', about_views.redirect, name='help'), - url(r'^help/about/$', about_views.redirect, name='help-about'), + re_path(r'^help/$', about_views.redirect, name='help'), + re_path(r'^help/about/$', about_views.redirect, name='help-about'), ] if 'debug_toolbar' in settings.INSTALLED_APPS: import debug_toolbar # noqa urlpatterns += [ - url(r'^__debug__/', include(debug_toolbar.urls)), + re_path(r'^__debug__/', include(debug_toolbar.urls)), ] if settings.ENABLE_XMLRPC: urlpatterns += [ - url(r'xmlrpc/$', xmlrpc_views.xmlrpc, name='xmlrpc'), - url(r'^project/(?P[^/]+)/pwclientrc/$', + re_path(r'xmlrpc/$', xmlrpc_views.xmlrpc, name='xmlrpc'), + re_path( + r'^project/(?P[^/]+)/pwclientrc/$', pwclient_views.pwclientrc, - name='pwclientrc'), + name='pwclientrc', + ), # legacy redirect - url(r'^help/pwclient/$', about_views.redirect, name='help-pwclient'), + re_path( + r'^help/pwclient/$', about_views.redirect, name='help-pwclient' + ), ] if settings.ENABLE_REST_API: if 'rest_framework' not in settings.INSTALLED_APPS: raise RuntimeError( - 'djangorestframework must be installed to enable the REST API.') + 'djangorestframework must be installed to enable the REST API.' + ) from patchwork.api import bundle as api_bundle_views # noqa from patchwork.api import check as api_check_views # noqa @@ -191,88 +250,134 @@ if settings.ENABLE_REST_API: from patchwork.api import user as api_user_views # noqa api_patterns = [ - url(r'^$', - api_index_views.IndexView.as_view(), - name='api-index'), - url(r'^users/$', + re_path(r'^$', api_index_views.IndexView.as_view(), name='api-index'), + re_path( + r'^users/$', api_user_views.UserList.as_view(), - name='api-user-list'), - url(r'^users/(?P[^/]+)/$', + name='api-user-list', + ), + re_path( + r'^users/(?P[^/]+)/$', api_user_views.UserDetail.as_view(), - name='api-user-detail'), - url(r'^people/$', + name='api-user-detail', + ), + re_path( + r'^people/$', api_person_views.PersonList.as_view(), - name='api-person-list'), - url(r'^people/(?P[^/]+)/$', + name='api-person-list', + ), + re_path( + r'^people/(?P[^/]+)/$', api_person_views.PersonDetail.as_view(), - name='api-person-detail'), - url(r'^covers/$', + name='api-person-detail', + ), + re_path( + r'^covers/$', api_cover_views.CoverList.as_view(), - name='api-cover-list'), - url(r'^covers/(?P[^/]+)/$', + name='api-cover-list', + ), + re_path( + r'^covers/(?P[^/]+)/$', api_cover_views.CoverDetail.as_view(), - name='api-cover-detail'), - url(r'^patches/$', + name='api-cover-detail', + ), + re_path( + r'^patches/$', api_patch_views.PatchList.as_view(), - name='api-patch-list'), - url(r'^patches/(?P[^/]+)/$', + name='api-patch-list', + ), + re_path( + r'^patches/(?P[^/]+)/$', api_patch_views.PatchDetail.as_view(), - name='api-patch-detail'), - url(r'^patches/(?P[^/]+)/checks/$', + name='api-patch-detail', + ), + re_path( + r'^patches/(?P[^/]+)/checks/$', api_check_views.CheckListCreate.as_view(), - name='api-check-list'), - url(r'^patches/(?P[^/]+)/checks/(?P[^/]+)/$', + name='api-check-list', + ), + re_path( + r'^patches/(?P[^/]+)/checks/(?P[^/]+)/$', api_check_views.CheckDetail.as_view(), - name='api-check-detail'), - url(r'^series/$', + name='api-check-detail', + ), + re_path( + r'^series/$', api_series_views.SeriesList.as_view(), - name='api-series-list'), - url(r'^series/(?P[^/]+)/$', + name='api-series-list', + ), + re_path( + r'^series/(?P[^/]+)/$', api_series_views.SeriesDetail.as_view(), - name='api-series-detail'), - url(r'^bundles/$', + name='api-series-detail', + ), + re_path( + r'^bundles/$', api_bundle_views.BundleList.as_view(), - name='api-bundle-list'), - url(r'^bundles/(?P[^/]+)/$', + name='api-bundle-list', + ), + re_path( + r'^bundles/(?P[^/]+)/$', api_bundle_views.BundleDetail.as_view(), - name='api-bundle-detail'), - url(r'^projects/$', + name='api-bundle-detail', + ), + re_path( + r'^projects/$', api_project_views.ProjectList.as_view(), - name='api-project-list'), - url(r'^projects/(?P[^/]+)/$', + name='api-project-list', + ), + re_path( + r'^projects/(?P[^/]+)/$', api_project_views.ProjectDetail.as_view(), - name='api-project-detail'), - url(r'^events/$', + name='api-project-detail', + ), + re_path( + r'^events/$', api_event_views.EventList.as_view(), - name='api-event-list'), + name='api-event-list', + ), ] api_1_1_patterns = [ - url(r'^patches/(?P[^/]+)/comments/$', + re_path( + r'^patches/(?P[^/]+)/comments/$', api_comment_views.PatchCommentList.as_view(), - name='api-patch-comment-list'), - url(r'^covers/(?P[^/]+)/comments/$', + name='api-patch-comment-list', + ), + re_path( + r'^covers/(?P[^/]+)/comments/$', api_comment_views.CoverCommentList.as_view(), - name='api-cover-comment-list'), + name='api-cover-comment-list', + ), ] urlpatterns += [ - url(r'^api/(?:(?P(1.0|1.1|1.2))/)?', include(api_patterns)), - url(r'^api/(?:(?P(1.1|1.2))/)?', include(api_1_1_patterns)), - + re_path( + r'^api/(?:(?P(1.0|1.1|1.2))/)?', include(api_patterns) + ), + re_path( + r'^api/(?:(?P(1.1|1.2))/)?', include(api_1_1_patterns) + ), # token change - url(r'^user/generate-token/$', user_views.generate_token, - name='generate_token'), + re_path( + r'^user/generate-token/$', + user_views.generate_token, + name='generate_token', + ), ] # redirect from old urls if settings.COMPAT_REDIR: urlpatterns += [ - url(r'^user/bundle/(?P[^/]+)/$', + re_path( + r'^user/bundle/(?P[^/]+)/$', bundle_views.bundle_detail_redir, - name='bundle-redir'), - url(r'^user/bundle/(?P[^/]+)/mbox/$', + name='bundle-redir', + ), + re_path( + r'^user/bundle/(?P[^/]+)/mbox/$', bundle_views.bundle_mbox_redir, - name='bundle-mbox-redir'), + name='bundle-mbox-redir', + ), ] -- cgit v1.2.3