-
Notifications
You must be signed in to change notification settings - Fork 0
/
loaders.py
26 lines (20 loc) · 860 Bytes
/
loaders.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
from django.conf import settings
from django.template.loaders.base import Loader as BaseLoader
from django.template import TemplateDoesNotExist
from django_blog_it.models import Theme
class Loader(BaseLoader):
is_usable = True
def load_template_source(self, template_name, template_dirs=None):
themes = Theme.objects.filter(enabled=True)
for theme in themes:
filepath = os.path.join(os.path.dirname(__file__), 'themes', theme.name, 'templates', template_name)
try:
file = open(filepath)
try:
return (file.read().decode(settings.FILE_CHARSET), filepath)
finally:
file.close()
except IOError:
pass
raise TemplateDoesNotExist("Could not find template '%s'." % template_name)