| 1 | """Wrapper for loading templates from eggs via pkg_resources.resource_string.""" |
| 2 | |
| 3 | try: |
| 4 | from pkg_resources import resource_string |
| 5 | except ImportError: |
| 6 | # python2.3 compatibility hack |
| 7 | def resource_string(*args): |
| 8 | raise AssertionError, 'pkg_resource required for template_eggs' |
| 9 | |
| 10 | from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION |
| 11 | from django.core.template import TemplateDoesNotExist |
| 12 | |
| 13 | def 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 |