Ticket #16787: 16787.3.diff

File 16787.3.diff, 5.9 KB (added by Ivan Sagalaev, 13 years ago)

More specific tests

  • django/template/base.py

    === modified file 'django/template/base.py'
     
    10121012            return func
    10131013        return dec
    10141014
     1015def is_library_missing(name):
     1016    """Check if library that failed to load cannot be found under a template
     1017    root or does exist but failes to import.
     1018
     1019    Non-existing condition is checked recursively for each subpackage in cases
     1020    like <temlpate_root>/subpacke/package/module.py.
     1021    """
     1022    # Don't bother to check if '.' is in name since any name will be prefixed
     1023    # with some template root.
     1024    path, module = name.rsplit('.', 1)
     1025    try:
     1026        package = import_module(path)
     1027        return not module_has_submodule(package, module)
     1028    except ImportError:
     1029        return is_library_missing(path)
     1030
    10151031def import_library(taglib_module):
    10161032    """Load a template tag library module.
    10171033
    10181034    Verifies that the library contains a 'register' attribute, and
    10191035    returns that attribute as the representation of the library
    10201036    """
    1021     app_path, taglib = taglib_module.rsplit('.',1)
    1022     app_module = import_module(app_path)
    10231037    try:
    10241038        mod = import_module(taglib_module)
    10251039    except ImportError, e:
    10261040        # If the ImportError is because the taglib submodule does not exist, that's not
    10271041        # an error that should be raised. If the submodule exists and raised an ImportError
    10281042        # on the attempt to load it, that we want to raise.
    1029         if not module_has_submodule(app_module, taglib):
     1043        if is_library_missing(taglib_module):
    10301044            return None
    10311045        else:
    10321046            raise InvalidTemplateLibrary("ImportError raised loading %s: %s" % (taglib_module, e))
  • docs/ref/templates/builtins.txt

    === modified file 'docs/ref/templates/builtins.txt'
     
    692692Load a custom template tag set.
    693693
    694694For example, the following template would load all the tags and filters
    695 registered in ``somelibrary`` and ``otherlibrary``::
     695registered in ``somelibrary`` and ``otherlibrary`` located in package
     696``package``::
    696697
    697     {% load somelibrary otherlibrary %}
     698    {% load somelibrary package.otherlibrary %}
    698699
    699700.. versionchanged:: 1.3
    700701
  • tests/regressiontests/templates/templatetags/subpackage/echo.py

    === added directory 'tests/regressiontests/templates/templatetags/subpackage'
    === added file 'tests/regressiontests/templates/templatetags/subpackage/__init__.py'
    === added file 'tests/regressiontests/templates/templatetags/subpackage/echo.py'
     
     1from django import template
     2
     3register = template.Library()
     4
     5@register.simple_tag
     6def echo2(arg):
     7    return arg
  • tests/regressiontests/templates/templatetags/subpackage/echo_invalid.py

    === added file 'tests/regressiontests/templates/templatetags/subpackage/echo_invalid.py'
     
     1import nonexistent.module
  • tests/regressiontests/templates/tests.py

    === modified file 'tests/regressiontests/templates/tests.py'
     
    11881188            'inheritance41': ("{% extends 'inheritance36' %}{% block opt %}new{{ block.super }}{% endblock %}", {'numbers': '123'}, '_new1_new2_new3_'),
    11891189
    11901190            ### LOADING TAG LIBRARIES #################################################
     1191            'load01': ("{% load testtags subpackage.echo %}{% echo test %} {% echo2 \"test\" %}", {}, "test test"),
     1192            'load02': ("{% load subpackage.echo %}{% echo2 \"test\" %}", {}, "test"),
    11911193
    11921194            # {% load %} tag, importing individual tags
    1193             'load1': ("{% load echo from testtags %}{% echo this that theother %}", {}, 'this that theother'),
    1194             'load2': ("{% load echo other_echo from testtags %}{% echo this that theother %} {% other_echo and another thing %}", {}, 'this that theother and another thing'),
    1195             'load3': ("{% load echo upper from testtags %}{% echo this that theother %} {{ statement|upper }}", {'statement': 'not shouting'}, 'this that theother NOT SHOUTING'),
     1195            'load03': ("{% load echo from testtags %}{% echo this that theother %}", {}, 'this that theother'),
     1196            'load04': ("{% load echo other_echo from testtags %}{% echo this that theother %} {% other_echo and another thing %}", {}, 'this that theother and another thing'),
     1197            'load05': ("{% load echo upper from testtags %}{% echo this that theother %} {{ statement|upper }}", {'statement': 'not shouting'}, 'this that theother NOT SHOUTING'),
     1198            'load06': ("{% load echo2 from subpackage.echo %}{% echo2 \"test\" %}", {}, "test"),
    11961199
    11971200            # {% load %} tag errors
    1198             'load4': ("{% load echo other_echo bad_tag from testtags %}", {}, template.TemplateSyntaxError),
    1199             'load5': ("{% load echo other_echo bad_tag from %}", {}, template.TemplateSyntaxError),
    1200             'load6': ("{% load from testtags %}", {}, template.TemplateSyntaxError),
    1201             'load7': ("{% load echo from bad_library %}", {}, template.TemplateSyntaxError),
     1201            'load07': ("{% load echo other_echo bad_tag from testtags %}", {}, template.TemplateSyntaxError),
     1202            'load08': ("{% load echo other_echo bad_tag from %}", {}, template.TemplateSyntaxError),
     1203            'load09': ("{% load from testtags %}", {}, template.TemplateSyntaxError),
     1204            'load10': ("{% load echo from bad_library %}", {}, template.TemplateSyntaxError),
     1205            'load11': ("{% load subpackage.echo_invalid %}", {}, template.TemplateSyntaxError),
     1206            'load12': ("{% load subpackage.missing %}", {}, template.TemplateSyntaxError),
    12021207
    12031208            ### I18N ##################################################################
    12041209
Back to Top