-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurls.py
128 lines (106 loc) · 4.38 KB
/
urls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from typing import TYPE_CHECKING, Union
from django.apps import apps
from django.conf import settings
from django.urls import include, path, re_path
from django.views.decorators.cache import never_cache
from django.views.decorators.vary import vary_on_headers
from django.views.generic import TemplateView
from wagtail import urls as wagtail_urls
from wagtail.contrib.sitemaps.views import sitemap
from wagtail.documents.views.serve import authenticate_with_password
from wagtail.utils.urlpatterns import decorate_urlpatterns
from cms.core import views as core_views
from cms.core.cache import get_default_cache_control_decorator
from cms.private_media import views as private_media_views
if TYPE_CHECKING:
from django.urls import URLPattern, URLResolver
# Internal URLs are not intended for public use.
internal_urlpatterns = [path("readiness/", core_views.ready, name="readiness")]
# Private URLs are not meant to be cached.
private_urlpatterns = [
path("-/", include((internal_urlpatterns, "internal"))),
path(
"documents/authenticate_with_password/<int:restriction_id>/",
authenticate_with_password,
name="wagtaildocs_authenticate_with_password",
),
]
# `wagtail.admin` must always be installed,
# so check `IS_EXTERNAL_ENV` directly.
if not settings.IS_EXTERNAL_ENV:
from wagtail.admin import urls as wagtailadmin_urls # pylint: disable=ungrouped-imports
private_urlpatterns.append(path("admin/", include(wagtailadmin_urls)))
if apps.is_installed("django.contrib.admin"):
from django.contrib import admin # pylint: disable=ungrouped-imports
private_urlpatterns.append(path("django-admin/", admin.site.urls))
# django-defender
if getattr(settings, "ENABLE_DJANGO_DEFENDER", False):
private_urlpatterns += [
path("django-admin/defender/", include("defender.urls")),
]
debug_urlpatterns: list[Union["URLResolver", "URLPattern"]] = []
if settings.DEBUG:
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# Serve static and media files from development server
debug_urlpatterns += staticfiles_urlpatterns()
debug_urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
debug_urlpatterns += [
# Add views for testing 404 and 500 templates
path(
"test404/",
TemplateView.as_view(template_name="templates/pages/errors/404.html"),
),
path(
"test403/",
TemplateView.as_view(template_name="templates/pages/errors/403.html"),
),
path(
"test500/",
TemplateView.as_view(template_name="templates/pages/errors/500.html"),
),
]
# Try to install the django debug toolbar, if exists
if apps.is_installed("debug_toolbar"):
import debug_toolbar
debug_urlpatterns = [path("__debug__/", include(debug_toolbar.urls)), *debug_urlpatterns]
# Public URLs that are meant to be cached.
urlpatterns = [
path("sitemap.xml", sitemap),
]
# Set public URLs to use the "default" cache settings.
urlpatterns = decorate_urlpatterns(urlpatterns, get_default_cache_control_decorator())
# Set private URLs to use the "never cache" cache settings.
private_urlpatterns = decorate_urlpatterns(private_urlpatterns, never_cache)
# Set vary header to instruct cache to serve different version on different
# cookies, different request method (e.g. AJAX) and different protocol
# (http vs https).
urlpatterns = decorate_urlpatterns(
urlpatterns,
vary_on_headers("Cookie", "X-Requested-With", "X-Forwarded-Proto", "Accept-Encoding"),
)
# Join private and public URLs.
urlpatterns = (
private_urlpatterns
+ debug_urlpatterns
+ urlpatterns
+ [
re_path(
r"^documents/(\d+)/(.*)$",
private_media_views.DocumentServeView.as_view(),
name="wagtaildocs_serve",
),
re_path(
r"^images/([^/]*)/(\d*)/([^/]*)/[^/]*$",
private_media_views.ImageServeView.as_view(),
name="wagtailimages_serve",
),
# Add Wagtail URLs at the end.
# Wagtail cache-control is set on the page models' serve methods
path("", include(wagtail_urls)),
]
)
# Error handlers
handler404 = "cms.core.views.page_not_found"
handler500 = "cms.core.views.server_error"
# CSRF errors also have their own views - see the `CSRF_FAILURE_VIEW` Django setting