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 from datetime import datetime, date
class vzhled: class vzhled:

2
mamweb/settings_common.py

@ -65,7 +65,6 @@ MIDDLEWARE_CLASSES = (
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'mamweb.middleware.vzhled',
) )
TEMPLATE_CONTEXT_PROCESSORS = ( TEMPLATE_CONTEXT_PROCESSORS = (
@ -79,6 +78,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.tz', 'django.core.context_processors.tz',
'sekizai.context_processors.sekizai', 'sekizai.context_processors.sekizai',
'django.core.context_processors.static', 'django.core.context_processors.static',
'mamweb.context_processors.vzhled',
) )
INSTALLED_APPS = ( INSTALLED_APPS = (

2
mamweb/templates/base.html

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

3
mamweb/templates/flatpages/default.html

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

Loading…
Cancel
Save