Ticket #13956: indefinite_inclusion_tag_args.diff
File indefinite_inclusion_tag_args.diff, 3.3 KB (added by , 14 years ago) |
---|
-
django/template/__init__.py
848 848 return '' 849 849 return _render_value_in_context(output, context) 850 850 851 def generic_tag_compiler(params, defaults, name, node_class, parser, token ):851 def generic_tag_compiler(params, defaults, name, node_class, parser, token, varargs=None): 852 852 "Returns a template.Node subclass." 853 853 bits = token.split_contents()[1:] 854 854 bmax = len(params) 855 855 def_len = defaults and len(defaults) or 0 856 856 bmin = bmax - def_len 857 if(len(bits) < bmin or len(bits) > bmax): 858 if bmin == bmax: 859 message = "%s takes %s arguments" % (name, bmin) 860 else: 861 message = "%s takes between %s and %s arguments" % (name, bmin, bmax) 862 raise TemplateSyntaxError(message) 857 if varargs is None: 858 if(len(bits) < bmin or len(bits) > bmax): 859 if bmin == bmax: 860 message = "%s takes %s arguments" % (name, bmin) 861 else: 862 message = "%s takes between %s and %s arguments" % (name, bmin, bmax) 863 raise TemplateSyntaxError(message) 864 else: 865 if(len(bits) < bmin): 866 message = "%s takes at least %s arguments" % (name, bmin) 867 raise TemplateSyntaxError(message) 863 868 return node_class(bits) 864 869 865 870 class Library(object): … … 916 921 return func 917 922 918 923 def simple_tag(self,func): 919 params, xx, xxx, defaults = getargspec(func)924 params, varargs, xx, defaults = getargspec(func) 920 925 921 926 class SimpleNode(Node): 922 927 def __init__(self, vars_to_resolve): … … 926 931 resolved_vars = [var.resolve(context) for var in self.vars_to_resolve] 927 932 return func(*resolved_vars) 928 933 929 compile_func = curry(generic_tag_compiler, params, defaults, getattr(func, "_decorated_function", func).__name__, SimpleNode )934 compile_func = curry(generic_tag_compiler, params, defaults, getattr(func, "_decorated_function", func).__name__, SimpleNode, varargs=varargs) 930 935 compile_func.__doc__ = func.__doc__ 931 936 self.tag(getattr(func, "_decorated_function", func).__name__, compile_func) 932 937 return func 933 938 934 939 def inclusion_tag(self, file_name, context_class=Context, takes_context=False): 935 940 def dec(func): 936 params, xx, xxx, defaults = getargspec(func)941 params, varargs, xx, defaults = getargspec(func) 937 942 if takes_context: 938 943 if params[0] == 'context': 939 944 params = params[1:] … … 968 973 if csrf_token is not None: 969 974 new_context['csrf_token'] = csrf_token 970 975 return self.nodelist.render(new_context) 971 972 compile_func = curry(generic_tag_compiler, params, defaults, getattr(func, "_decorated_function", func).__name__, InclusionNode) 976 compile_func = curry(generic_tag_compiler, params, defaults, getattr(func, "_decorated_function", func).__name__, InclusionNode, varargs=varargs) 973 977 compile_func.__doc__ = func.__doc__ 974 978 self.tag(getattr(func, "_decorated_function", func).__name__, compile_func) 975 979 return func