Ticket #1675: ticket_1675.diff

File ticket_1675.diff, 2.4 KB (added by shs, 9 years ago)

fix for magic-removal branch. This implementation uses the settings.INSTALLED_APPS list to generate the search path for custom template tags

  • django/template/__init__.py

     
    861861        try:
    862862            mod = __import__(module_name, '', '', [''])
    863863        except ImportError, e:
    864             raise InvalidTemplateLibrary, "Could not load template library from %s, %s" % (module_name, e)
     864            raise ImportError, "Could not load template library from %s, %s" % (module_name, e)
    865865        try:
    866866            lib = mod.register
    867867            libraries[module_name] = lib
     
    869869            raise InvalidTemplateLibrary, "Template library %s does not have a variable named 'register'" % module_name
    870870    return lib
    871871
     872templatetag_searchpath = [ "django" ]
     873templatetag_searchpath.extend( settings.INSTALLED_APPS )
     874
    872875def add_to_builtins(module_name):
    873876    builtins.append(get_library(module_name))
    874877
    875878add_to_builtins('django.template.defaulttags')
    876879add_to_builtins('django.template.defaultfilters')
     880
     881
     882
  • django/template/defaulttags.py

     
    33from django.template import Node, NodeList, Template, Context, resolve_variable
    44from django.template import TemplateSyntaxError, VariableDoesNotExist, BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END
    55from django.template import get_library, Library, InvalidTemplateLibrary
     6from django.template import templatetag_searchpath
    67from django.conf import settings
    78import sys
    89
     
    645646    bits = token.contents.split()
    646647    for taglib in bits[1:]:
    647648        # add the library to the parser
    648         try:
    649             lib = get_library("django.templatetags.%s" % taglib.split('.')[-1])
     649
     650        lib = None
     651        for app in templatetag_searchpath:
     652            try:
     653                lib = get_library("%s.templatetags.%s" % (app,taglib))
     654            except ImportError,e:
     655                continue
    650656            parser.add_library(lib)
    651         except InvalidTemplateLibrary, e:
    652             raise TemplateSyntaxError, "'%s' is not a valid tag library: %s" % (taglib, e)
     657            break
     658        if not lib:
     659            raise InvalidTemplateLibrary, "'%s' is not a valid tag library" % (taglib,)
    653660    return LoadNode()
    654661load = register.tag(load)
    655662
Back to Top