mirror of
https://github.com/jazzband/django-dbtemplates.git
synced 2026-05-03 13:14:47 +00:00
Fixed wrong return types in FileSystemBackend. git-svn-id: https://django-dbtemplates.googlecode.com/svn/trunk@59 cfb8ba98-e953-0410-9cff-959ffddf5974 committer: leidel <leidel@cfb8ba98-e953-0410-9cff-959ffddf5974> --HG-- extra : convert_revision : 7ea05e043c43c23fbf846bc9ddd80400519631e2
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
import os
|
|
from django.conf import settings
|
|
from django.template import TemplateDoesNotExist
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
|
from dbtemplates.models import Template, backend
|
|
|
|
def load_template_source(template_name, template_dirs=None):
|
|
"""
|
|
Tries to load the template from the dbtemplates cache backend specified
|
|
by the DBTEMPLATES_CACHE_BACKEND setting. If it does not find a template
|
|
it falls back to query the database field ``name`` with the template path
|
|
and ``sites`` with the current site.
|
|
"""
|
|
display_name = 'db:%s:%s' % (settings.DATABASE_ENGINE, template_name)
|
|
if backend:
|
|
try:
|
|
backend_template = backend.load(template_name)
|
|
if backend_template is not None:
|
|
return backend_template, template_name
|
|
except:
|
|
pass
|
|
try:
|
|
template = Template.objects.get(name__exact=template_name,
|
|
sites__pk=settings.SITE_ID)
|
|
return (template.content, display_name)
|
|
except:
|
|
pass
|
|
raise TemplateDoesNotExist, template_name
|
|
load_template_source.is_usable = True
|