From b86685b3bbdc5fe9aaa4cc13d97943e0f3ed912c Mon Sep 17 00:00:00 2001 From: "Bc. Petr Pecha" Date: Wed, 23 Sep 2015 16:15:17 +0200 Subject: [PATCH] Noc | nocni tema Nakonec pouzit context_processor, ktery je k tomu urceny. Prida do contextu promenou noc tak, ze pokud je mezi 20. hodinou vecerni a 7. hodinou ranni, pak je noc True. Kdyz je noc True, pak se v base templeatu prida do header class prepona NOC. CSS-ko vuci tomu upraveno --- mamweb/context_processors.py | 12 ++++++++++++ mamweb/middleware.py | 1 + mamweb/settings_common.py | 2 +- mamweb/templates/base.html | 2 +- mamweb/templates/flatpages/default.html | 3 --- 5 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 mamweb/context_processors.py diff --git a/mamweb/context_processors.py b/mamweb/context_processors.py new file mode 100644 index 00000000..ec6481df --- /dev/null +++ b/mamweb/context_processors.py @@ -0,0 +1,12 @@ + +from datetime import datetime, date + +def vzhled(request): + ''' Podle casu prida do templatu, zdali je nebo neni noc ''' + hodin = datetime.now().hour + if (hodin <= 6) or (hodin >= 20): + noc = True + else: + noc = False + return {'noc' : noc} + diff --git a/mamweb/middleware.py b/mamweb/middleware.py index 58d7584a..1bc0b4fa 100644 --- a/mamweb/middleware.py +++ b/mamweb/middleware.py @@ -1,4 +1,5 @@ +from django.http import HttpResponse from datetime import datetime, date class vzhled: diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index 0696c212..345bbc3b 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -65,7 +65,6 @@ MIDDLEWARE_CLASSES = ( 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', - 'mamweb.middleware.vzhled', ) TEMPLATE_CONTEXT_PROCESSORS = ( @@ -79,6 +78,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.tz', 'sekizai.context_processors.sekizai', 'django.core.context_processors.static', + 'mamweb.context_processors.vzhled', ) INSTALLED_APPS = ( diff --git a/mamweb/templates/base.html b/mamweb/templates/base.html index 54e0f19c..a97d5168 100644 --- a/mamweb/templates/base.html +++ b/mamweb/templates/base.html @@ -48,7 +48,7 @@