app/django/template/loaders/eggs.py
author Sverre Rabbelier <srabbelier@gmail.com>
Wed, 05 Nov 2008 23:36:28 +0000
changeset 445 31927f21970d
parent 54 03e267d67478
permissions -rw-r--r--
Major site restructuring, also deleting of many unused or obsolete documents The new structure is as follows: <entity>/list - list all <entitie>s <entity>/create - create a new <entity> <entity>/show/<key fields> - public page for <entity> <entity>/edit/<key fields> - edit a <entity> <entity>/delete/key fields> - delete a specific entity

# Wrapper for loading templates from eggs via pkg_resources.resource_string.

try:
    from pkg_resources import resource_string
except ImportError:
    resource_string = None

from django.template import TemplateDoesNotExist
from django.conf import settings

def load_template_source(template_name, template_dirs=None):
    """
    Loads templates from Python eggs via pkg_resource.resource_string.

    For every installed app, it tries to get the resource (app, template_name).
    """
    if resource_string is not None:
        pkg_name = 'templates/' + template_name
        for app in settings.INSTALLED_APPS:
            try:
                return (resource_string(app, pkg_name).decode(settings.FILE_CHARSET), 'egg:%s:%s' % (app, pkg_name))
            except:
                pass
    raise TemplateDoesNotExist, template_name
load_template_source.is_usable = resource_string is not None