1 from django import template
2 from django.core.cache import cache
3 from django.utils.safestring import mark_safe
4 from django.utils.translation import get_language
5 from ..models import Chunk, Attachment
8 register = template.Library()
12 def chunk(key, cache_time=0):
14 cache_key = 'chunk:%s:%s' % (key, get_language())
15 c = cache.get(cache_key)
17 c = Chunk.objects.get(key=key)
18 cache.set(cache_key, c, int(cache_time))
20 except Chunk.DoesNotExist:
24 return mark_safe(content)
28 def attachment(key, cache_time=0):
30 cache_key = 'attachment_' + key
31 c = cache.get(cache_key)
33 c = Attachment.objects.get(key=key)
34 cache.set(cache_key, c, int(cache_time))
35 return c.attachment.url
36 except Attachment.DoesNotExist: