]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
urls: Convert to flask-style URL patterns
authorStephen Finucane <stephen@that.guru>
Sat, 20 Feb 2021 13:08:04 +0000 (13:08 +0000)
committerStephen Finucane <stephen@that.guru>
Sat, 20 Feb 2021 14:10:11 +0000 (14:10 +0000)
These are easier to grok that the old regex based paths, though three
of these are retained as an alternative to creating custom path
converters [1].

[1] https://docs.djangoproject.com/en/3.0/topics/http/urls/#registering-custom-path-converters

Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/urls.py

index be388ac5d383b28a027eec83de88e16c1a9262b4..6ac9b81a8c034e5beadbac2ca0608d2018cbe6af 100644 (file)
@@ -6,7 +6,10 @@
 from django.conf import settings
 from django.contrib import admin
 from django.contrib.auth import views as auth_views
-from django.urls import include, re_path, reverse_lazy
+from django.urls import include
+from django.urls import path
+from django.urls import re_path
+from django.urls import reverse_lazy
 
 from patchwork.views import about as about_views
 from patchwork.views import api as api_views
@@ -26,20 +29,20 @@ from patchwork.views import xmlrpc as xmlrpc_views
 admin.autodiscover()
 
 urlpatterns = [
-    re_path(r'^admin/', admin.site.urls),
-    re_path(r'^$', project_views.project_list, name='project-list'),
-    re_path(
-        r'^project/(?P<project_id>[^/]+)/list/$',
+    path('admin/', admin.site.urls),
+    path('', project_views.project_list, name='project-list'),
+    path(
+        'project/<project_id>/list/',
         patch_views.patch_list,
         name='patch-list',
     ),
-    re_path(
-        r'^project/(?P<project_id>[^/]+)/bundles/$',
+    path(
+        'project/<project_id>/bundles/',
         bundle_views.bundle_list,
         name='bundle-list',
     ),
-    re_path(
-        r'^project/(?P<project_id>[^/]+)/$',
+    path(
+        'project/<project_id>/',
         project_views.project_detail,
         name='project-detail',
     ),
@@ -55,139 +58,130 @@ 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.
-    re_path(
-        r'^project/(?P<project_id>[^/]+)/patch/(?P<msgid>.+)/raw/$',
+    path(
+        'project/<project_id>/patch/<path:msgid>/raw/',
         patch_views.patch_raw,
         name='patch-raw',
     ),
-    re_path(
-        r'^project/(?P<project_id>[^/]+)/patch/(?P<msgid>.+)/mbox/$',
+    path(
+        'project/<project_id>/patch/<path:msgid>/mbox/',
         patch_views.patch_mbox,
         name='patch-mbox',
     ),
-    re_path(
-        r'^project/(?P<project_id>[^/]+)/patch/(?P<msgid>.+)/$',
+    path(
+        'project/<project_id>/patch/<path:msgid>/',
         patch_views.patch_detail,
         name='patch-detail',
     ),
     # ... old-style /patch/N/* urls
-    re_path(
-        r'^patch/(?P<patch_id>\d+)/raw/$',
+    path(
+        'patch/<int:patch_id>/raw/',
         patch_views.patch_raw_by_id,
         name='patch-raw-redirect',
     ),
-    re_path(
-        r'^patch/(?P<patch_id>\d+)/mbox/$',
+    path(
+        'patch/<int:patch_id>/mbox/',
         patch_views.patch_mbox_by_id,
         name='patch-mbox-redirect',
     ),
-    re_path(
-        r'^patch/(?P<patch_id>\d+)/$',
+    path(
+        'patch/<int:patch_id>/',
         patch_views.patch_by_id,
         name='patch-id-redirect',
     ),
     # cover views
-    re_path(
-        r'^project/(?P<project_id>[^/]+)/cover/(?P<msgid>.+)/mbox/$',
+    path(
+        'project/<project_id>/cover/<path:msgid>/mbox/',
         cover_views.cover_mbox,
         name='cover-mbox',
     ),
-    re_path(
-        r'^project/(?P<project_id>[^/]+)/cover/(?P<msgid>.+)/$',
+    path(
+        'project/<project_id>/cover/<path:msgid>/',
         cover_views.cover_detail,
         name='cover-detail',
     ),
     # ... old-style /cover/N/* urls
-    re_path(
-        r'^cover/(?P<cover_id>\d+)/mbox/$',
+    path(
+        'cover/<int:cover_id>/mbox/',
         cover_views.cover_mbox_by_id,
         name='cover-mbox-redirect',
     ),
-    re_path(
-        r'^cover/(?P<cover_id>\d+)/$',
+    path(
+        'cover/<int:cover_id>/',
         cover_views.cover_by_id,
         name='cover-id-redirect',
     ),
     # comment views
-    re_path(
-        r'^comment/(?P<comment_id>\d+)/$',
+    path(
+        'comment/<int:comment_id>/',
         comment_views.comment,
         name='comment-redirect',
     ),
     # series views
-    re_path(
-        r'^series/(?P<series_id>\d+)/mbox/$',
+    path(
+        'series/<int:series_id>/mbox/',
         series_views.series_mbox,
         name='series-mbox',
     ),
     # logged-in user stuff
-    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<project_id>[^/]+)/$',
-        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<person_id>[^/]+)/$',
-        user_views.unlink,
-        name='user-unlink',
-    ),
+    path('user/', user_views.profile, name='user-profile'),
+    path('user/todo/', user_views.todo_lists, name='user-todos'),
+    path('user/todo/<project_id>/', user_views.todo_list, name='user-todo'),
+    path('user/bundles/', bundle_views.bundle_list, name='user-bundles'),
+    path('user/link/', user_views.link, name='user-link'),
+    path('user/unlink/<person_id>/', user_views.unlink, name='user-unlink'),
     # password change
-    re_path(
-        r'^user/password-change/$',
+    path(
+        'user/password-change/',
         auth_views.PasswordChangeView.as_view(),
         name='password_change',
     ),
-    re_path(
-        r'^user/password-change/done/$',
+    path(
+        'user/password-change/done/',
         auth_views.PasswordChangeDoneView.as_view(),
         name='password_change_done',
     ),
-    re_path(
-        r'^user/password-reset/$',
+    path(
+        'user/password-reset/',
         auth_views.PasswordResetView.as_view(),
         name='password_reset',
     ),
-    re_path(
-        r'^user/password-reset/mail-sent/$',
+    path(
+        'user/password-reset/mail-sent/',
         auth_views.PasswordResetDoneView.as_view(),
         name='password_reset_done',
     ),
-    re_path(
-        r'^user/password-reset/(?P<uidb64>[0-9A-Za-z_\-]+)/'
-        r'(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,32})/$',
+    path(
+        'user/password-reset/<uidb64>/<token>/',
         auth_views.PasswordResetConfirmView.as_view(),
         name='password_reset_confirm',
     ),
-    re_path(
-        r'^user/password-reset/complete/$',
+    path(
+        'user/password-reset/complete/',
         auth_views.PasswordResetCompleteView.as_view(),
         name='password_reset_complete',
     ),
     # login/logout
-    re_path(
-        r'^user/login/$',
+    path(
+        'user/login/',
         auth_views.LoginView.as_view(template_name='patchwork/login.html'),
         name='auth_login',
     ),
-    re_path(
-        r'^user/logout/$',
+    path(
+        'user/logout/',
         auth_views.LogoutView.as_view(next_page=reverse_lazy('project-list')),
         name='auth_logout',
     ),
     # registration
-    re_path(r'^register/', user_views.register, name='user-register'),
+    path('register/', user_views.register, name='user-register'),
     # public view for bundles
-    re_path(
-        r'^bundle/(?P<username>[^/]*)/(?P<bundlename>[^/]*)/$',
+    path(
+        'bundle/<username>/<bundlename>/',
         bundle_views.bundle_detail,
         name='bundle-detail',
     ),
-    re_path(
-        r'^bundle/(?P<username>[^/]*)/(?P<bundlename>[^/]*)/mbox/$',
+    path(
+        'bundle/<username>/<bundlename>/mbox/',
         bundle_views.bundle_mbox,
         name='bundle-mbox',
     ),
@@ -197,38 +191,36 @@ urlpatterns = [
         name='confirm',
     ),
     # submitter autocomplete
-    re_path(r'^submitter/$', api_views.submitters, name='api-submitters'),
-    re_path(r'^delegate/$', api_views.delegates, name='api-delegates'),
+    path('submitter/', api_views.submitters, name='api-submitters'),
+    path('delegate/', api_views.delegates, name='api-delegates'),
     # email setup
-    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'),
+    path('mail/', mail_views.settings, name='mail-settings'),
+    path('mail/optout/', mail_views.optout, name='mail-optout'),
+    path('mail/optin/', mail_views.optin, name='mail-optin'),
     # about
-    re_path(r'^about/$', about_views.about, name='about'),
+    path('about/', about_views.about, name='about'),
     # legacy redirects
-    re_path(r'^help/$', about_views.redirect, name='help'),
-    re_path(r'^help/about/$', about_views.redirect, name='help-about'),
+    path('help/', about_views.redirect, name='help'),
+    path('help/about/', about_views.redirect, name='help-about'),
 ]
 
 if 'debug_toolbar' in settings.INSTALLED_APPS:
     import debug_toolbar  # noqa
 
     urlpatterns += [
-        re_path(r'^__debug__/', include(debug_toolbar.urls)),
+        path('__debug__/', include(debug_toolbar.urls)),
     ]
 
 if settings.ENABLE_XMLRPC:
     urlpatterns += [
-        re_path(r'xmlrpc/$', xmlrpc_views.xmlrpc, name='xmlrpc'),
-        re_path(
-            r'^project/(?P<project_id>[^/]+)/pwclientrc/$',
+        path('xmlrpc/', xmlrpc_views.xmlrpc, name='xmlrpc'),
+        path(
+            'project/<project_id>/pwclientrc/',
             pwclient_views.pwclientrc,
             name='pwclientrc',
         ),
         # legacy redirect
-        re_path(
-            r'^help/pwclient/$', about_views.redirect, name='help-pwclient'
-        ),
+        path('help/pwclient/', about_views.redirect, name='help-pwclient'),
     ]
 
 if settings.ENABLE_REST_API:
@@ -250,102 +242,102 @@ if settings.ENABLE_REST_API:
     from patchwork.api import user as api_user_views  # noqa
 
     api_patterns = [
-        re_path(r'^$', api_index_views.IndexView.as_view(), name='api-index'),
-        re_path(
-            r'^users/$',
+        path('', api_index_views.IndexView.as_view(), name='api-index'),
+        path(
+            'users/',
             api_user_views.UserList.as_view(),
             name='api-user-list',
         ),
-        re_path(
-            r'^users/(?P<pk>[^/]+)/$',
+        path(
+            'users/<pk>/',
             api_user_views.UserDetail.as_view(),
             name='api-user-detail',
         ),
-        re_path(
-            r'^people/$',
+        path(
+            'people/',
             api_person_views.PersonList.as_view(),
             name='api-person-list',
         ),
-        re_path(
-            r'^people/(?P<pk>[^/]+)/$',
+        path(
+            'people/<pk>/',
             api_person_views.PersonDetail.as_view(),
             name='api-person-detail',
         ),
-        re_path(
-            r'^covers/$',
+        path(
+            'covers/',
             api_cover_views.CoverList.as_view(),
             name='api-cover-list',
         ),
-        re_path(
-            r'^covers/(?P<pk>[^/]+)/$',
+        path(
+            'covers/<pk>/',
             api_cover_views.CoverDetail.as_view(),
             name='api-cover-detail',
         ),
-        re_path(
-            r'^patches/$',
+        path(
+            'patches/',
             api_patch_views.PatchList.as_view(),
             name='api-patch-list',
         ),
-        re_path(
-            r'^patches/(?P<pk>[^/]+)/$',
+        path(
+            'patches/<pk>/',
             api_patch_views.PatchDetail.as_view(),
             name='api-patch-detail',
         ),
-        re_path(
-            r'^patches/(?P<patch_id>[^/]+)/checks/$',
+        path(
+            'patches/<patch_id>/checks/',
             api_check_views.CheckListCreate.as_view(),
             name='api-check-list',
         ),
-        re_path(
-            r'^patches/(?P<patch_id>[^/]+)/checks/(?P<check_id>[^/]+)/$',
+        path(
+            'patches/<patch_id>/checks/<check_id>/',
             api_check_views.CheckDetail.as_view(),
             name='api-check-detail',
         ),
-        re_path(
-            r'^series/$',
+        path(
+            'series/',
             api_series_views.SeriesList.as_view(),
             name='api-series-list',
         ),
-        re_path(
-            r'^series/(?P<pk>[^/]+)/$',
+        path(
+            'series/<pk>/',
             api_series_views.SeriesDetail.as_view(),
             name='api-series-detail',
         ),
-        re_path(
-            r'^bundles/$',
+        path(
+            'bundles/',
             api_bundle_views.BundleList.as_view(),
             name='api-bundle-list',
         ),
-        re_path(
-            r'^bundles/(?P<pk>[^/]+)/$',
+        path(
+            'bundles/<pk>/',
             api_bundle_views.BundleDetail.as_view(),
             name='api-bundle-detail',
         ),
-        re_path(
-            r'^projects/$',
+        path(
+            'projects/',
             api_project_views.ProjectList.as_view(),
             name='api-project-list',
         ),
-        re_path(
-            r'^projects/(?P<pk>[^/]+)/$',
+        path(
+            'projects/<pk>/',
             api_project_views.ProjectDetail.as_view(),
             name='api-project-detail',
         ),
-        re_path(
-            r'^events/$',
+        path(
+            'events/',
             api_event_views.EventList.as_view(),
             name='api-event-list',
         ),
     ]
 
     api_1_1_patterns = [
-        re_path(
-            r'^patches/(?P<pk>[^/]+)/comments/$',
+        path(
+            'patches/<pk>/comments/',
             api_comment_views.PatchCommentList.as_view(),
             name='api-patch-comment-list',
         ),
-        re_path(
-            r'^covers/(?P<pk>[^/]+)/comments/$',
+        path(
+            'covers/<pk>/comments/',
             api_comment_views.CoverCommentList.as_view(),
             name='api-cover-comment-list',
         ),
@@ -359,8 +351,8 @@ if settings.ENABLE_REST_API:
             r'^api/(?:(?P<version>(1.1|1.2))/)?', include(api_1_1_patterns)
         ),
         # token change
-        re_path(
-            r'^user/generate-token/$',
+        path(
+            'user/generate-token/',
             user_views.generate_token,
             name='generate_token',
         ),
@@ -370,13 +362,13 @@ if settings.ENABLE_REST_API:
 # redirect from old urls
 if settings.COMPAT_REDIR:
     urlpatterns += [
-        re_path(
-            r'^user/bundle/(?P<bundle_id>[^/]+)/$',
+        path(
+            'user/bundle/<bundle_id>/',
             bundle_views.bundle_detail_redir,
             name='bundle-redir',
         ),
-        re_path(
-            r'^user/bundle/(?P<bundle_id>[^/]+)/mbox/$',
+        path(
+            'user/bundle/<bundle_id>/mbox/',
             bundle_views.bundle_mbox_redir,
             name='bundle-mbox-redir',
         ),