Ticket #12847: renamed_simple_tags.2.patch
File renamed_simple_tags.2.patch, 4.2 KB (added by , 13 years ago) |
---|
-
docs/howto/custom-template-tags.txt
687 687 For more information on how the ``takes_context`` option works, see the section 688 688 on :ref:`inclusion tags<howto-custom-template-tags-inclusion-tags>`. 689 689 690 .. versionadded:: 1.4 691 692 If you need to rename your tag, you can provide a custom name for it:: 693 694 register.simple_tags(lambda x: x - 1, name='minusone') 695 696 @register.simple_tag(name='minustwo') 697 def some_function(value): 698 return value - 1 699 690 700 .. _howto-custom-template-tags-assignment-tags: 691 701 692 702 Assignment tags -
docs/releases/1.4.txt
166 166 code are slightly emphasized. This change makes it easier to scan a stacktrace 167 167 for issues in user code. 168 168 169 * Customizable names for :meth:`~django.template.Library.simple_tag`. 169 170 170 171 .. _backwards-incompatible-changes-1.4: 171 172 -
django/template/base.py
866 866 self.filters[getattr(func, "_decorated_function", func).__name__] = func 867 867 return func 868 868 869 def simple_tag(self, func=None, takes_context=None ):869 def simple_tag(self, func=None, takes_context=None, name=None): 870 870 def dec(func): 871 params, xx, xxx, defaults = getargspec(func)871 params, varargs, kwargs, defaults = getargspec(func) 872 872 if takes_context: 873 873 if params[0] == 'context': 874 874 params = params[1:] … … 887 887 func_args = resolved_vars 888 888 return func(*func_args) 889 889 890 compile_func = partial(generic_tag_compiler, params, defaults, getattr(func, "_decorated_function", func).__name__, SimpleNode) 890 function_name = name or getattr(func, '_decorated_function', func).__name__ 891 compile_func = partial(generic_tag_compiler, params, defaults, function_name, SimpleNode) 891 892 compile_func.__doc__ = func.__doc__ 892 self.tag( getattr(func, "_decorated_function", func).__name__, compile_func)893 self.tag(function_name, compile_func) 893 894 return func 894 895 895 896 if func is None: -
tests/regressiontests/templates/tests.py
1385 1385 'templatetag11': ('{% templatetag opencomment %}', {}, '{#'), 1386 1386 'templatetag12': ('{% templatetag closecomment %}', {}, '#}'), 1387 1387 1388 # Simple tags with customized names 1389 'simpletag-renamed01': ('{% load custom %}{% minusone 7 %}', {}, '6'), 1390 'simpletag-renamed02': ('{% load custom %}{% minustwo 7 %}', {}, '5'), 1391 'simpletag-renamed03': ('{% load custom %}{% minustwo_overridden_name 7 %}', {}, template.TemplateSyntaxError), 1392 1388 1393 ### WIDTHRATIO TAG ######################################################## 1389 1394 'widthratio01': ('{% widthratio a b 0 %}', {'a':50,'b':100}, '0'), 1390 1395 'widthratio02': ('{% widthratio a b 100 %}', {'a':0,'b':0}, ''), -
tests/regressiontests/templates/templatetags/custom.py
114 114 """Expected assignment_params_and_context __doc__""" 115 115 return "assignment_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg) 116 116 assignment_params_and_context.anything = "Expected assignment_params_and_context __dict__" 117 118 register.simple_tag(lambda x: x - 1, name='minusone') 119 120 @register.simple_tag(name='minustwo') 121 def minustwo_overridden_name(value): 122 return value - 2