Created
October 10, 2023 23:23
-
-
Save cnk/c86954340bb7aafda3089e18a61dd34a to your computer and use it in GitHub Desktop.
Overriding the ETAG decorator for wagtail document's serve method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################################################ | |
# Replace the wagtaildocs serve() view to change the cache-control header that it returns. | |
# This prevents any cache besides the user's own browser from storing any potentially confidential document. | |
################################################################################################################ | |
multitenant_document_serve = etag(document_etag)(cache_control(max_age=3600, private=True)(serve.__wrapped__)) | |
patched_wagtail_urlpatterns = [ | |
# This overrides the wagtaildocs_serve view. | |
re_path(r'^documents/(\d+)/(.*)$', multitenant_document_serve), | |
] | |
#### and then in our urls.py file, we prepend the normal patterns with the patch list | |
# We override several /admin/* URLs with our own custom views, which are defined in patched_wagtail_urlpatterns. | |
urlpatterns = patched_wagtail_urlpatterns + [ | |
# Serve the usual django admin interface from /django-admin/, because Wagtail takes /admin/. | |
path('django-admin/', include(django_admin.site.urls[:2], namespace=django_admin.site.name)), | |
# We now include wagtails' own admin URLs. | |
path('admin/', include('wagtail.admin.urls')), | |
# These are the URLs Wagtail serves documents from. | |
path('documents/', include('wagtail.documents.urls')), | |
# Public URLs for our custom apps. | |
# etc | |
] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment