| 891 | | return node_class(bits) |
| | 891 | return node_class(bits, **init) |
| | 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 | |
| | 902 | class InclusionNode(Node): |
| | 903 | def __init__(self, vars_to_resolve, file_name, context_class, takes_context, func): |
| | 904 | self.vars_to_resolve = map(Variable, vars_to_resolve) |
| | 905 | self.file_name = file_name |
| | 906 | self.context_class = context_class |
| | 907 | self.takes_context = takes_context |
| | 908 | self.func = func |
| | 909 | |
| | 910 | def render(self, context): |
| | 911 | resolved_vars = [var.resolve(context) for var in self.vars_to_resolve] |
| | 912 | if self.takes_context: |
| | 913 | args = [context] + resolved_vars |
| | 914 | else: |
| | 915 | args = resolved_vars |
| | 916 | |
| | 917 | dict = self.func(*args) |
| | 918 | |
| | 919 | if not getattr(self, 'nodelist', False): |
| | 920 | from django.template.loader import get_template, select_template |
| | 921 | if not isinstance(self.file_name, basestring) and is_iterable(self.file_name): |
| | 922 | t = select_template(self.file_name) |
| | 923 | else: |
| | 924 | t = get_template(self.file_name) |
| | 925 | self.nodelist = t.nodelist |
| | 926 | return self.nodelist.render(self.context_class(dict, |
| | 927 | autoescape=context.autoescape)) |
| 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) |
| 956 | | |
| 957 | | compile_func = curry(generic_tag_compiler, params, defaults, getattr(func, "_decorated_function", func).__name__, SimpleNode) |
| | 985 | compile_func = curry(generic_tag_compiler, {"func": func}, params, defaults, getattr(func, "_decorated_function", func).__name__, SimpleNode) |
| 971 | | class InclusionNode(Node): |
| 972 | | def __init__(self, vars_to_resolve): |
| 973 | | self.vars_to_resolve = map(Variable, vars_to_resolve) |
| 974 | | |
| 975 | | def render(self, context): |
| 976 | | resolved_vars = [var.resolve(context) for var in self.vars_to_resolve] |
| 977 | | if takes_context: |
| 978 | | args = [context] + resolved_vars |
| 979 | | else: |
| 980 | | args = resolved_vars |
| 981 | | |
| 982 | | dict = func(*args) |
| 983 | | |
| 984 | | if not getattr(self, 'nodelist', False): |
| 985 | | from django.template.loader import get_template, select_template |
| 986 | | if not isinstance(file_name, basestring) and is_iterable(file_name): |
| 987 | | t = select_template(file_name) |
| 988 | | else: |
| 989 | | t = get_template(file_name) |
| 990 | | self.nodelist = t.nodelist |
| 991 | | return self.nodelist.render(context_class(dict, |
| 992 | | autoescape=context.autoescape)) |
| 993 | | |
| 994 | | compile_func = curry(generic_tag_compiler, params, defaults, getattr(func, "_decorated_function", func).__name__, InclusionNode) |
| | 999 | init = {"file_name": file_name, "context_class": context_class, "takes_context": takes_context, "func": func} |
| | 1000 | compile_func = curry(generic_tag_compiler, init, params, defaults, getattr(func, "_decorated_function", func).__name__, InclusionNode) |