view apps/lib/templatetags/theme.py @ 1368:c36944d45994
tagging: support for django 1.2
The tagging app really should be upgraded, but that currently breaks other
things, so for the time being, backport
http://code.google.com/p/django-tagging/source/detail?r=172 which is the fix for
http://code.google.com/p/django-tagging/issues/detail?id=233
| author |
Peter Nixon <listuser@peternixon.net> |
| date |
Wed May 19 18:13:12 2010 +0300 (2 months 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)