| 876 | def subview_tag(self, template_cmd, context_class=Context, takes_context=True): |
| 877 | def dec(func): |
| 878 | params, xx, xxx, defaults = getargspec(func) |
| 879 | if takes_context: |
| 880 | if params[0] == 'context': |
| 881 | params = params[1:] |
| 882 | else: |
| 883 | raise TemplateSyntaxError, "Any tag function decorated with takes_context=True must have a first argument of 'context'" |
| 884 | |
| 885 | class SubviewNode(Node): |
| 886 | def __init__(self, vars_to_resolve): |
| 887 | self.vars_to_resolve = vars_to_resolve |
| 888 | |
| 889 | def render(self, context): |
| 890 | resolved_vars = [resolve_variable(var, context) for var in self.vars_to_resolve] |
| 891 | if takes_context: |
| 892 | args = [context] + resolved_vars |
| 893 | else: |
| 894 | args = resolved_vars |
| 895 | |
| 896 | return func(*args) |
| 897 | |
| 898 | compile_func = curry(generic_tag_compiler, params, defaults, func.__name__, SubviewNode) |
| 899 | compile_func = curry(generic_tag_compiler, params, defaults, |
| 900 | func.__name__, SubviewNode) |
| 901 | compile_func.__doc__ = func.__doc__ |
| 902 | self.tag(template_cmd, compile_func) |
| 903 | return func |
| 904 | return dec |
| 905 | |