diff --git a/.env.example b/.env.example index a754e4d65..f9ae34ada 100644 --- a/.env.example +++ b/.env.example @@ -104,3 +104,9 @@ FEEDBACK_NOTIFICATION_EMAIL_RECIPIENTS="marcel.kornblum@digital.trade.gov.uk," SEARCH_SHOW_INACTIVE_PROFILES_WITHIN_DAYS=90 # Manage apllication caching SEARCH_ENABLE_QUERY_CACHE=False + +# Django Silk +SILK_ENABLED=False + +# Django Debug Toolbar +DDT_ENABLED=False \ No newline at end of file diff --git a/assets/js/application.js b/assets/js/application.js index 9a29ac63e..d62a37b9d 100644 --- a/assets/js/application.js +++ b/assets/js/application.js @@ -7,8 +7,16 @@ require.context("govuk-frontend/govuk/assets"); require.context( "@ministryofjustice/frontend/moj/assets" ); -import {initAll} from "govuk-frontend"; +import { initAll } from "govuk-frontend"; import mojFrontend from "@ministryofjustice/frontend"; initAll(); mojFrontend.initAll(); + +if (typeof window.djdt !== "undefined" && typeof window.htmx !== "undefined") { + htmx.on("htmx:afterSettle", function (detail) { + if (detail.target instanceof HTMLBodyElement) { + djdt.show_toolbar(); + } + }); +} \ No newline at end of file diff --git a/poetry.lock b/poetry.lock index 1c7740277..b754e100e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1082,6 +1082,21 @@ Django = ">=3.2" jinja2 = ["jinja2 (>=2.9.6)"] tests = ["jinja2 (>=2.9.6)", "pytest", "pytest-cov", "pytest-django", "pytest-ruff"] +[[package]] +name = "django-debug-toolbar" +version = "4.4.6" +description = "A configurable set of panels that display various debug information about the current request/response." +optional = false +python-versions = ">=3.8" +files = [ + {file = "django_debug_toolbar-4.4.6-py3-none-any.whl", hash = "sha256:3beb671c9ec44ffb817fad2780667f172bd1c067dbcabad6268ce39a81335f45"}, + {file = "django_debug_toolbar-4.4.6.tar.gz", hash = "sha256:36e421cb908c2f0675e07f9f41e3d1d8618dc386392ec82d23bcfcd5d29c7044"}, +] + +[package.dependencies] +django = ">=4.2.9" +sqlparse = ">=0.2" + [[package]] name = "django-elasticsearch-dsl" version = "7.4" @@ -1818,7 +1833,7 @@ files = [ {file = "greenlet-3.0.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:0b72b802496cccbd9b31acea72b6f87e7771ccfd7f7927437d592e5c92ed703c"}, {file = "greenlet-3.0.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:527cd90ba3d8d7ae7dceb06fda619895768a46a1b4e423bdb24c1969823b8362"}, {file = "greenlet-3.0.0-cp311-cp311-win_amd64.whl", hash = "sha256:37f60b3a42d8b5499be910d1267b24355c495064f271cfe74bf28b17b099133c"}, - {file = "greenlet-3.0.0-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:1482fba7fbed96ea7842b5a7fc11d61727e8be75a077e603e8ab49d24e234383"}, + {file = "greenlet-3.0.0-cp311-universal2-macosx_10_9_universal2.whl", hash = "sha256:c3692ecf3fe754c8c0f2c95ff19626584459eab110eaab66413b1e7425cd84e9"}, {file = "greenlet-3.0.0-cp312-cp312-macosx_13_0_arm64.whl", hash = "sha256:be557119bf467d37a8099d91fbf11b2de5eb1fd5fc5b91598407574848dc910f"}, {file = "greenlet-3.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:73b2f1922a39d5d59cc0e597987300df3396b148a9bd10b76a058a2f2772fc04"}, {file = "greenlet-3.0.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d1e22c22f7826096ad503e9bb681b05b8c1f5a8138469b255eb91f26a76634f2"}, @@ -1828,6 +1843,7 @@ files = [ {file = "greenlet-3.0.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:952256c2bc5b4ee8df8dfc54fc4de330970bf5d79253c863fb5e6761f00dda35"}, {file = "greenlet-3.0.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:269d06fa0f9624455ce08ae0179430eea61085e3cf6457f05982b37fd2cefe17"}, {file = "greenlet-3.0.0-cp312-cp312-win_amd64.whl", hash = "sha256:9adbd8ecf097e34ada8efde9b6fec4dd2a903b1e98037adf72d12993a1c80b51"}, + {file = "greenlet-3.0.0-cp312-universal2-macosx_10_9_universal2.whl", hash = "sha256:553d6fb2324e7f4f0899e5ad2c427a4579ed4873f42124beba763f16032959af"}, {file = "greenlet-3.0.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c6b5ce7f40f0e2f8b88c28e6691ca6806814157ff05e794cdd161be928550f4c"}, {file = "greenlet-3.0.0-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ecf94aa539e97a8411b5ea52fc6ccd8371be9550c4041011a091eb8b3ca1d810"}, {file = "greenlet-3.0.0-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:80dcd3c938cbcac986c5c92779db8e8ce51a89a849c135172c88ecbdc8c056b7"}, @@ -2253,16 +2269,6 @@ files = [ {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:5bbe06f8eeafd38e5d0a4894ffec89378b6c6a625ff57e3028921f8ff59318ac"}, {file = "MarkupSafe-2.1.3-cp311-cp311-win32.whl", hash = "sha256:dd15ff04ffd7e05ffcb7fe79f1b98041b8ea30ae9234aed2a9168b5797c3effb"}, {file = "MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl", hash = "sha256:134da1eca9ec0ae528110ccc9e48041e0828d79f24121a1a146161103c76e686"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f698de3fd0c4e6972b92290a45bd9b1536bffe8c6759c62471efaa8acb4c37bc"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aa57bd9cf8ae831a362185ee444e15a93ecb2e344c8e52e4d721ea3ab6ef1823"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:47d4f1c5f80fc62fdd7777d0d40a2e9dda0a05883ab11374334f6c4de38adffd"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1f67c7038d560d92149c060157d623c542173016c4babc0c1913cca0564b9939"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9aad3c1755095ce347e26488214ef77e0485a3c34a50c5a5e2471dff60b9dd9c"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:14ff806850827afd6b07a5f32bd917fb7f45b046ba40c57abdb636674a8b559c"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8f9293864fe09b8149f0cc42ce56e3f0e54de883a9de90cd427f191c346eb2e1"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-win32.whl", hash = "sha256:715d3562f79d540f251b99ebd6d8baa547118974341db04f5ad06d5ea3eb8007"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-win_amd64.whl", hash = "sha256:1b8dd8c3fd14349433c79fa8abeb573a55fc0fdd769133baac1f5e07abf54aeb"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8e254ae696c88d98da6555f5ace2279cf7cd5b3f52be2b5cf97feafe883b58d2"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cb0932dc158471523c9637e807d9bfb93e06a95cbf010f1a38b98623b929ef2b"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9402b03f1a1b4dc4c19845e5c749e3ab82d5078d16a2a4c2cd2df62d57bb0707"}, @@ -2452,7 +2458,6 @@ optional = false python-versions = ">=3.6" files = [ {file = "mkdocs-redirects-1.2.1.tar.gz", hash = "sha256:9420066d70e2a6bb357adf86e67023dcdca1857f97f07c7fe450f8f1fb42f861"}, - {file = "mkdocs_redirects-1.2.1-py3-none-any.whl", hash = "sha256:497089f9e0219e7389304cffefccdfa1cac5ff9509f2cb706f4c9b221726dffb"}, ] [package.dependencies] @@ -3124,8 +3129,6 @@ files = [ {file = "psycopg2-2.9.9-cp310-cp310-win_amd64.whl", hash = "sha256:426f9f29bde126913a20a96ff8ce7d73fd8a216cfb323b1f04da402d452853c3"}, {file = "psycopg2-2.9.9-cp311-cp311-win32.whl", hash = "sha256:ade01303ccf7ae12c356a5e10911c9e1c51136003a9a1d92f7aa9d010fb98372"}, {file = "psycopg2-2.9.9-cp311-cp311-win_amd64.whl", hash = "sha256:121081ea2e76729acfb0673ff33755e8703d45e926e416cb59bae3a86c6a4981"}, - {file = "psycopg2-2.9.9-cp312-cp312-win32.whl", hash = "sha256:d735786acc7dd25815e89cc4ad529a43af779db2e25aa7c626de864127e5a024"}, - {file = "psycopg2-2.9.9-cp312-cp312-win_amd64.whl", hash = "sha256:a7653d00b732afb6fc597e29c50ad28087dcb4fbfb28e86092277a559ae4e693"}, {file = "psycopg2-2.9.9-cp37-cp37m-win32.whl", hash = "sha256:5e0d98cade4f0e0304d7d6f25bbfbc5bd186e07b38eac65379309c4ca3193efa"}, {file = "psycopg2-2.9.9-cp37-cp37m-win_amd64.whl", hash = "sha256:7e2dacf8b009a1c1e843b5213a87f7c544b2b042476ed7755be813eaf4e8347a"}, {file = "psycopg2-2.9.9-cp38-cp38-win32.whl", hash = "sha256:ff432630e510709564c01dafdbe996cb552e0b9f3f065eb89bdce5bd31fabf4c"}, @@ -3411,7 +3414,6 @@ files = [ {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, - {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, @@ -3419,16 +3421,8 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, - {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, - {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, - {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, - {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, @@ -3445,7 +3439,6 @@ files = [ {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, - {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, @@ -3453,7 +3446,6 @@ files = [ {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, - {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, @@ -4378,4 +4370,4 @@ test = ["big-O", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more-it [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "e25a3a72ed9456e845d8db00c5a09f0e15b9890a3d33236f855ef2c751236d36" +content-hash = "238237610c2522b289520a8a550f54e1765abd6db2d1c0e6a9a6d40e658f2f5d" diff --git a/pyproject.toml b/pyproject.toml index 46001635d..33f4790b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,12 +87,13 @@ wagtail-factories = "^4.0.0" # Util bpython = "^0.24" django-extensions = "^3.2.1" +django-silk = "^5.0.4" +django-debug-toolbar = "^4.4.6" werkzeug = "^3.0.6" blessings = "^1.7" pytest-mock = "^3.11.1" pytest-freezer = "^0.4.8" playwright = "^1.36" -django-silk = "^5.0.4" snakeviz = "^2.2.0" debugpy = "*" diff --git a/src/config/settings/developer.py b/src/config/settings/developer.py index af1290ad1..9e49fae51 100644 --- a/src/config/settings/developer.py +++ b/src/config/settings/developer.py @@ -18,7 +18,20 @@ "django.core.files.uploadhandler.TemporaryFileUploadHandler", ] -try: +# Enable Django Debug Toolbar +DDT_ENABLED = env.bool("DDT_ENABLED", False) # noqa F405 +if DDT_ENABLED: + INSTALLED_APPS += [ + "debug_toolbar", + ] + # Add the middleware to the top of the list. + MIDDLEWARE.insert(0, "debug_toolbar.middleware.DebugToolbarMiddleware") # noqa F405 + INTERNAL_IPS = [ + "127.0.0.1", + ] + +SILK_ENABLED = env.bool("SILK_ENABLED", False) # noqa F405 +if SILK_ENABLED: # Add django-silk for profiling import silk # noqa F401 @@ -35,8 +48,6 @@ "profiler_results", ) SILKY_META = True -except ModuleNotFoundError: - ... DEV_TOOLS_ENABLED = env.bool("DEV_TOOLS_ENABLED", True) # noqa F405 diff --git a/src/config/urls.py b/src/config/urls.py index d81f2a4f5..076978ecb 100644 --- a/src/config/urls.py +++ b/src/config/urls.py @@ -74,12 +74,18 @@ urlpatterns += [ path("dev-tools/", include("dev_tools.urls", namespace="dev_tools")) ] + if "debug_toolbar" in settings.INSTALLED_APPS: + # Django Debug Toolbar purposefully only active with DEBUG=True + from debug_toolbar.toolbar import debug_toolbar_urls + + urlpatterns += debug_toolbar_urls() urlpatterns += [ # Wagtail path("", include(wagtail_urls)), ] + # Removed until we find a fix for Wagtail's redirect behaviour handler404 = "core.views.view_404" handler500 = "core.views.view_500" diff --git a/src/content/models.py b/src/content/models.py index f71c68cb9..eeb6ad5fc 100644 --- a/src/content/models.py +++ b/src/content/models.py @@ -12,8 +12,6 @@ from django.utils.html import strip_tags from simple_history.models import HistoricalRecords from wagtail.admin.panels import ( - FieldPanel, - InlinePanel, ObjectList, TabbedInterface, TitleFieldPanel, @@ -33,6 +31,7 @@ truncate_words_and_chars, ) from content.validators import validate_description_word_count +from core.panels import FieldPanel, InlinePanel from extended_search.index import DWIndexedField as IndexedField from extended_search.index import Indexed, RelatedFields from peoplefinder.widgets import PersonChooser diff --git a/src/core/panels.py b/src/core/panels.py index 29ae25be6..e223a3d6a 100644 --- a/src/core/panels.py +++ b/src/core/panels.py @@ -1,4 +1,4 @@ -from wagtail.admin.panels import PageChooserPanel +from wagtail.admin.panels import FieldPanel, InlinePanel, PageChooserPanel from core.widgets import ReadOnlyPageInput @@ -9,3 +9,19 @@ def __init__(self, **kwargs): super().__init__(**kwargs) if self.instance and self.instance.pk: self.bound_field.field.widget = ReadOnlyPageInput() + + +class FieldPanel(FieldPanel): + class BoundPanel(FieldPanel.BoundPanel): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + if not self.bound_field.field.required: + self.heading += " (optional)" + + +class InlinePanel(InlinePanel): + class BoundPanel(InlinePanel.BoundPanel): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + if self.panel.min_num is None or self.panel.min_num == 0: + self.heading += " (optional)" diff --git a/src/country_fact_sheet/models.py b/src/country_fact_sheet/models.py index 4e02c0964..0618e83ce 100644 --- a/src/country_fact_sheet/models.py +++ b/src/country_fact_sheet/models.py @@ -2,10 +2,11 @@ from django.contrib.auth import get_user_model from django.db import models -from wagtail.admin.panels import FieldPanel, MultiFieldPanel +from wagtail.admin.panels import MultiFieldPanel from wagtail.documents.models import Document from content.models import ContentPage +from core.panels import FieldPanel UserModel = get_user_model() diff --git a/src/events/models.py b/src/events/models.py index 302594f37..4b7e94fab 100644 --- a/src/events/models.py +++ b/src/events/models.py @@ -6,11 +6,12 @@ from django.shortcuts import redirect from django.template.response import TemplateResponse from django.utils import timezone -from wagtail.admin.panels import FieldPanel, FieldRowPanel, MultiFieldPanel +from wagtail.admin.panels import FieldRowPanel, MultiFieldPanel from wagtail.contrib.routable_page.models import RoutablePageMixin, route from content.models import BasePage, ContentPage from core.models import fields +from core.panels import FieldPanel from events import types from events.utils import get_event_datetime_display_string diff --git a/src/home/models.py b/src/home/models.py index 41548d92e..fe48b4d30 100644 --- a/src/home/models.py +++ b/src/home/models.py @@ -11,8 +11,6 @@ from modelcluster.fields import ParentalKey from modelcluster.models import ClusterableModel from wagtail.admin.panels import ( - FieldPanel, - InlinePanel, MultiFieldPanel, ) from wagtail.models import PagePermissionTester @@ -23,7 +21,7 @@ from content.models import BasePage, ContentPage from core.models import fields from core.models.models import SiteAlertBanner -from core.panels import PageSelectorPanel +from core.panels import FieldPanel, InlinePanel, PageSelectorPanel from events.models import EventPage from home.forms import HomePageForm from home.validators import validate_home_priority_pages diff --git a/src/networks/models.py b/src/networks/models.py index 176fed221..9cd940808 100644 --- a/src/networks/models.py +++ b/src/networks/models.py @@ -1,9 +1,9 @@ from django import forms from wagtail.admin.forms import WagtailAdminPageForm -from wagtail.admin.panels import FieldPanel import peoplefinder.models as pf_models from content.models import ContentOwnerMixin, ContentPage +from core.panels import FieldPanel from extended_search.index import DWIndexedField as IndexedField diff --git a/src/news/models.py b/src/news/models.py index ba34272c0..e53ecfe71 100644 --- a/src/news/models.py +++ b/src/news/models.py @@ -7,11 +7,11 @@ from django.utils.text import slugify from modelcluster.fields import ParentalKey from simple_history.models import HistoricalRecords -from wagtail.admin.panels import FieldPanel, InlinePanel from wagtail.contrib.routable_page.models import RoutablePageMixin, route from wagtail.snippets.models import register_snippet from content.models import BasePage +from core.panels import FieldPanel, InlinePanel from extended_search.index import DWIndexedField as IndexedField from extended_search.index import ScoreFunction from news.forms import CommentForm diff --git a/src/tools/models.py b/src/tools/models.py index 107a93e23..89c34adb4 100644 --- a/src/tools/models.py +++ b/src/tools/models.py @@ -2,10 +2,10 @@ from django.core.serializers.json import DjangoJSONEncoder from django.db import models from django.shortcuts import redirect -from wagtail.admin.panels import FieldPanel from content.models import ContentPage from core.models import fields +from core.panels import FieldPanel from extended_search.index import DWIndexedField as IndexedField from working_at_dit.models import PageWithTopics diff --git a/src/working_at_dit/models.py b/src/working_at_dit/models.py index f99223345..029a2a1f9 100644 --- a/src/working_at_dit/models.py +++ b/src/working_at_dit/models.py @@ -3,9 +3,9 @@ from django.db import models from django.db.models import Q from modelcluster.fields import ParentalKey -from wagtail.admin.panels import FieldPanel, InlinePanel from content.models import BasePage, ContentOwnerMixin, ContentPage, Theme +from core.panels import FieldPanel, InlinePanel from extended_search.index import DWIndexedField as IndexedField