diff --git a/django/template/__init__.py b/django/template/__init__.py
index 29daa76..9b24cba 100644
|
a
|
b
|
from django.utils.encoding import smart_unicode, force_unicode
|
| 59 | 59 | from django.utils.translation import ugettext as _ |
| 60 | 60 | from django.utils.safestring import SafeData, EscapeData, mark_safe, mark_for_escaping |
| 61 | 61 | from django.utils.html import escape |
| 62 | | |
| | 62 | from django.templatetags import get_library_names |
| 63 | 63 | __all__ = ('Template', 'Context', 'RequestContext', 'compile_string') |
| 64 | 64 | |
| 65 | 65 | TOKEN_TEXT = 0 |
| … |
… |
class Library(object):
|
| 910 | 910 | return func |
| 911 | 911 | return dec |
| 912 | 912 | |
| 913 | | def get_library(module_name): |
| | 913 | def get_library(module_name, full_path=False): |
| 914 | 914 | lib = libraries.get(module_name, None) |
| 915 | 915 | if not lib: |
| | 916 | library_names = get_library_names() |
| 916 | 917 | try: |
| 917 | | mod = __import__(module_name, {}, {}, ['']) |
| | 918 | library_name = full_path and module_name or library_names[module_name] |
| | 919 | mod = __import__(library_name, {}, {}, ['']) |
| 918 | 920 | except ImportError, e: |
| 919 | 921 | raise InvalidTemplateLibrary("Could not load template library from %s, %s" % (module_name, e)) |
| 920 | 922 | try: |
| … |
… |
def get_library(module_name):
|
| 925 | 927 | return lib |
| 926 | 928 | |
| 927 | 929 | def add_to_builtins(module_name): |
| 928 | | builtins.append(get_library(module_name)) |
| | 930 | builtins.append(get_library(module_name, full_path=True)) |
| 929 | 931 | |
| 930 | 932 | add_to_builtins('django.template.defaulttags') |
| 931 | 933 | add_to_builtins('django.template.defaultfilters') |
diff --git a/django/templatetags/__init__.py b/django/templatetags/__init__.py
index 9204535..a4c2931 100644
|
a
|
b
|
|
| 1 | 1 | from django.conf import settings |
| | 2 | import os |
| 2 | 3 | |
| 3 | | for a in settings.INSTALLED_APPS: |
| 4 | | try: |
| 5 | | __path__.extend(__import__(a + '.templatetags', {}, {}, ['']).__path__) |
| 6 | | except ImportError: |
| 7 | | pass |
| | 4 | library_names = {} |
| | 5 | |
| | 6 | def get_library_names(): |
| | 7 | if not library_names: |
| | 8 | for a in settings.INSTALLED_APPS: |
| | 9 | try: |
| | 10 | appname = a.find('.')!=-1 and a.split('.')[-1] or a |
| | 11 | name = a + '.templatetags' |
| | 12 | mod = __import__(name, {}, {}, ['']) |
| | 13 | for root, dirs, files in os.walk(mod.__path__[0]): |
| | 14 | for file in files: |
| | 15 | if not file.endswith('.pyc') and not file.startswith('__init__'): |
| | 16 | library_name = os.path.splitext(file)[0] |
| | 17 | library_names[library_name] = name + '.' + library_name |
| | 18 | library_names[appname + '.' + library_name] = name + '.' + library_name |
| | 19 | except ImportError: |
| | 20 | pass |
| | 21 | library_names['i18n'] = 'django.templatetags.i18n' |
| | 22 | library_names['cache'] = 'django.templatetags.cache' |
| | 23 | return library_names |