diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2011-11-21 10:28:12 +0000 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2011-11-21 10:28:12 +0000 |
| commit | c5a899b190d1afa798efade499e8d00a5286fa28 (patch) | |
| tree | 3be4704f57848c3696e895ea6e4a79ed792a5ef8 /django/template/base.py | |
| parent | 19e54084dc7d85d0bf190e0d79575126c5d29a50 (diff) | |
Fixed #16787 -- Restored the ability to {% load %} template tags libraries within packages. Thanks Ivan Sagalaev for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17133 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/template/base.py')
| -rw-r--r-- | django/template/base.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/django/template/base.py b/django/template/base.py index 40a577dbd8..e23420b828 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -1215,6 +1215,22 @@ class Library(object): return func return dec +def is_library_missing(name): + """Check if library that failed to load cannot be found under any + templatetags directory or does exist but fails to import. + + Non-existing condition is checked recursively for each subpackage in cases + like <appdir>/templatetags/subpackage/package/module.py. + """ + # Don't bother to check if '.' is in name since any name will be prefixed + # with some template root. + path, module = name.rsplit('.', 1) + try: + package = import_module(path) + return not module_has_submodule(package, module) + except ImportError: + return is_library_missing(path) + def import_library(taglib_module): """ Load a template tag library module. @@ -1222,8 +1238,6 @@ def import_library(taglib_module): Verifies that the library contains a 'register' attribute, and returns that attribute as the representation of the library """ - app_path, taglib = taglib_module.rsplit('.', 1) - app_module = import_module(app_path) try: mod = import_module(taglib_module) except ImportError, e: @@ -1231,7 +1245,7 @@ def import_library(taglib_module): # that's not an error that should be raised. If the submodule exists # and raised an ImportError on the attempt to load it, that we want # to raise. - if not module_has_submodule(app_module, taglib): + if is_library_missing(taglib_module): return None else: raise InvalidTemplateLibrary("ImportError raised loading %s: %s" % |
