view apps/lib/templatetags/theme.py @ 1363:f75ca7dfb4f0
fix py2.4 compat
| author |
Alexander Solovyov <piranha@piranha.org.ua> |
| date |
Wed Feb 03 11:48:39 2010 +0200 (5 weeks ago) |
| parents |
c77e2bcea832 |
| children |
|
line source
1 # -*- mode: python; coding: utf-8; -*-
3 from time import localtime, strftime
4 from os.path import join, exists, isdir, getmtime
6 from django.template import Library
7 from django.conf import settings
10 time = localtime(getmtime(filename))
11 return strftime('%Y%m%d%H%M', time)
13 def theme_static(kind, filename):
14 file = '%s.%s' % (filename, kind)
15 candidates = [[settings.THEME_STATIC_URL, settings.THEME_STATIC_ROOT, kind, file],
16 [settings.STATIC_URL, settings.STATIC_ROOT, settings.THEME, kind, file],
17 [settings.STATIC_URL, settings.STATIC_ROOT, kind, file]]
19 for candidate in candidates:
20 full_path = join(*candidate[1:])
21 if exists(full_path) and not isdir(full_path):
22 url = '/'.join(candidate[2:])
23 if settings.APPEND_MTIME_TO_STATIC:
24 url = '%s?%s' % (url, gettime(full_path))
25 return {'STATIC_URL': candidate[0], 'include': True, 'url': url}
27 return {'include': False}
31 @register.inclusion_tag('templatetags/css.html')
32 def theme_css(filename='main'):
33 return theme_static('css', filename)
35 @register.inclusion_tag('templatetags/js.html')
36 def theme_js(filename='main'):
37 return theme_static('js', filename)