Python django.template.Library() Examples

The following are code examples for showing how to use django.template.Library(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: django-performance-testing   Author: PaesslerAG   File: test_template_limit_blocks.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_there_is_a_correct_templatetag_library():
    """
    see https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/
    """
    from django_performance_testing.templatetags import djpt_limits
    assert hasattr(djpt_limits, 'register')
    assert isinstance(djpt_limits.register, template.Library)
    assert 'djptlimit' in djpt_limits.register.tags


# The below tests are based on the registry's content. Tests will rely on the
# global defaults that are tested elsewhere in the test*registry*.py files 
Example 2
Project: django-performance-testing   Author: PaesslerAG   File: djpt_limits.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_args_kwargs(parser, token):
    """ copied from
        django.template.(base|library).Library.simple_tag.compile_func """
    def to_limit(limit_name, **limit_kwargs):
        pass
    params, varargs, varkw, defaults = getargspec(to_limit)
    function_name = 'djptlimit'
    bits = token.split_contents()[1:]
    takes_context = False
    args, kwargs = parse_bits(
        parser, bits, params,
        varargs, varkw, defaults, takes_context, function_name)
    return args, kwargs 
Example 3
Project: AgendaTCC   Author: agendaTCC   File: tests.py    GNU General Public License v2.0 5 votes vote down vote up
def test_naming(self):
        # test implicit naming
        class MyTag(core.Tag):
            pass
        lib = template.Library()
        lib.tag(MyTag)
        msg = "'my_tag' not in %s" % lib.tags.keys()
        self.assertTrue('my_tag' in lib.tags, msg)
        # test explicit naming

        class MyTag2(core.Tag):
            name = 'my_tag_2'

        lib = template.Library()
        lib.tag(MyTag2)
        msg = "'my_tag_2' not in %s" % lib.tags.keys()
        self.assertTrue('my_tag_2' in lib.tags, msg)
        # test named registering
        lib = template.Library()
        lib.tag('my_tag_3', MyTag)
        msg = "'my_tag_3' not in %s" % lib.tags.keys()
        self.assertTrue('my_tag_3' in lib.tags, msg)
        msg = "'my_tag' in %s" % lib.tags.keys()
        self.assertTrue('my_tag' not in lib.tags, msg)
        lib = template.Library()
        lib.tag('my_tag_4', MyTag2)
        msg = "'my_tag_4' not in %s" % lib.tags.keys()
        self.assertTrue('my_tag_4' in lib.tags, msg)
        msg = "'my_tag2' in %s" % lib.tags.keys()
        self.assertTrue('my_tag2' not in lib.tags, msg) 
Example 4
Project: AgendaTCC   Author: agendaTCC   File: context_managers.py    GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *tags):
        self.lib = template.Library()
        for tag in tags:
            self.lib.tag(tag) 
Example 5
Project: docker-django-polymer-starter-kit   Author: JTarball   File: search_tags.py    ISC License 5 votes vote down vote up
def show_results():
    #choices = poll.choice_set.all()
    return {'choices': 'zxcxzczx'}

# Here, register is a django.template.Library instance, as before