Changeset 5286
- Timestamp:
- 08/28/08 09:15:30 (4 months ago)
- Files:
-
- trunk/tg/configuration.py (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tg/configuration.py
r5285 r5286 43 43 return AttributeError 44 44 45 class DictWrapper(dict):45 class PylonsConfigWrapper(dict): 46 46 """Simple wrapper for the pylons config object that provides attribute 47 47 style access to the pylons config dictionary. … … 100 100 return get_partial_dict('pylons', self.config_proxy.current_conf()) 101 101 102 config = DictWrapper(pylons_config) 102 #Create a config object that has attribute style lookup built in. 103 config = PylonsConfigWrapper(pylons_config) 103 104 104 105 class Bunch(dict): … … 130 131 that is NECESSARY for proper application function. 131 132 Deployment specific configuration information should go in 132 the config files (eg: development.ini or production.ini)" 133 the config files (eg: development.ini or production.ini) 134 135 AppConfig instances have a number of methods that are meant to be 136 overridden by users who wish to have finer grained controll over 137 the setup of the WSGI envirnment in which their applcation is run. 138 139 This is the place to configure custom routes, transaction handling, 140 error handling, etc. 133 141 """ 134 142 135 143 def __init__(self): 144 """Creates some configuration defaults""" 145 146 #Create a few bunches we know we'll use 147 self.paths = Bunch() 148 self.render_functions = Bunch() 149 150 #Set individual defaults 136 151 self.stand_alone = True 137 152 self.default_renderer = 'genshi' 138 153 self.auth_backend = None 139 154 self.serve_static = True 140 self. paths = Bunch()141 self.render_functions = Bunch() 155 self.use_legacy_render = True 156 142 157 143 158 def setup_paths(self): … … 154 169 155 170 def init_config(self, global_conf, app_conf): 156 # Initialize config with the basic options 171 """Initialize the config object. 172 173 tg.config is a proxy for pylons.config that allows attribute style 174 access, so it's automatically setup when we create the poylons config 175 176 Besides basic initialization, this method copies all the values 177 in base_config into the ``tg.config`` object. 178 """ 157 179 pylons_config.init_app(global_conf, app_conf, 158 180 package=self.package.__name__, … … 192 214 193 215 def setup_mako_renderer(self): 194 # Create the Mako TemplateLookup, with the default auto-escaping216 """Setup a renderer and loader for mako templates""" 195 217 from mako.lookup import TemplateLookup 196 218 from tg.render import render_mako … … 206 228 207 229 def setup_genshi_renderer(self): 208 # Create the Genshi TemplateLoader230 """Setup a renderer and loader for Genshi templates""" 209 231 from genshi.template import TemplateLoader 210 232 from tg.render import render_genshi … … 221 243 222 244 def setup_jinja_renderer(self): 223 # Create the Jinja Environment245 """Setup a renderer and loader for Jinja templates""" 224 246 from jinja import ChoiceLoader, Environment, FileSystemLoader 225 247 from tg.render import render_jinja … … 233 255 234 256 def setup_default_renderer(self): 257 """Setup template defaults in the buffed plugin 258 259 This is only used when use_legacy_renderer is set to True 260 261 And it will not depricated in the next major turbogears 262 release. 263 """ 235 264 #This is specific to buffet, will not be needed later 236 265 config['buffet.template_engines'].pop() … … 240 269 241 270 def setup_sqlalchemy(self): 242 # Setup SQLAlchemy database engine271 """Setup SQLAlchemy database engine""" 243 272 from sqlalchemy import engine_from_config 244 273 engine = engine_from_config(pylons_config, 'sqlalchemy.') … … 287 316 288 317 def add_error_middleware(self, global_conf, app): 289 # Handle Python exceptions318 """Adds middleware which handles errors and exceptions""" 290 319 app = ErrorHandler(app, global_conf, **config['pylons.errorware']) 291 320 … … 299 328 300 329 def add_auth_middleware(self, app): 301 # configure identity Middleware330 """Configure authorization/authentication""" 302 331 from tg.ext.repoze.who.middleware import make_who_middleware 303 332 … … 312 341 313 342 def add_core_middleware(self, app): 343 """Adds support for routes dispatch, sessions, and caching""" 314 344 app = RoutesMiddleware(app, config['routes.map']) 315 345 app = SessionMiddleware(app, config) … … 318 348 319 349 def add_tosca_middleware(self, app): 350 """Configure the ToscaWidgets middleware""" 320 351 app = tw_middleware(app, { 321 352 'toscawidgets.framework.default_view': … … 342 373 343 374 def add_tm_middleware(self, app): 375 """Sets up the transaction managment middleware 376 377 To abort a transaction inside a TG2 app:: 378 379 import transaction 380 transaction.doom() 381 382 By default http error responses also roll back transactions, 383 but this behavior can be overridden by overiding 384 base_config.commit_veto 385 """ 344 386 from repoze.tm import make_tm 345 387 return make_tm(app, self.commit_veto) 346 388 347 389 def add_dbsession_remover_middleware(self, app): 390 """Sets up middleware that cleans up the sqlalchmy session 391 392 The default behavior of TG2 is to clean up the session on 393 every request. Only overide this method if you know what you 394 are doing! 395 396 """ 348 397 def remover(environ, start_response): 349 398 try: