Ticket #1105: simple_tag_with_context_r1764.diff

File simple_tag_with_context_r1764.diff, 1.2 KB (added by django@…, 19 years ago)

Patch adds simple_tag_with_context tag function decorator

  • django/core/template/__init__.py

     
    858858        self.tag(func.__name__, compile_func)
    859859        return func
    860860
     861    def simple_tag_with_context(self,func):
     862        (params, xx, xxx, defaults) = getargspec(func)
     863
     864        class SimpleWithContextNode(Node):
     865            def __init__(self, vars_to_resolve):
     866                self.vars_to_resolve = vars_to_resolve
     867
     868            def render(self, context):
     869                resolved_vars = [resolve_variable(var, context) for var in self.vars_to_resolve]
     870                rendered = func(context, *resolved_vars)
     871                return rendered or ''
     872
     873        compile_func = curry(generic_tag_compiler, params[1:], defaults, func.__name__, SimpleWithContextNode)
     874        compile_func.__doc__ = func.__doc__
     875        self.tag(func.__name__, compile_func)
     876        return func
     877
    861878    def inclusion_tag(self, file_name, context_class=Context, takes_context=False):
    862879        def dec(func):
    863880            (params, xx, xxx, defaults) = getargspec(func)
Back to Top