0
|
1 """Pylons environment configuration"""
|
|
2 import logging
|
|
3 import os
|
12
|
4
|
0
|
5 from mako.lookup import TemplateLookup
|
|
6 from pylons.error import handle_mako_error
|
12
|
7 from pylons import config
|
|
8
|
0
|
9 import pylons_app.lib.app_globals as app_globals
|
|
10 import pylons_app.lib.helpers
|
|
11 from pylons_app.config.routing import make_map
|
|
12
|
|
13 log = logging.getLogger(__name__)
|
|
14
|
|
15 def load_environment(global_conf, app_conf):
|
|
16 """Configure the Pylons environment via the ``pylons.config``
|
|
17 object
|
|
18 """
|
|
19 # Pylons paths
|
|
20 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
21 paths = dict(root = root,
|
|
22 controllers = os.path.join(root, 'controllers'),
|
|
23 static_files = os.path.join(root, 'public'),
|
|
24 templates = [os.path.join(root, 'templates')])
|
|
25
|
|
26 # Initialize config with the basic options
|
|
27 config.init_app(global_conf, app_conf, package = 'pylons_app',
|
|
28 template_engine = 'mako', paths = paths)
|
|
29
|
|
30 config['routes.map'] = make_map()
|
|
31 config['pylons.g'] = app_globals.Globals()
|
|
32 config['pylons.h'] = pylons_app.lib.helpers
|
|
33
|
|
34 # Create the Mako TemplateLookup, with the default auto-escaping
|
|
35 config['pylons.g'].mako_lookup = TemplateLookup(
|
|
36 directories = paths['templates'],
|
|
37 error_handler = handle_mako_error,
|
|
38 module_directory = os.path.join(app_conf['cache_dir'], 'templates'),
|
12
|
39 input_encoding = 'utf-8', output_encoding = 'utf-8',
|
|
40 imports = ['from webhelpers.html import escape'],
|
|
41 default_filters = ['escape'])
|
0
|
42
|
|
43 # CONFIGURATION OPTIONS HERE (note: all config options will override
|
|
44 # any Pylons config options)
|