From a3c475f137773b78afa550a2e468e489b19226b4 Mon Sep 17 00:00:00 2001 From: wowol Date: Tue, 5 May 2020 13:39:57 +0200 Subject: [PATCH] urls: Migrate dev urls to use modern django patterns. --- zerver/lib/test_helpers.py | 8 ++-- zproject/dev_urls.py | 82 +++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py index 492f7eaa9a..dd41b4f56d 100644 --- a/zerver/lib/test_helpers.py +++ b/zerver/lib/test_helpers.py @@ -419,10 +419,10 @@ def write_instrumentation_reports(full_suite: bool, include_webhooks: bool) -> N # We also exempt some development environment debugging # static content URLs, since the content they point to may # or may not exist. - 'coverage/(?P.*)', - 'node-coverage/(?P.*)', - 'docs/(?P.*)', - 'casper/(?P.*)', + 'coverage/(?P.+)', + 'node-coverage/(?P.+)', + 'docs/(?P.+)', + 'casper/(?P.+)', 'static/(?P.*)', ] + [webhook.url for webhook in WEBHOOK_INTEGRATIONS if not include_webhooks]) diff --git a/zproject/dev_urls.py b/zproject/dev_urls.py index 2b0ea06b62..03aae63101 100644 --- a/zproject/dev_urls.py +++ b/zproject/dev_urls.py @@ -2,10 +2,10 @@ import os from urllib.parse import urlsplit from django.conf import settings -from django.conf.urls import url from django.conf.urls.static import static from django.contrib.staticfiles.views import serve as staticfiles_serve from django.http import HttpRequest, HttpResponse +from django.urls import path, re_path from django.views.generic import TemplateView from django.views.static import serve @@ -20,59 +20,59 @@ use_prod_static = not settings.DEBUG urls = [ # Serve useful development environment resources (docs, coverage reports, etc.) - url(r'^coverage/(?P.*)$', - serve, {'document_root': - os.path.join(settings.DEPLOY_ROOT, 'var/coverage'), - 'show_indexes': True}), - url(r'^node-coverage/(?P.*)$', - serve, {'document_root': - os.path.join(settings.DEPLOY_ROOT, 'var/node-coverage/lcov-report'), - 'show_indexes': True}), - url(r'^casper/(?P.*)$', - serve, {'document_root': - os.path.join(settings.DEPLOY_ROOT, 'var/casper'), - 'show_indexes': True}), - url(r'^docs/(?P.*)$', - serve, {'document_root': - os.path.join(settings.DEPLOY_ROOT, 'docs/_build/html')}), + path('coverage/', + serve, {'document_root': + os.path.join(settings.DEPLOY_ROOT, 'var/coverage'), + 'show_indexes': True}), + path('node-coverage/', + serve, {'document_root': + os.path.join(settings.DEPLOY_ROOT, 'var/node-coverage/lcov-report'), + 'show_indexes': True}), + path('casper/', + serve, {'document_root': + os.path.join(settings.DEPLOY_ROOT, 'var/casper'), + 'show_indexes': True}), + path('docs/', + serve, {'document_root': + os.path.join(settings.DEPLOY_ROOT, 'docs/_build/html')}), # The special no-password login endpoint for development - url(r'^devlogin/$', zerver.views.auth.login_page, - {'template_name': 'zerver/dev_login.html'}, name='zerver.views.auth.login_page'), + path('devlogin/', zerver.views.auth.login_page, + {'template_name': 'zerver/dev_login.html'}, name='zerver.views.auth.login_page'), # Page for testing email templates - url(r'^emails/$', zerver.views.development.email_log.email_page), - url(r'^emails/generate/$', zerver.views.development.email_log.generate_all_emails), - url(r'^emails/clear/$', zerver.views.development.email_log.clear_emails), + path('emails/', zerver.views.development.email_log.email_page), + path('emails/generate/', zerver.views.development.email_log.generate_all_emails), + path('emails/clear/', zerver.views.development.email_log.clear_emails), # Listing of useful URLs and various tools for development - url(r'^devtools/$', TemplateView.as_view(template_name='zerver/dev_tools.html')), + path('devtools/', TemplateView.as_view(template_name='zerver/dev_tools.html')), # Register New User and Realm - url(r'^devtools/register_user/$', - zerver.views.development.registration.register_development_user, - name='zerver.views.development.registration.register_development_user'), - url(r'^devtools/register_realm/$', - zerver.views.development.registration.register_development_realm, - name='zerver.views.development.registration.register_development_realm'), + path('devtools/register_user/', + zerver.views.development.registration.register_development_user, + name='zerver.views.development.registration.register_development_user'), + path('devtools/register_realm/', + zerver.views.development.registration.register_development_realm, + name='zerver.views.development.registration.register_development_realm'), # Have easy access for error pages - url(r'^errors/404/$', TemplateView.as_view(template_name='404.html')), - url(r'^errors/5xx/$', TemplateView.as_view(template_name='500.html')), + path('errors/404/', TemplateView.as_view(template_name='404.html')), + path('errors/5xx/', TemplateView.as_view(template_name='500.html')), # Add a convenient way to generate webhook messages from fixtures. - url(r'^devtools/integrations/$', zerver.views.development.integrations.dev_panel), - url(r'^devtools/integrations/check_send_webhook_fixture_message$', - zerver.views.development.integrations.check_send_webhook_fixture_message), - url(r'^devtools/integrations/send_all_webhook_fixture_messages$', - zerver.views.development.integrations.send_all_webhook_fixture_messages), - url(r'^devtools/integrations/(?P.+)/fixtures$', - zerver.views.development.integrations.get_fixtures), + path('devtools/integrations/', zerver.views.development.integrations.dev_panel), + path('devtools/integrations/check_send_webhook_fixture_message', + zerver.views.development.integrations.check_send_webhook_fixture_message), + path('devtools/integrations/send_all_webhook_fixture_messages', + zerver.views.development.integrations.send_all_webhook_fixture_messages), + path('devtools/integrations//fixtures', + zerver.views.development.integrations.get_fixtures), ] # Serve static assets via the Django server if use_prod_static: urls += [ - url(r'^static/(?P.*)$', serve, {'document_root': settings.STATIC_ROOT}), + re_path(r'^static/(?P.*)$', serve, {'document_root': settings.STATIC_ROOT}), ] else: def serve_static(request: HttpRequest, path: str) -> HttpResponse: @@ -83,12 +83,12 @@ else: urls += static(urlsplit(settings.STATIC_URL).path, view=serve_static) i18n_urls = [ - url(r'^confirmation_key/$', zerver.views.development.registration.confirmation_key), + path('confirmation_key/', zerver.views.development.registration.confirmation_key), ] # On a production instance, these files would be served by nginx. if settings.LOCAL_UPLOADS_DIR is not None: urls += [ - url(r'^user_avatars/(?P.*)$', serve, - {'document_root': os.path.join(settings.LOCAL_UPLOADS_DIR, "avatars")}), + re_path(r'^user_avatars/(?P.*)$', serve, + {'document_root': os.path.join(settings.LOCAL_UPLOADS_DIR, "avatars")}), ]