=== modified file 'django/template/base.py'
|
|
|
1012 | 1012 | return func |
1013 | 1013 | return dec |
1014 | 1014 | |
| 1015 | def 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 | |
1015 | 1031 | def import_library(taglib_module): |
1016 | 1032 | """Load a template tag library module. |
1017 | 1033 | |
1018 | 1034 | Verifies that the library contains a 'register' attribute, and |
1019 | 1035 | returns that attribute as the representation of the library |
1020 | 1036 | """ |
1021 | | app_path, taglib = taglib_module.rsplit('.',1) |
1022 | | app_module = import_module(app_path) |
1023 | 1037 | try: |
1024 | 1038 | mod = import_module(taglib_module) |
1025 | 1039 | except ImportError, e: |
1026 | 1040 | # If the ImportError is because the taglib submodule does not exist, that's not |
1027 | 1041 | # an error that should be raised. If the submodule exists and raised an ImportError |
1028 | 1042 | # 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): |
1030 | 1044 | return None |
1031 | 1045 | else: |
1032 | 1046 | raise InvalidTemplateLibrary("ImportError raised loading %s: %s" % (taglib_module, e)) |
=== modified file 'docs/ref/templates/builtins.txt'
|
|
|
692 | 692 | Load a custom template tag set. |
693 | 693 | |
694 | 694 | For example, the following template would load all the tags and filters |
695 | | registered in ``somelibrary`` and ``otherlibrary``:: |
| 695 | registered in ``somelibrary`` and ``otherlibrary`` located in package |
| 696 | ``package``:: |
696 | 697 | |
697 | | {% load somelibrary otherlibrary %} |
| 698 | {% load somelibrary package.otherlibrary %} |
698 | 699 | |
699 | 700 | .. versionchanged:: 1.3 |
700 | 701 | |
=== 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'
|
|
|
| 1 | from django import template |
| 2 | |
| 3 | register = template.Library() |
| 4 | |
| 5 | @register.simple_tag |
| 6 | def echo(arg): |
| 7 | return arg |
=== added file 'tests/regressiontests/templates/templatetags/subpackage/echo_invalid.py'
|
|
|
| 1 | import nonexistent.module |
=== modified file 'tests/regressiontests/templates/tests.py'
|
|
|
1200 | 1200 | 'load6': ("{% load from testtags %}", {}, template.TemplateSyntaxError), |
1201 | 1201 | 'load7': ("{% load echo from bad_library %}", {}, template.TemplateSyntaxError), |
1202 | 1202 | |
| 1203 | # {% load %} tag, libraries in hierarchies |
| 1204 | 'load8': ("{% load subpackage.echo %}{% echo \"test\" %}", {}, "test"), |
| 1205 | 'load9': ("{% load subpackage.echo_invalid %}", {}, template.TemplateSyntaxError), |
| 1206 | 'load10': ("{% load subpackage.missing %}", {}, template.TemplateSyntaxError), |
| 1207 | |
1203 | 1208 | ### I18N ################################################################## |
1204 | 1209 | |
1205 | 1210 | # {% spaceless %} tag |