Ticket #12847: renamed_simple_tags.patch

File renamed_simple_tags.patch, 3.0 KB (added by Vladimir Moskva, 13 years ago)
  • django/template/base.py

     
    866866        self.filters[getattr(func, "_decorated_function", func).__name__] = func
    867867        return func
    868868
    869     def simple_tag(self, func=None, takes_context=None):
     869    def simple_tag(self, func=None, takes_context=None, name=None):
    870870        def dec(func):
    871             params, xx, xxx, defaults = getargspec(func)
     871            params, varargs, kwargs, defaults = getargspec(func)
    872872            if takes_context:
    873873                if params[0] == 'context':
    874874                    params = params[1:]
     
    887887                        func_args = resolved_vars
    888888                    return func(*func_args)
    889889
    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)
    891892            compile_func.__doc__ = func.__doc__
    892             self.tag(getattr(func, "_decorated_function", func).__name__, compile_func)
     893            self.tag(function_name, compile_func)
    893894            return func
    894895
    895896        if func is None:
  • tests/regressiontests/templates/tests.py

     
    13851385            'templatetag11': ('{% templatetag opencomment %}', {}, '{#'),
    13861386            'templatetag12': ('{% templatetag closecomment %}', {}, '#}'),
    13871387
     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
    13881393            ### WIDTHRATIO TAG ########################################################
    13891394            'widthratio01': ('{% widthratio a b 0 %}', {'a':50,'b':100}, '0'),
    13901395            'widthratio02': ('{% widthratio a b 100 %}', {'a':0,'b':0}, ''),
  • tests/regressiontests/templates/templatetags/custom.py

     
    114114    """Expected assignment_params_and_context __doc__"""
    115115    return "assignment_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)
    116116assignment_params_and_context.anything = "Expected assignment_params_and_context __dict__"
     117
     118register.simple_tag(lambda x: x - 1, name='minusone')
     119
     120@register.simple_tag(name='minustwo')
     121def minustwo_overridden_name(value):
     122    return value - 2
Back to Top