diff --git a/website/common/middleware.py b/website/common/middleware.py new file mode 100644 index 0000000..cb79f93 --- /dev/null +++ b/website/common/middleware.py @@ -0,0 +1,9 @@ +from django_minify_html.middleware import MinifyHtmlMiddleware + + +class CustomMinifyHtmlMiddleware(MinifyHtmlMiddleware): + minify_args = { + "do_not_minify_doctype": True, + "ensure_spec_compliant_unquoted_attribute_values": True, + "keep_spaces_between_attributes": True, + } diff --git a/website/search/tests.py b/website/search/tests.py index 15c474c..b6acbbb 100644 --- a/website/search/tests.py +++ b/website/search/tests.py @@ -38,7 +38,7 @@ class SearchPageTestCase(TestCase): self.assertEqual(search_input.attrs["name"], "q") self.assertEqual(search_input.attrs["hx-get"], "results/") - self.assertEqual(search_input.attrs.get("value", ""), "") + self.assertNotIn("value", search_input.attrs) # Because of minify-html self.assertEqual(len(soup.select(search_input.attrs["hx-target"])), 1) self.assertEqual(len(soup.select(search_input.attrs["hx-indicator"])), 2) diff --git a/website/settings.py b/website/settings.py index e424730..d36b665 100644 --- a/website/settings.py +++ b/website/settings.py @@ -100,7 +100,7 @@ MIDDLEWARE = [ "corsheaders.middleware.CorsMiddleware", "enforce_host.EnforceHostMiddleware", "whitenoise.middleware.WhiteNoiseMiddleware", - "django_minify_html.middleware.MinifyHtmlMiddleware", + "website.common.middleware.CustomMinifyHtmlMiddleware", "django.middleware.common.CommonMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.csrf.CsrfViewMiddleware",