Author: mtredinnick
Date: 2008-08-24 23:52:55 -0500 (Sun, 24 Aug 2008)
New Revision: 8533
Modified:
django/trunk/django/templatetags/cache.py
django/trunk/tests/regressiontests/templates/tests.py
Log:
Fixed #7460 -- Made the "cache" template tag always generate keys that can be
used with the memcache backend (which has the strongest restriction on keys).
Based on a patch from trbs.
Modified: django/trunk/django/templatetags/cache.py
===================================================================
--- django/trunk/django/templatetags/cache.py 2008-08-25 04:13:27 UTC (rev
8532)
+++ django/trunk/django/templatetags/cache.py 2008-08-25 04:52:55 UTC (rev
8533)
@@ -2,6 +2,7 @@
from django.template import resolve_variable
from django.core.cache import cache
from django.utils.encoding import force_unicode
+from django.utils.http import urlquote
register = Library()
@@ -22,7 +23,7 @@
except (ValueError, TypeError):
raise TemplateSyntaxError('"cache" tag got a non-integer timeout
value: %r' % expire_time)
# Build a unicode key for this fragment and all vary-on's.
- cache_key = u':'.join([self.fragment_name] +
[force_unicode(resolve_variable(var, context)) for var in self.vary_on])
+ cache_key = u':'.join([self.fragment_name] +
[urlquote(resolve_variable(var, context)) for var in self.vary_on])
value = cache.get(cache_key)
if value is None:
value = self.nodelist.render(context)
Modified: django/trunk/tests/regressiontests/templates/tests.py
===================================================================
--- django/trunk/tests/regressiontests/templates/tests.py 2008-08-25
04:13:27 UTC (rev 8532)
+++ django/trunk/tests/regressiontests/templates/tests.py 2008-08-25
04:52:55 UTC (rev 8533)
@@ -917,6 +917,9 @@
'cache14': ('{% load cache %}{% cache foo bar %}{% endcache %}',
{'foo': 'fail'}, template.TemplateSyntaxError),
'cache15': ('{% load cache %}{% cache foo bar %}{% endcache %}',
{'foo': []}, template.TemplateSyntaxError),
+ # Regression test for #7460.
+ 'cache16': ('{% load cache %}{% cache 1 foo bar %}{% endcache %}',
{'foo': 'foo', 'bar': 'with spaces'}, ''),
+
### AUTOESCAPE TAG ##############################################
'autoescape-tag01': ("{% autoescape off %}hello{% endautoescape
%}", {}, "hello"),
'autoescape-tag02': ("{% autoescape off %}{{ first }}{%
endautoescape %}", {"first": "<b>hello</b>"}, "<b>hello</b>"),
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---