From 71c08f55687a57c6c9e0405b27279f65bd74b322 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 25 Jul 2022 19:30:47 +0100 Subject: [PATCH] Use class name rather than database name for body classes This avoids duplication and makes the classnames a bit shorter, and more sane. --- static/src/scss/_homepage.scss | 2 +- website/common/models.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/static/src/scss/_homepage.scss b/static/src/scss/_homepage.scss index 6d71195..1236cb1 100644 --- a/static/src/scss/_homepage.scss +++ b/static/src/scss/_homepage.scss @@ -1,4 +1,4 @@ -body.page-home-homepage { +body.page-homepage { main { background-repeat: no-repeat; background-size: cover; diff --git a/website/common/models.py b/website/common/models.py index 169e295..09a444e 100644 --- a/website/common/models.py +++ b/website/common/models.py @@ -4,6 +4,7 @@ from typing import Any, Optional from django.db import models from django.http.request import HttpRequest from django.utils.functional import cached_property, classproperty +from django.utils.text import slugify from wagtail.admin.panels import FieldPanel from wagtail.fields import StreamField from wagtail.images import get_image_model_string @@ -26,7 +27,7 @@ class BasePage(Page): @classproperty def body_class(cls) -> str: - return "page-" + cls._meta.db_table.replace("_", "-") + return "page-" + slugify(cls.__name__) def get_parent_pages(self) -> PageQuerySet: """