]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/config/environment.py
We have pie charts.
[bluechips.git] / bluechips / config / environment.py
1 """Pylons environment configuration"""
2 import os
3
4 from mako.lookup import TemplateLookup
5 from pylons import config
6 from sqlalchemy import engine_from_config
7 from mailer import Mailer
8
9 import bluechips.lib.app_globals as app_globals
10 import bluechips.lib.helpers
11 from bluechips.config.routing import make_map
12 from bluechips.model import init_model
13
14 def load_environment(global_conf, app_conf):
15     """Configure the Pylons environment via the ``pylons.config``
16     object
17     """
18     # Pylons paths
19     root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
20     paths = dict(root=root,
21                  controllers=os.path.join(root, 'controllers'),
22                  static_files=os.path.join(root, 'public'),
23                  templates=[os.path.join(root, 'templates')])
24
25     # Initialize config with the basic options
26     config.init_app(global_conf, app_conf, package='bluechips', paths=paths)
27
28     config['routes.map'] = make_map()
29     config['pylons.app_globals'] = app_globals.Globals()
30     config['pylons.h'] = bluechips.lib.helpers
31
32     # Create the Mako TemplateLookup, with the default auto-escaping
33     config['pylons.app_globals'].mako_lookup = TemplateLookup(
34         directories=paths['templates'],
35         module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
36         input_encoding='utf-8', output_encoding='utf-8',
37         imports=['from webhelpers.html import escape'],
38         default_filters=['escape'])
39     
40     # Setup SQLAlchemy database engine
41     engine = engine_from_config(config, 'sqlalchemy.')
42     init_model(engine)
43     
44     # CONFIGURATION OPTIONS HERE (note: all config options will override
45     # any Pylons config options)
46     config['pylons.app_globals'].mailer = Mailer(config.get('mailer.host',
47                                                             '127.0.0.1'))