2005-10-15 06:22:12 +08:00
|
|
|
# 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.core.template import TemplateDoesNotExist
|
|
|
|
from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION
|
|
|
|
|
2005-10-17 09:53:22 +08:00
|
|
|
def load_template_source(template_name, template_dirs=None):
|
2005-10-15 06:22:12 +08:00
|
|
|
"""
|
|
|
|
Loads templates from Python eggs via pkg_resource.resource_string.
|
|
|
|
|
2005-10-17 09:53:22 +08:00
|
|
|
For every installed app, it tries to get the resource (app, template_name).
|
2005-10-15 06:22:12 +08:00
|
|
|
"""
|
|
|
|
if resource_string is not None:
|
2005-10-17 09:53:22 +08:00
|
|
|
pkg_name = 'templates/' + template_name + TEMPLATE_FILE_EXTENSION
|
2005-10-15 06:22:12 +08:00
|
|
|
for app in INSTALLED_APPS:
|
|
|
|
try:
|
2005-11-24 07:10:17 +08:00
|
|
|
return (resource_string(app, pkg_name), 'egg:%s:%s ' % (app, pkg_name))
|
2005-10-15 06:22:12 +08:00
|
|
|
except:
|
|
|
|
pass
|
2005-10-17 09:53:22 +08:00
|
|
|
raise TemplateDoesNotExist, template_name
|
2005-10-15 06:22:12 +08:00
|
|
|
load_template_source.is_usable = resource_string is not None
|