Compare commits

...

8 Commits

Author SHA1 Message Date
Jake Howard 8d724277b0
Add random button to listing pages 2024-05-09 19:42:33 +01:00
Jake Howard 7fcbbad885
Move gzipping to nginx
This means less time is spent in gunicorn, letting the workers process other requests sooner.
2024-05-04 23:19:43 +01:00
Jake Howard 514e609973
Change minify-html details to be more spec compliant 2024-05-04 23:07:35 +01:00
Jake Howard b89b9d0797
Update Django to 5.0.4 2024-05-04 22:05:10 +01:00
Jake Howard 413b3165e0
Update Wagtail to 5.2.5 2024-05-04 20:59:57 +01:00
Jake Howard 2779a3e97f
Fix arguments on `after_move_page` hook 2024-05-04 20:56:23 +01:00
Jake Howard ac2ba1ef17
Return when a colours error is found 2024-05-04 20:53:45 +01:00
Jake Howard 0f328aff0a
Minify HTML 2024-05-04 20:07:59 +01:00
11 changed files with 41 additions and 8 deletions

View File

@ -14,6 +14,9 @@ server {
gzip_static on;
gzip on;
gzip_vary on;
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Forwarded-For;
@ -39,6 +42,7 @@ server {
location / {
proxy_pass http://localhost:8080;
gzip_types *;
}
location /static {

View File

@ -1,5 +1,5 @@
Django==5.0.1
wagtail==5.2.2
Django==5.0.4
wagtail==5.2.5
django-environ==0.11.2
whitenoise[brotli]==6.6.0
Pygments==2.17.2
@ -28,6 +28,7 @@ django-permissions-policy==4.18.0
django-enforce-host==1.1.0
django-proxy==1.2.2
wagtail-lite-youtube-embed==0.1.0
django-minify-html==1.7.1
# DRF OpenAPI dependencies
uritemplate

View File

@ -1,7 +1,5 @@
{% extends "common/listing_page.html" %}
{% load wagtailroutablepage_tags %}
{% block hero_buttons %}
<a class="button is-radiusless" href="{{ page.tag_list_page_url }}" title="View tags"><i class="fas fa-tags" aria-hidden="true"></i></a>
{{ block.super }}

View File

@ -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,
}

View File

@ -295,6 +295,13 @@ class BaseListingPage(RoutablePageMixin, BaseContentPage):
def feed(self, request: HttpRequest) -> HttpResponse:
return redirect("feed", permanent=True)
@route(r"^random/$")
def random(self, request: HttpRequest) -> HttpResponse:
page = self.get_listing_pages().order_by("?").first()
if page is None:
return redirect(self.get_url(request=request), permanent=False)
return redirect(page.get_url(request=request), permanent=False)
class ListingPage(BaseListingPage):
pass

View File

@ -1,8 +1,10 @@
{% extends "common/content_page.html" %}
{% load wagtailadmin_tags %}
{% load wagtailadmin_tags wagtailroutablepage_tags %}
{% block hero_buttons %}
<a class="button is-radiusless" href="{% routablepageurl page 'random' %}" title="View random"><i class="fas fa-dice" aria-hidden="true"></i></a>
{% if listing_pages.has_previous %}
<a class="button is-radiusless" href="{% querystring page=listing_pages.previous_page_number %}" title="Previous page"><i class="fas fa-arrow-left" aria-hidden="true"></i></a>
{% endif %}

View File

@ -77,3 +77,12 @@ class ListingPageTestCase(TestCase):
self.assertEqual(
response.context["page"].get_meta_url(), self.page.full_url + "?page=2"
)
def test_random(self) -> None:
url = self.page.url + self.page.reverse_subpage("random")
with self.assertNumQueries(10):
response = self.client.get(url)
self.assertEqual(response.status_code, 302)
self.assertIn(
response.url, [page.get_url() for page in self.page.get_listing_pages()]
)

View File

@ -9,6 +9,7 @@ class GitHubLinguistHealthCheckBackend(BaseHealthCheckBackend):
colours = _get_linguist_colours()
except Exception as e:
self.add_error(str(e))
return
if colours is None:
self.add_error("No colours provided")

View File

@ -1,5 +1,6 @@
from django.core.cache import cache
from wagtail import hooks
from wagtail.models import Page
from website.common.utils import get_page_models
@ -7,7 +8,7 @@ from .utils import SingletonPageCache
@hooks.register("after_move_page")
def clear_singleton_url_cache(**kwargs: dict) -> None:
def clear_singleton_url_cache(page_to_move: Page) -> None:
"""
Clear all page caches, in case a parent has moved
"""

View File

@ -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["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)

View File

@ -79,6 +79,7 @@ INSTALLED_APPS = [
"wagtail_2fa",
"django_otp",
"django_otp.plugins.otp_totp",
"django_minify_html",
"health_check",
"health_check.db",
"health_check.cache",
@ -93,12 +94,12 @@ INSTALLED_APPS = [
]
MIDDLEWARE = [
"django.middleware.gzip.GZipMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"corsheaders.middleware.CorsMiddleware",
"enforce_host.EnforceHostMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"website.common.middleware.CustomMinifyHtmlMiddleware",
"django.middleware.common.CommonMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",