# HG changeset patch
# User Simon Law <simon@akoha.org>
# Date 1197999869 18000
# Branch trunk
# Node ID a742eea27d06087ce019c4564967bd3883b91c4c
# Parent 6636f16ed3195d7021d339598a3b229e5ae6553e
Allow pickling of django.template.SimpleNode objects.
diff --git a/django/template/__init__.py b/django/template/__init__.py
a
|
b
|
def generic_tag_compiler(params, default
|
890 | 890 | raise TemplateSyntaxError, message |
891 | 891 | return node_class(bits) |
892 | 892 | |
| 893 | class SimpleNode(Node): |
| 894 | def __init__(self, vars_to_resolve, func): |
| 895 | self.vars_to_resolve = map(Variable, vars_to_resolve) |
| 896 | self.func = func |
| 897 | |
| 898 | def render(self, context): |
| 899 | resolved_vars = [var.resolve(context) for var in self.vars_to_resolve] |
| 900 | return self.func(*resolved_vars) |
| 901 | |
893 | 902 | class Library(object): |
894 | 903 | def __init__(self): |
895 | 904 | self.filters = {} |
… |
… |
class Library(object):
|
946 | 955 | def simple_tag(self,func): |
947 | 956 | params, xx, xxx, defaults = getargspec(func) |
948 | 957 | |
949 | | class SimpleNode(Node): |
950 | | def __init__(self, vars_to_resolve): |
951 | | self.vars_to_resolve = map(Variable, vars_to_resolve) |
952 | | |
953 | | def render(self, context): |
954 | | resolved_vars = [var.resolve(context) for var in self.vars_to_resolve] |
955 | | return func(*resolved_vars) |
| 958 | def SimpleNode__init__(self, vars_to_resolve): |
| 959 | self.vars_to_resolve = map(Variable, vars_to_resolve) |
| 960 | self.func = func |
| 961 | SimpleNode.__init__ = SimpleNode__init__ |
956 | 962 | |
957 | 963 | compile_func = curry(generic_tag_compiler, params, defaults, getattr(func, "_decorated_function", func).__name__, SimpleNode) |
958 | 964 | compile_func.__doc__ = func.__doc__ |