1
Fork 0

Add view name to template for nicer styling

This commit is contained in:
Jake Howard 2020-04-13 12:50:08 +01:00
parent f3ab567e47
commit 27298cd707
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 12 additions and 2 deletions

View file

@ -14,7 +14,7 @@
<link rel="stylesheet" href="{% static 'css/font-awesome.min.css' %}" /> <link rel="stylesheet" href="{% static 'css/font-awesome.min.css' %}" />
<link rel="stylesheet" href="{% static 'css/index.css' %}" /> <link rel="stylesheet" href="{% static 'css/index.css' %}" />
</head> </head>
<body> <body class="{{ view_name }}">
<header id="top"> <header id="top">
<nav> <nav>

View file

@ -1,5 +1,10 @@
from django.conf import settings from django.conf import settings
from django.utils.text import slugify
def settings_injector(request=None): def settings_injector(request):
return {"settings": settings} return {"settings": settings}
def view_name(request):
return {"view_name": slugify(request.resolver_match.func.__name__)}

View file

@ -10,3 +10,7 @@ class HomepageViewTestCase(BaseTestCase):
def test_accessible(self): def test_accessible(self):
response = self.client.get(reverse("homepage")) response = self.client.get(reverse("homepage"))
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
def test_contains_view_name(self):
response = self.client.get(reverse("homepage"))
self.assertContains(response, '<body class="homepageview">')

View file

@ -62,6 +62,7 @@ TEMPLATES = [
"django.template.context_processors.debug", "django.template.context_processors.debug",
"django.template.context_processors.request", "django.template.context_processors.request",
"website.common.context_processors.settings_injector", "website.common.context_processors.settings_injector",
"website.common.context_processors.view_name",
], ],
}, },
}, },