Mercurial > kallithea
annotate 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 |
rev | line source |
---|---|
0 | 1 """Pylons environment configuration""" |
2 import logging | |
3 import os | |
12 | 4 |
0 | 5 from mako.lookup import TemplateLookup |
43 | 6 from pylons.configuration import PylonsConfig |
0 | 7 from pylons.error import handle_mako_error |
43 | 8 from sqlalchemy import engine_from_config |
12 | 9 |
0 | 10 import pylons_app.lib.app_globals as app_globals |
11 import pylons_app.lib.helpers | |
12 from pylons_app.config.routing import make_map | |
43 | 13 from pylons_app.model import init_model |
0 | 14 |
15 log = logging.getLogger(__name__) | |
16 | |
17 def load_environment(global_conf, app_conf): | |
18 """Configure the Pylons environment via the ``pylons.config`` | |
19 object | |
20 """ | |
43 | 21 config = PylonsConfig() |
22 | |
0 | 23 # Pylons paths |
24 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
32
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
25 paths = dict(root=root, |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
26 controllers=os.path.join(root, 'controllers'), |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
27 static_files=os.path.join(root, 'public'), |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
28 templates=[os.path.join(root, 'templates')]) |
0 | 29 |
30 # Initialize config with the basic options | |
43 | 31 config.init_app(global_conf, app_conf, package='pylons_app', paths=paths) |
0 | 32 |
43 | 33 config['routes.map'] = make_map(config) |
34 config['pylons.app_globals'] = app_globals.Globals(config) | |
0 | 35 config['pylons.h'] = pylons_app.lib.helpers |
43 | 36 |
37 # Setup cache object as early as possible | |
38 import pylons | |
39 pylons.cache._push_object(config['pylons.app_globals'].cache) | |
40 | |
0 | 41 |
42 # Create the Mako TemplateLookup, with the default auto-escaping | |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
32
diff
changeset
|
43 config['pylons.app_globals'].mako_lookup = TemplateLookup( |
32
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
44 directories=paths['templates'], |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
45 error_handler=handle_mako_error, |
f93b523c0be3
dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents:
12
diff
changeset
|
46 module_directory=os.path.join(app_conf['cache_dir'], 'templates'), |
41
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
32
diff
changeset
|
47 input_encoding='utf-8', default_filters=['escape'], |
71ffa932799d
Added app basic auth.
Marcin Kuzminski <marcin@python-blog.com>
parents:
32
diff
changeset
|
48 imports=['from webhelpers.html import escape']) |
0 | 49 |
43 | 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 | |
0 | 65 # CONFIGURATION OPTIONS HERE (note: all config options will override |
66 # any Pylons config options) | |
43 | 67 |
68 return config |