Code

Ticket #18260: cachetag.2.diff

File cachetag.2.diff, 1.6 KB (added by FunkyBob, 2 years ago)

Changed to using token.split_contents() instead of token.contents.split() [thanks, brad!]

Line 
1--- /home/curtis/src/svn/django/django/templatetags/cache.py    2011-07-14 11:05:26.000000000 +1000
2+++ django/templatetags/cache.py        2012-05-03 18:49:10.000000000 +1000
3@@ -9,7 +9,7 @@
4 class CacheNode(Node):
5     def __init__(self, nodelist, expire_time_var, fragment_name, vary_on):
6         self.nodelist = nodelist
7-        self.expire_time_var = Variable(expire_time_var)
8+        self.expire_time_var = expire_time_var
9         self.fragment_name = fragment_name
10         self.vary_on = vary_on
11 
12@@ -23,8 +23,8 @@
13         except (ValueError, TypeError):
14             raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time)
15         # Build a unicode key for this fragment and all vary-on's.
16-        args = hashlib.md5(u':'.join([urlquote(resolve_variable(var, context)) for var in self.vary_on]))
17-        cache_key = 'template.cache.%s.%s' % (self.fragment_name, args.hexdigest())
18+        args = hashlib.md5(u':'.join([urlquote(var.resolve(context)) for var in self.vary_on]))
19+        cache_key = 'template.cache.%s.%s' % (self.fragment_name.resolve(context), args.hexdigest())
20         value = cache.get(cache_key)
21         if value is None:
22             value = self.nodelist.render(context)
23@@ -55,7 +55,7 @@
24     """
25     nodelist = parser.parse(('endcache',))
26     parser.delete_first_token()
27-    tokens = token.contents.split()
28+    tokens = [parser.compile_filter(token) for token in token.split_contents()]
29     if len(tokens) < 3:
30         raise TemplateSyntaxError(u"'%r' tag requires at least 2 arguments." % tokens[0])
31     return CacheNode(nodelist, tokens[1], tokens[2], tokens[3:])