From 27c8c8f10be9383914a621b14fd31c12b4064baa Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 25 Nov 2015 21:11:52 +0000 Subject: [PATCH] Added better custom template --- project/common/views.py | 19 +++++++++---------- project/pages/views.py | 15 ++++++++------- templates/about/website.html | 4 ---- templates/base.html | 4 ++-- templates/content_base.html | 4 ---- templates/index.html | 2 -- 6 files changed, 19 insertions(+), 29 deletions(-) diff --git a/project/common/views.py b/project/common/views.py index b382523..8ff6ea1 100644 --- a/project/common/views.py +++ b/project/common/views.py @@ -1,13 +1,12 @@ from django.views.generic import TemplateView -class CustomHeaderBG(): - """Allow custom header background""" - - class Template(TemplateView): - header_BG = "" - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context['header_BG'] = self.header_BG - return context +class CustomTemplate(TemplateView): + html_title = "" + body_class = "" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['html_title'] = self.html_title + context['body_class'] = self.body_class + return context diff --git a/project/pages/views.py b/project/pages/views.py index 1842fa8..66b45f2 100644 --- a/project/pages/views.py +++ b/project/pages/views.py @@ -1,13 +1,14 @@ -from django.views.generic import TemplateView -from project.common.views import CustomHeaderBG +from project.common.views import CustomTemplate from django.contrib.staticfiles.templatetags.staticfiles import static -class IndexView(TemplateView): +class IndexView(CustomTemplate): template_name = 'index.html' + html_title = "Homepage" + body_class = "index" -class NoJavascriptView(TemplateView): +class NoJavascriptView(CustomTemplate): template_name = 'core/no-js.html' def get_context_data(self, **kwargs): @@ -16,7 +17,7 @@ class NoJavascriptView(TemplateView): return context -class Custom404View(CustomHeaderBG.Template): +class Custom404View(CustomTemplate): template_name = 'core/404.html' def get(self, request, *args, **kwargs): @@ -24,9 +25,9 @@ class Custom404View(CustomHeaderBG.Template): return self.render_to_response(context, status=404) -class AboutWebsiteView(CustomHeaderBG.Template): +class AboutWebsiteView(CustomTemplate): template_name = 'about/website.html' -class AboutIndexView(TemplateView): +class AboutIndexView(CustomTemplate): template_name = 'about/index.html' diff --git a/templates/about/website.html b/templates/about/website.html index bce7cc6..b25728e 100644 --- a/templates/about/website.html +++ b/templates/about/website.html @@ -1,9 +1,5 @@ {% extends 'content_base.html' %} -{% block htmlTitle %}About the website{% endblock %} - -{% block bodyClass %}{% endblock %} - {% block pageTitle %}About my website{% endblock %} {% block content %} diff --git a/templates/base.html b/templates/base.html index b955b92..855209a 100644 --- a/templates/base.html +++ b/templates/base.html @@ -2,14 +2,14 @@ - {% block baseHtmlTitle %}{% endblock %} | TheOrangeOne + {{ html_title }} | TheOrangeOne - + {% block baseContent%}{% endblock %}