Web M&M
https://mam.matfyz.cz
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
![]()
9 years ago
|
|
||
|
from datetime import datetime, date
|
||
![]()
4 years ago
|
import random
|
||
|
|
||
|
from django.conf import settings
|
||
|
|
||
![]()
4 years ago
|
from header_fotky.models import FotkaUrlVazba
|
||
![]()
4 years ago
|
|
||
![]()
9 years ago
|
|
||
|
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
|
||
![]()
4 years ago
|
nedoba = 'den'
|
||
|
doba = 'noc'
|
||
![]()
9 years ago
|
else:
|
||
|
noc = False
|
||
![]()
4 years ago
|
nedoba = 'noc'
|
||
|
doba = 'den'
|
||
|
url = request.path
|
||
|
|
||
|
fotky = FotkaUrlVazba.objects.exclude(denni_doba=nedoba)
|
||
|
fotka = None
|
||
|
|
||
|
# TODO rychlejší patternmatch?
|
||
|
while (fotka is None) and (url != ''):
|
||
|
presne = fotky.filter(url__exact=url)
|
||
|
if presne.count() > 0:
|
||
|
presne_doba = presne.filter(denni_doba=doba)
|
||
|
if presne_doba.count() > 0:
|
||
|
fotka = random.choice(presne_doba).url_fotky()
|
||
|
else:
|
||
|
fotka = random.choice(presne).url_fotky()
|
||
|
|
||
|
url = url[:-1]
|
||
|
index = url.rfind('/')
|
||
|
if index != -1:
|
||
|
url = url[:index+1]
|
||
|
|
||
|
if fotka is None:
|
||
|
fotka = settings.STATIC_URL + "images/header/vikendovka.jpg"
|
||
|
|
||
|
return {'noc': noc, 'fotka': fotka}
|
||
![]()
9 years ago
|
|