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
|
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
from django.template import TemplateDoesNotExist
|
|
|
|
from django.conf import settings
|
2005-10-15 06:22:12 +08:00
|
|
|
|
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:
|
2006-05-02 09:31:56 +08:00
|
|
|
pkg_name = 'templates/' + template_name
|
|
|
|
for app in settings.INSTALLED_APPS:
|
2005-10-15 06:22:12 +08:00
|
|
|
try:
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
return (resource_string(app, pkg_name), 'egg:%s:%s ' % (app, pkg_name)).decode(settings.FILE_CHARSET)
|
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
|