Ticket #16787: 16787.5.diff

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

Patch updated to current trunk

  • django/template/base.py

    === modified file 'django/template/base.py'
     
    11901190            return func
    11911191        return dec
    11921192
     1193def is_library_missing(name):
     1194    """Check if library that failed to load cannot be found under any
     1195    templatetags directory or does exist but fails to import.
     1196
     1197    Non-existing condition is checked recursively for each subpackage in cases
     1198    like <appdir>/templatetags/subpackage/package/module.py.
     1199    """
     1200    # Don't bother to check if '.' is in name since any name will be prefixed
     1201    # with some template root.
     1202    path, module = name.rsplit('.', 1)
     1203    try:
     1204        package = import_module(path)
     1205        return not module_has_submodule(package, module)
     1206    except ImportError:
     1207        return is_library_missing(path)
     1208
    11931209def import_library(taglib_module):
    11941210    """
    11951211    Load a template tag library module.
     
    11971213    Verifies that the library contains a 'register' attribute, and
    11981214    returns that attribute as the representation of the library
    11991215    """
    1200     app_path, taglib = taglib_module.rsplit('.', 1)
    1201     app_module = import_module(app_path)
    12021216    try:
    12031217        mod = import_module(taglib_module)
    12041218    except ImportError, e:
     
    12061220        # that's not an error that should be raised. If the submodule exists
    12071221        # and raised an ImportError on the attempt to load it, that we want
    12081222        # to raise.
    1209         if not module_has_submodule(app_module, taglib):
     1223        if is_library_missing(taglib_module):
    12101224            return None
    12111225        else:
    12121226            raise InvalidTemplateLibrary("ImportError raised loading %s: %s" %
  • docs/ref/templates/builtins.txt

    === modified file 'docs/ref/templates/builtins.txt'
     
    698698Loads a custom template tag set.
    699699
    700700For example, the following template would load all the tags and filters
    701 registered in ``somelibrary`` and ``otherlibrary``::
     701registered in ``somelibrary`` and ``otherlibrary`` located in package
     702``package``::
    702703
    703     {% load somelibrary otherlibrary %}
     704    {% load somelibrary package.otherlibrary %}
    704705
    705706.. versionchanged:: 1.3
    706707
  • 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'
     
    11911191            'inheritance41': ("{% extends 'inheritance36' %}{% block opt %}new{{ block.super }}{% endblock %}", {'numbers': '123'}, '_new1_new2_new3_'),
    11921192
    11931193            ### LOADING TAG LIBRARIES #################################################
     1194            'load01': ("{% load testtags subpackage.echo %}{% echo test %} {% echo2 \"test\" %}", {}, "test test"),
     1195            'load02': ("{% load subpackage.echo %}{% echo2 \"test\" %}", {}, "test"),
    11941196
    11951197            # {% load %} tag, importing individual tags
    1196             'load1': ("{% load echo from testtags %}{% echo this that theother %}", {}, 'this that theother'),
    1197             'load2': ("{% load echo other_echo from testtags %}{% echo this that theother %} {% other_echo and another thing %}", {}, 'this that theother and another thing'),
    1198             'load3': ("{% load echo upper from testtags %}{% echo this that theother %} {{ statement|upper }}", {'statement': 'not shouting'}, 'this that theother NOT SHOUTING'),
     1198            'load03': ("{% load echo from testtags %}{% echo this that theother %}", {}, 'this that theother'),
     1199            'load04': ("{% load echo other_echo from testtags %}{% echo this that theother %} {% other_echo and another thing %}", {}, 'this that theother and another thing'),
     1200            'load05': ("{% load echo upper from testtags %}{% echo this that theother %} {{ statement|upper }}", {'statement': 'not shouting'}, 'this that theother NOT SHOUTING'),
     1201            'load06': ("{% load echo2 from subpackage.echo %}{% echo2 \"test\" %}", {}, "test"),
    11991202
    12001203            # {% load %} tag errors
    1201             'load4': ("{% load echo other_echo bad_tag from testtags %}", {}, template.TemplateSyntaxError),
    1202             'load5': ("{% load echo other_echo bad_tag from %}", {}, template.TemplateSyntaxError),
    1203             'load6': ("{% load from testtags %}", {}, template.TemplateSyntaxError),
    1204             'load7': ("{% load echo from bad_library %}", {}, template.TemplateSyntaxError),
     1204            'load07': ("{% load echo other_echo bad_tag from testtags %}", {}, template.TemplateSyntaxError),
     1205            'load08': ("{% load echo other_echo bad_tag from %}", {}, template.TemplateSyntaxError),
     1206            'load09': ("{% load from testtags %}", {}, template.TemplateSyntaxError),
     1207            'load10': ("{% load echo from bad_library %}", {}, template.TemplateSyntaxError),
     1208            'load11': ("{% load subpackage.echo_invalid %}", {}, template.TemplateSyntaxError),
     1209            'load12': ("{% load subpackage.missing %}", {}, template.TemplateSyntaxError),
    12051210
    12061211            ### I18N ##################################################################
    12071212
Back to Top