Mercurial > kallithea
comparison pylons_app/config/environment.py @ 43:2e1247e62c5b
changed for pylons 0.1 / 1.0
added admin controller
author | marcink |
---|---|
date | Wed, 07 Apr 2010 15:28:50 +0200 |
parents | 71ffa932799d |
children | 3ada2f409c1c |
comparison
equal
deleted
inserted
replaced
42:b2bc08f2974b | 43:2e1247e62c5b |
---|---|
1 """Pylons environment configuration""" | 1 """Pylons environment configuration""" |
2 import logging | 2 import logging |
3 import os | 3 import os |
4 | 4 |
5 from mako.lookup import TemplateLookup | 5 from mako.lookup import TemplateLookup |
6 from pylons.configuration import PylonsConfig | |
6 from pylons.error import handle_mako_error | 7 from pylons.error import handle_mako_error |
7 from pylons import config | 8 from sqlalchemy import engine_from_config |
8 | 9 |
9 import pylons_app.lib.app_globals as app_globals | 10 import pylons_app.lib.app_globals as app_globals |
10 import pylons_app.lib.helpers | 11 import pylons_app.lib.helpers |
11 from pylons_app.config.routing import make_map | 12 from pylons_app.config.routing import make_map |
13 from pylons_app.model import init_model | |
12 | 14 |
13 log = logging.getLogger(__name__) | 15 log = logging.getLogger(__name__) |
14 | 16 |
15 def load_environment(global_conf, app_conf): | 17 def load_environment(global_conf, app_conf): |
16 """Configure the Pylons environment via the ``pylons.config`` | 18 """Configure the Pylons environment via the ``pylons.config`` |
17 object | 19 object |
18 """ | 20 """ |
21 config = PylonsConfig() | |
22 | |
19 # Pylons paths | 23 # Pylons paths |
20 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 24 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
21 paths = dict(root=root, | 25 paths = dict(root=root, |
22 controllers=os.path.join(root, 'controllers'), | 26 controllers=os.path.join(root, 'controllers'), |
23 static_files=os.path.join(root, 'public'), | 27 static_files=os.path.join(root, 'public'), |
24 templates=[os.path.join(root, 'templates')]) | 28 templates=[os.path.join(root, 'templates')]) |
25 | 29 |
26 # Initialize config with the basic options | 30 # Initialize config with the basic options |
27 config.init_app(global_conf, app_conf, package='pylons_app', | 31 config.init_app(global_conf, app_conf, package='pylons_app', paths=paths) |
28 template_engine='mako', paths=paths) | |
29 | 32 |
30 config['routes.map'] = make_map() | 33 config['routes.map'] = make_map(config) |
31 config['pylons.app_globals'] = app_globals.Globals() | 34 config['pylons.app_globals'] = app_globals.Globals(config) |
32 config['pylons.h'] = pylons_app.lib.helpers | 35 config['pylons.h'] = pylons_app.lib.helpers |
36 | |
37 # Setup cache object as early as possible | |
38 import pylons | |
39 pylons.cache._push_object(config['pylons.app_globals'].cache) | |
40 | |
33 | 41 |
34 # Create the Mako TemplateLookup, with the default auto-escaping | 42 # Create the Mako TemplateLookup, with the default auto-escaping |
35 config['pylons.app_globals'].mako_lookup = TemplateLookup( | 43 config['pylons.app_globals'].mako_lookup = TemplateLookup( |
36 directories=paths['templates'], | 44 directories=paths['templates'], |
37 error_handler=handle_mako_error, | 45 error_handler=handle_mako_error, |
38 module_directory=os.path.join(app_conf['cache_dir'], 'templates'), | 46 module_directory=os.path.join(app_conf['cache_dir'], 'templates'), |
39 input_encoding='utf-8', default_filters=['escape'], | 47 input_encoding='utf-8', default_filters=['escape'], |
40 imports=['from webhelpers.html import escape']) | 48 imports=['from webhelpers.html import escape']) |
41 | 49 |
50 #sets the c attribute access when don't existing attribute ar accessed | |
51 config['pylons.strict_tmpl_context'] = False | |
52 | |
53 #MULTIPLE DB configs | |
54 # Setup the SQLAlchemy database engine | |
55 # if config['debug']: | |
56 # #use query time debugging. | |
57 # from pylons_app.lib.timer_proxy import TimerProxy | |
58 # sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.', | |
59 # proxy=TimerProxy()) | |
60 # else: | |
61 # sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.') | |
62 | |
63 #init_model(sa_engine_db1) | |
64 | |
42 # CONFIGURATION OPTIONS HERE (note: all config options will override | 65 # CONFIGURATION OPTIONS HERE (note: all config options will override |
43 # any Pylons config options) | 66 # any Pylons config options) |
67 | |
68 return config |