from jinja2 import Environment FileSystemLoader from svarga core excep

 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from jinja2 import Environment, FileSystemLoader
from svarga.core.exceptions import ImproperlyConfigured
from svarga.core.env import env
class LocalSettingsProvider(object):
paths = []
def __init__(self):
self.jinja_env = None
"""Create jinja2 environment using configuration settings."""
def _create_env(self):
template_path = getattr(env.settings, 'TEMPLATE_PATH', None)
if template_path is not None:
self.paths.extend([template_path])
# Get any user supplied extensions (if any)
extensions = getattr(env.settings, 'JINJA_EXTENSIONS', [])
extensions.extend(['svarga.template.tags.UrlReverseExtension'])
return Environment(loader=FileSystemLoader(self.paths),
extensions=extensions)
def apply(self):
if self.jinja_env is None:
self.jinja_env = self._create_env()
env.jinja = self.jinja_env
class AppSettingsProvider(object):
def __init__(self, apps):
for app, config in apps.iteritems():
# TODO: add path to the LocalSettingsProvider
def appcontribute(app_settings):
def add_path(self, path):
LocalSettingsProvider.paths.append(path)
app_settings.add_template_path = add_path
return AppSettingsManager