PageRenderTime 51ms CodeModel.GetById 34ms RepoModel.GetById 4ms app.codeStats 0ms

/minger_plus/config/environment.py

https://bitbucket.org/bwmcadams/mingerplus
Python | 45 lines | 27 code | 9 blank | 9 comment | 0 complexity | feefe98e007b937572ba63487ba9e48b MD5 | raw file
  1. """Pylons environment configuration"""
  2. import os
  3. from mako.lookup import TemplateLookup
  4. from paste.deploy.converters import asbool
  5. from pylons import config
  6. from pylons.error import handle_mako_error
  7. from mongokit.ext.pylons_env import MongoPylonsEnv
  8. import minger_plus.lib.app_globals as app_globals
  9. import minger_plus.lib.helpers
  10. from minger_plus.config.routing import make_map
  11. def load_environment(global_conf, app_conf):
  12. """Configure the Pylons environment via the ``pylons.config``
  13. object
  14. """
  15. # Pylons paths
  16. root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  17. paths = dict(root=root,
  18. controllers=os.path.join(root, 'controllers'),
  19. static_files=os.path.join(root, 'public'),
  20. templates=[os.path.join(root, 'templates')])
  21. # Initialize config with the basic options
  22. config.init_app(global_conf, app_conf, package='minger_plus', paths=paths)
  23. config['routes.map'] = make_map()
  24. config['pylons.app_globals'] = app_globals.Globals()
  25. config['pylons.h'] = minger_plus.lib.helpers
  26. # Create the Mako TemplateLookup, with the default auto-escaping
  27. config['pylons.app_globals'].mako_lookup = TemplateLookup(
  28. directories=paths['templates'],
  29. error_handler=handle_mako_error,
  30. module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
  31. input_encoding='utf-8', default_filters=['escape'],
  32. imports=['from webhelpers.html import escape'],
  33. filesystem_checks=asbool(config['debug']))
  34. # CONFIGURATION OPTIONS HERE (note: all config options will override
  35. # any Pylons config options)
  36. MongoPylonsEnv.init_mongo()