Ticket #6587: new_template_lib_loader_5.diff
File new_template_lib_loader_5.diff, 5.1 KB (added by , 17 years ago) |
---|
-
django/template/__init__.py
diff --git a/django/template/__init__.py b/django/template/__init__.py index 29daa76..3141ce2 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 from django.templatetags import get_templatetags_modules 62 63 63 64 __all__ = ('Template', 'Context', 'RequestContext', 'compile_string') 64 65 … … class Library(object): 910 911 return func 911 912 return dec 912 913 913 def get_library( module_name):914 lib = libraries.get( module_name, None)914 def get_library(library_name, extra_modules=[]): 915 lib = libraries.get(library_name, None) 915 916 if not lib: 916 try: 917 mod = __import__(module_name, {}, {}, ['']) 918 except ImportError, e: 919 raise InvalidTemplateLibrary("Could not load template library from %s, %s" % (module_name, e)) 920 try: 921 lib = mod.register 922 libraries[module_name] = lib 923 except AttributeError: 924 raise InvalidTemplateLibrary("Template library %s does not have a variable named 'register'" % module_name) 917 templatetags_modules = get_templatetags_modules() 918 search_modules = extra_modules + templatetags_modules 919 for m in search_modules: 920 app_label = m.split('.')[-1] 921 "Allow both library_name and app_label.library_name" 922 try: 923 app, library = library_name.split('.') 924 except: 925 app, library = ('', library_name) 926 if not app or app == app_label: 927 try: 928 module_name = '%s.%s' % (m, library) 929 mod = __import__(module_name, {}, {}, ['']) 930 except ImportError: 931 continue 932 else: 933 continue 934 try: 935 lib = mod.register 936 libraries[library_name] = lib 937 except AttributeError: 938 raise InvalidTemplateLibrary("Template library %s does not have a variable named 'register'" % module_name) 939 if not lib: 940 raise InvalidTemplateLibrary("Template library %s not found, tried %s" % (library_name, str(search_modules))) 925 941 return lib 926 942 927 def add_to_builtins(module_name ):928 builtins.append(get_library( module_name))943 def add_to_builtins(module_name, library_name): 944 builtins.append(get_library(library_name, extra_modules=[module_name])) 929 945 930 add_to_builtins('django.template .defaulttags')931 add_to_builtins('django.template .defaultfilters')946 add_to_builtins('django.template', 'defaulttags') 947 add_to_builtins('django.template', 'defaultfilters') -
django/template/defaulttags.py
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index e5a8e66..cd671b9 100644
a b def load(parser, token): 850 850 for taglib in bits[1:]: 851 851 # add the library to the parser 852 852 try: 853 lib = get_library( "django.templatetags.%s" %taglib)853 lib = get_library(taglib) 854 854 parser.add_library(lib) 855 855 except InvalidTemplateLibrary, e: 856 856 raise TemplateSyntaxError("'%s' is not a valid tag library: %s" % -
django/template/loader.py
diff --git a/django/template/loader.py b/django/template/loader.py index 03e6f8d..9cb893c 100644
a b def select_template(template_name_list): 115 115 # If we get here, none of the templates could be loaded 116 116 raise TemplateDoesNotExist, ', '.join(template_name_list) 117 117 118 add_to_builtins('django.template .loader_tags')118 add_to_builtins('django.template', 'loader_tags') -
django/templatetags/__init__.py
diff --git a/django/templatetags/__init__.py b/django/templatetags/__init__.py index 9204535..6e4db0e 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 templatetags_modules = [] 5 6 def get_templatetags_modules(): 7 if not templatetags_modules: 8 for a in ['django'] + list(settings.INSTALLED_APPS): 9 try: 10 name = a + '.templatetags' 11 mod = __import__(name, {}, {}, ['']) 12 templatetags_modules.append(name) 13 except ImportError: 14 pass 15 return templatetags_modules -
tests/regressiontests/templates/tests.py
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py index aef6f50..0490f2a 100644
a b def do_echo(parser, token): 45 45 46 46 register.tag("echo", do_echo) 47 47 48 template.libraries[' django.templatetags.testtags'] = register48 template.libraries['testtags'] = register 49 49 50 50 ##################################### 51 51 # Helper objects for template tests #