Fix truncatewords and truncatewords_html for Django 1.6 support
This commit is contained in:
parent
71be0fedf6
commit
6cf2899472
|
@ -77,12 +77,22 @@ def time(value, arg=None):
|
|||
def truncatewords(value, length):
|
||||
# Jinja2 has it's own ``truncate`` filter that supports word
|
||||
# boundaries and more stuff, but cannot deal with HTML.
|
||||
from django.utils.text import truncate_words
|
||||
try:
|
||||
from django.utils.text import Truncator
|
||||
except ImportError:
|
||||
from django.utils.text import truncate_words # Django < 1.6
|
||||
else:
|
||||
truncate_words = lambda value, length: Truncator(value).words(length)
|
||||
return truncate_words(value, int(length))
|
||||
|
||||
@register.jinja2_filter(jinja2_only=True)
|
||||
def truncatewords_html(value, length):
|
||||
from django.utils.text import truncate_html_words
|
||||
try:
|
||||
from django.utils.text import Truncator
|
||||
except ImportError:
|
||||
from django.utils.text import truncate_html_words # Django < 1.6
|
||||
else:
|
||||
truncate_html_words = lambda value, length: Truncator(value).words(length, html=True)
|
||||
return truncate_html_words(value, int(length))
|
||||
|
||||
@register.jinja2_filter(jinja2_only=True)
|
||||
|
|
|
@ -327,9 +327,9 @@ class CacheExtension(Extension):
|
|||
[], [], body).set_lineno(lineno)
|
||||
|
||||
def _cache_support(self, expire_time, fragm_name, vary_on, lineno, caller):
|
||||
from hashlib import md5
|
||||
from django.core.cache import cache # delay depending in settings
|
||||
from django.utils.http import urlquote
|
||||
from django.utils.hashcompat import md5_constructor
|
||||
|
||||
try:
|
||||
expire_time = int(expire_time)
|
||||
|
@ -338,7 +338,7 @@ class CacheExtension(Extension):
|
|||
'value: %r' % (list(self.tags)[0], expire_time), lineno)
|
||||
|
||||
args_string = u':'.join([urlquote(v) for v in vary_on])
|
||||
args_md5 = md5_constructor(args_string)
|
||||
args_md5 = md5(args_string)
|
||||
cache_key = 'template.cache.%s.%s' % (fragm_name, args_md5.hexdigest())
|
||||
value = cache.get(cache_key)
|
||||
if value is None:
|
||||
|
|
Loading…
Reference in New Issue