Ticket #582: template_eggs.patch

File template_eggs.patch, 1.8 KB (added by sune.kirkeby@…, 19 years ago)
  • django/core/template_eggs.py

     
     1"""Wrapper for loading templates from eggs via pkg_resources.resource_string."""
     2
     3try:
     4    from pkg_resources import resource_string
     5except ImportError:
     6    # python2.3 compatibility hack
     7    def resource_string(*args):
     8        raise AssertionError, 'pkg_resource required for template_eggs'
     9
     10from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION
     11from django.core.template import TemplateDoesNotExist
     12
     13def load_template_source(name, dirs=None):
     14    """I load templates from Python eggs via pkg_resource.resource_string.
     15
     16    For every install app I try to get the resource (app, name)."""
     17
     18    pkg_name = 'templates/' + name + TEMPLATE_FILE_EXTENSION
     19
     20    for app in INSTALLED_APPS:
     21        try:
     22            return resource_string(app, pkg_name)
     23        except:
     24            pass
     25
     26    raise TemplateDoesNotExist, name
  • django/core/template_loader.py

     
    11"Wrapper for loading templates from storage of some sort (e.g. files or db)"
    22import template
    3 from template_file import load_template_source
     3import template_file
     4import template_eggs
    45
     6template_source_loaders = [
     7    template_file.load_template_source,
     8    template_eggs.load_template_source,
     9]
     10def load_template_source(name, dirs=None):
     11    for loader in template_source_loaders:
     12        try:
     13            return loader(name, dirs)
     14        except:
     15            pass
     16    raise template.TemplateDoesNotExist, name
     17
    518class ExtendsError(Exception):
    619    pass
    720
Back to Top