Code

Ticket #1105: simple_tag_with_context_r1764.diff

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

Patch adds simple_tag_with_context tag function decorator

Line 
1Index: django/core/template/__init__.py
2===================================================================
3--- django/core/template/__init__.py    (revision 1764)
4+++ django/core/template/__init__.py    (working copy)
5@@ -858,6 +858,23 @@
6         self.tag(func.__name__, compile_func)
7         return func
8 
9+    def simple_tag_with_context(self,func):
10+        (params, xx, xxx, defaults) = getargspec(func)
11+
12+        class SimpleWithContextNode(Node):
13+            def __init__(self, vars_to_resolve):
14+                self.vars_to_resolve = vars_to_resolve
15+
16+            def render(self, context):
17+                resolved_vars = [resolve_variable(var, context) for var in self.vars_to_resolve]
18+                rendered = func(context, *resolved_vars)
19+                return rendered or ''
20+
21+        compile_func = curry(generic_tag_compiler, params[1:], defaults, func.__name__, SimpleWithContextNode)
22+        compile_func.__doc__ = func.__doc__
23+        self.tag(func.__name__, compile_func)
24+        return func
25+
26     def inclusion_tag(self, file_name, context_class=Context, takes_context=False):
27         def dec(func):
28             (params, xx, xxx, defaults) = getargspec(func)