Browse Source

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
remotes/origin/noc
Bc. Petr Pecha 9 years ago
parent
commit
b86685b3bb
  1. 12
      mamweb/context_processors.py
  2. 1
      mamweb/middleware.py
  3. 2
      mamweb/settings_common.py
  4. 2
      mamweb/templates/base.html
  5. 3
      mamweb/templates/flatpages/default.html

12
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}

1
mamweb/middleware.py

@ -1,4 +1,5 @@
from django.http import HttpResponse
from datetime import datetime, date
class vzhled:

2
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 = (

2
mamweb/templates/base.html

@ -48,7 +48,7 @@
<div class='row'>
<div class='col-md-12'>
<a href='/'>
<div id="header" class="{% block noc %}{% if noc %}NOC{% endif %}{% endblock %}{% block header %}{% endblock %}">
<div id="header" class="{% if noc %}NOC{% endif %}{% block header %}{% endblock %}">
<img class="logo" src="{% static 'images/logo.png' %}" />
<!--<h1>{% block nadpis1b %}Nadpis 1. úrovně{% endblock %}</h1>-->
</div>

3
mamweb/templates/flatpages/default.html

@ -4,10 +4,7 @@
{{ flatpage.title }}
{% endblock %}{% endblock %}
{% block noc %}{% if flatpage.noc %}NOC{% endif %}{% endblock noc %}
{% block content %}
<div>
{{ flatpage.content }}
</div>

Loading…
Cancel
Save