PageRenderTime 424ms CodeModel.GetById 201ms app.highlight 6ms RepoModel.GetById 215ms app.codeStats 0ms

/tests/regressiontests/templates/templatetags/custom.py

https://code.google.com/p/mango-py/
Python | 71 lines | 47 code | 14 blank | 10 comment | 0 complexity | 4a386a888c9dec908e4aee8cd4fe4db9 MD5 | raw file
 1from django import template
 2from django.template.defaultfilters import stringfilter
 3
 4register = template.Library()
 5
 6def trim(value, num):
 7    return value[:num]
 8trim = stringfilter(trim)
 9
10register.filter(trim)
11
12@register.simple_tag
13def no_params():
14    """Expected no_params __doc__"""
15    return "no_params - Expected result"
16no_params.anything = "Expected no_params __dict__"
17
18@register.simple_tag
19def one_param(arg):
20    """Expected one_param __doc__"""
21    return "one_param - Expected result: %s" % arg
22one_param.anything = "Expected one_param __dict__"
23
24@register.simple_tag(takes_context=False)
25def explicit_no_context(arg):
26    """Expected explicit_no_context __doc__"""
27    return "explicit_no_context - Expected result: %s" % arg
28explicit_no_context.anything = "Expected explicit_no_context __dict__"
29
30@register.simple_tag(takes_context=True)
31def no_params_with_context(context):
32    """Expected no_params_with_context __doc__"""
33    return "no_params_with_context - Expected result (context value: %s)" % context['value']
34no_params_with_context.anything = "Expected no_params_with_context __dict__"
35
36@register.simple_tag(takes_context=True)
37def params_and_context(context, arg):
38    """Expected params_and_context __doc__"""
39    return "params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)
40params_and_context.anything = "Expected params_and_context __dict__"
41
42@register.inclusion_tag('inclusion.html')
43def inclusion_no_params():
44    """Expected inclusion_no_params __doc__"""
45    return {"result" : "inclusion_no_params - Expected result"}
46inclusion_no_params.anything = "Expected inclusion_no_params __dict__"
47
48@register.inclusion_tag('inclusion.html')
49def inclusion_one_param(arg):
50    """Expected inclusion_one_param __doc__"""
51    return {"result" : "inclusion_one_param - Expected result: %s" % arg}
52inclusion_one_param.anything = "Expected inclusion_one_param __dict__"
53
54@register.inclusion_tag('inclusion.html', takes_context=False)
55def inclusion_explicit_no_context(arg):
56    """Expected inclusion_explicit_no_context __doc__"""
57    return {"result" : "inclusion_explicit_no_context - Expected result: %s" % arg}
58inclusion_explicit_no_context.anything = "Expected inclusion_explicit_no_context __dict__"
59
60@register.inclusion_tag('inclusion.html', takes_context=True)
61def inclusion_no_params_with_context(context):
62    """Expected inclusion_no_params_with_context __doc__"""
63    return {"result" : "inclusion_no_params_with_context - Expected result (context value: %s)" % context['value']}
64inclusion_no_params_with_context.anything = "Expected inclusion_no_params_with_context __dict__"
65
66@register.inclusion_tag('inclusion.html', takes_context=True)
67def inclusion_params_and_context(context, arg):
68    """Expected inclusion_params_and_context __doc__"""
69    return {"result" : "inclusion_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)}
70inclusion_params_and_context.anything = "Expected inclusion_params_and_context __dict__"
71