20683db0c9f08b4fa3008cda2220fecdb15280fa
1 """Pylons environment configuration"""
4 from mako
.lookup
import TemplateLookup
5 from pylons
import config
6 from pylons
.error
import handle_mako_error
7 from sqlalchemy
import engine_from_config
9 import floof
.lib
.app_globals
as app_globals
10 import floof
.lib
.helpers
11 from floof
import model
12 from floof
.config
.routing
import make_map
14 def load_environment(global_conf
, app_conf
):
15 """Configure the Pylons environment via the ``pylons.config``
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')])
25 # Initialize config with the basic options
26 config
.init_app(global_conf
, app_conf
, package
='floof', paths
=paths
)
28 config
['routes.map'] = make_map()
29 config
['pylons.app_globals'] = app_globals
.Globals()
30 config
['pylons.h'] = floof
.lib
.helpers
32 # Create the Mako TemplateLookup, with the default auto-escaping
33 config
['pylons.app_globals'].mako_lookup
= TemplateLookup(
34 directories
=paths
['templates'],
35 error_handler
=handle_mako_error
,
36 module_directory
=os
.path
.join(app_conf
['cache_dir'], 'templates'),
37 input_encoding
='utf-8', default_filters
=['escape'],
38 imports
=['from webhelpers.html import escape'])
40 # Setup the SQLAlchemy database engine
41 engine
= engine_from_config(config
, 'sqlalchemy.')
43 if model
.elixir
.options_defaults
.get('autoload'):
44 model
.elixir
.bind
= engine
45 model
.metadata
.bind
= engine
46 model
.elixir
.setup_all()
48 model
.init_model(engine
)
50 model
.meta
.engine
= engine
52 # CONFIGURATION OPTIONS HERE (note: all config options will override
53 # any Pylons config options)