Ticket #18260: cachetag4.diff

File cachetag4.diff, 3.3 KB (added by wkeeling, 12 years ago)
  • django/templatetags/cache.py

    diff --git a/django/templatetags/cache.py b/django/templatetags/cache.py
    index 056eadc..6b5839c 100644
    a b from __future__ import unicode_literals  
    22
    33import hashlib
    44from django.template import Library, Node, TemplateSyntaxError, Variable, VariableDoesNotExist
    5 from django.template import resolve_variable
    65from django.core.cache import cache
    76from django.utils.http import urlquote
    87
    class CacheNode(Node):  
    2524        except (ValueError, TypeError):
    2625            raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time)
    2726        # Build a unicode key for this fragment and all vary-on's.
    28         args = hashlib.md5(':'.join([urlquote(resolve_variable(var, context)) for var in self.vary_on]))
     27        args = hashlib.md5(u':'.join([urlquote(var.resolve(context)) for var in self.vary_on]))
    2928        cache_key = 'template.cache.%s.%s' % (self.fragment_name, args.hexdigest())
    3029        value = cache.get(cache_key)
    3130        if value is None:
    def do_cache(parser, token):  
    6059    tokens = token.contents.split()
    6160    if len(tokens) < 3:
    6261        raise TemplateSyntaxError("'%r' tag requires at least 2 arguments." % tokens[0])
    63     return CacheNode(nodelist, tokens[1], tokens[2], tokens[3:])
     62    return CacheNode(nodelist, tokens[1], tokens[2], [parser.compile_filter(token) for token in tokens[3:]])
  • tests/regressiontests/templates/tests.py

    diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
    index 4aa71f9..307861c 100644
    a b from django.utils.formats import date_format  
    2828from django.utils.translation import activate, deactivate, ugettext as _
    2929from django.utils.safestring import mark_safe
    3030from django.utils.tzinfo import LocalTimezone
     31from django.http import QueryDict
    3132
    3233from .callables import CallableVariablesTests
    3334from .context import ContextTests
    class Templates(unittest.TestCase):  
    15631564            # Regression test for #11270.
    15641565            'cache17': ('{% load cache %}{% cache 10 long_cache_key poem %}Some Content{% endcache %}', {'poem': 'Oh freddled gruntbuggly/Thy micturations are to me/As plurdled gabbleblotchits/On a lurgid bee/That mordiously hath bitled out/Its earted jurtles/Into a rancid festering/Or else I shall rend thee in the gobberwarts with my blurglecruncheon/See if I dont.'}, 'Some Content'),
    15651566
     1567            # Regression tests for #18260
     1568            'cache18': ('{% load cache %}{% cache 2 frag_name request.GET.abc %}cache18{% endcache %}', {'request': RequestContext(RequestFactory().get("/somepath"), dict_={"GET" : QueryDict("abc=xyz")})}, 'cache18'),
     1569            'cache19': ('{% load cache %}{% cache 2 frag_name request.GET.abc %}cache19{% endcache %}', {'request': RequestContext(RequestFactory().get("/somepath"), dict_={"GET" : QueryDict("foo=bar")})}, 'cache19'),
     1570            'cache20': ('{% load cache %}{% cache 2 frag_name request.GET.abc|default:"xyz" %}cache20{% endcache %}', {'request': RequestContext(RequestFactory().get("/somepath"), dict_={"GET" : QueryDict("foo=bar")})}, ('cache18', 'cache19')),
     1571
    15661572
    15671573            ### AUTOESCAPE TAG ##############################################
    15681574            'autoescape-tag01': ("{% autoescape off %}hello{% endautoescape %}", {}, "hello"),
Back to Top