annotate pylons_app/config/environment.py @ 368:e9a6783f5502

fixed user permissions bug when adding permissions to user who couldn load those because of auth decorators Small fix for hg model and injecting dbrepo into cached repos
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 27 Jul 2010 14:54:41 +0200
parents ec7b76d4bda4
children 3bcf9529d221
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
1 """Pylons environment configuration"""
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
2 from mako.lookup import TemplateLookup
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
3 from pylons.configuration import PylonsConfig
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
4 from pylons.error import handle_mako_error
239
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 107
diff changeset
5 from pylons_app.config.routing import make_map
309
7e4771a0ff43 added base path into config
Marcin Kuzminski <marcin@python-works.com>
parents: 300
diff changeset
6 from pylons_app.lib.auth import set_available_permissions, set_base_path
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 309
diff changeset
7 from pylons_app.lib.utils import repo2db_mapper, make_ui, set_hg_app_config
239
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 107
diff changeset
8 from pylons_app.model import init_model
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
9 from pylons_app.model.hg_model import _get_repos_cached_initial
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
10 from sqlalchemy import engine_from_config
239
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 107
diff changeset
11 import logging
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 107
diff changeset
12 import os
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
13 import pylons_app.lib.app_globals as app_globals
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
14 import pylons_app.lib.helpers
239
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 107
diff changeset
15
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
16 log = logging.getLogger(__name__)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
17
365
ec7b76d4bda4 Added initial query skipp when seting up the app.
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
18 def load_environment(global_conf, app_conf, initial=False):
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
19 """Configure the Pylons environment via the ``pylons.config``
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
20 object
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
21 """
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
22 config = PylonsConfig()
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
23
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
24 # Pylons paths
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
25 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
26 paths = dict(root=root,
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 12
diff changeset
27 controllers=os.path.join(root, 'controllers'),
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 12
diff changeset
28 static_files=os.path.join(root, 'public'),
f93b523c0be3 dirty fix for multiple file encodings,
Marcin Kuzminski <marcin@python-blog.com>
parents: 12
diff changeset
29 templates=[os.path.join(root, 'templates')])
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
30
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
31 # Initialize config with the basic options
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
32 config.init_app(global_conf, app_conf, package='pylons_app', paths=paths)
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
33
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
34 config['routes.map'] = make_map(config)
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
35 config['pylons.app_globals'] = app_globals.Globals(config)
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
36 config['pylons.h'] = pylons_app.lib.helpers
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
37
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
38 # Setup cache object as early as possible
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
39 import pylons
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
40 pylons.cache._push_object(config['pylons.app_globals'].cache)
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
41
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
49
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 239
diff changeset
50 #sets the c attribute access when don't existing attribute are accessed
107
5e2470ebdbc6 Added repo switcher, in base and long term caching for this.
Marcin Kuzminski <marcin@python-works.com>
parents: 49
diff changeset
51 config['pylons.strict_tmpl_context'] = True
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
52
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
53 #MULTIPLE DB configs
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
54 # Setup the SQLAlchemy database engine
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
55 if config['debug']:
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
56 #use query time debugging.
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
57 from pylons_app.lib.timerproxy import TimerProxy
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
58 sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.',
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
59 proxy=TimerProxy())
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
60 else:
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
61 sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.')
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
62
49
3ada2f409c1c Added sqlalchemy support
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
63 init_model(sa_engine_db1)
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 309
diff changeset
64 config['pylons.app_globals'].baseui = make_ui('db')
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 309
diff changeset
65
365
ec7b76d4bda4 Added initial query skipp when seting up the app.
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
66 repo2db_mapper(_get_repos_cached_initial(config['pylons.app_globals'], initial))
239
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 107
diff changeset
67 set_available_permissions(config)
309
7e4771a0ff43 added base path into config
Marcin Kuzminski <marcin@python-works.com>
parents: 300
diff changeset
68 set_base_path(config)
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 309
diff changeset
69 set_hg_app_config(config)
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
70 # CONFIGURATION OPTIONS HERE (note: all config options will override
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
71 # any Pylons config options)
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
72
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 41
diff changeset
73 return config