django-dbtemplates/dbtemplates/loader.py
leidel bbc00a779b again: refactoring as a standalone application
git-svn-id: https://django-dbtemplates.googlecode.com/svn/trunk@12 cfb8ba98-e953-0410-9cff-959ffddf5974

committer: leidel <leidel@cfb8ba98-e953-0410-9cff-959ffddf5974>

--HG--
extra : convert_revision : 5fc12102108671ddb3b9890c9091bd39cb446728
2007-07-20 14:30:48 +00:00

23 lines
No EOL
792 B
Python

from django.conf import settings
from django.template import TemplateDoesNotExist
from django.contrib.dbtemplates.models import Template
from django.contrib.sites.models import Site
try:
site = Site.objects.get_current()
except:
site = None
def load_template_source(template_name, template_dirs=None):
"""
Loads templates from the database by querying the database field ``name``
with a template path and ``sites`` with the current site.
"""
if site is not None:
try:
t = Template.objects.get(name__exact=template_name, sites__pk=site.id)
return (t.content, 'db:%s:%s' % (settings.DATABASE_ENGINE, template_name))
except:
pass
raise TemplateDoesNotExist, template_name
load_template_source.is_usable = True