PageRenderTime 63ms CodeModel.GetById 22ms RepoModel.GetById 19ms app.codeStats 0ms

/shabti/templates/quickwiki/+package+/config/environment.py_tmpl

https://bitbucket.org/gawel/shabti
Unknown | 53 lines | 42 code | 11 blank | 0 comment | 0 complexity | a2fcb5a399e346b3c4de3bd0df459fe5 MD5 | raw file
  1. """Pylons environment configuration"""
  2. import os
  3. from mako.lookup import TemplateLookup
  4. from pylons.configuration import PylonsConfig
  5. from pylons.error import handle_mako_error
  6. from sqlalchemy import engine_from_config
  7. import {{package}}.lib.app_globals as app_globals
  8. import {{package}}.lib.helpers
  9. from {{package}}.config.routing import make_map
  10. from {{package}}.model import init_model
  11. def load_environment(global_conf, app_conf):
  12. """Configure the Pylons environment via the ``pylons.config``
  13. object
  14. """
  15. config = PylonsConfig()
  16. # Pylons paths
  17. root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  18. paths = dict(root=root,
  19. controllers=os.path.join(root, 'controllers'),
  20. static_files=os.path.join(root, 'public'),
  21. templates=[os.path.join(root, 'templates')])
  22. # Initialize config with the basic options
  23. config.init_app(global_conf, app_conf, package='{{package}}', paths=paths)
  24. config['routes.map'] = make_map(config)
  25. config['pylons.app_globals'] = app_globals.Globals(config)
  26. config['pylons.h'] = {{package}}.lib.helpers
  27. # Setup cache object as early as possible
  28. import pylons
  29. pylons.cache._push_object(config['pylons.app_globals'].cache)
  30. # Create the Mako TemplateLookup, with the default auto-escaping
  31. config['pylons.app_globals'].mako_lookup = TemplateLookup(
  32. directories=paths['templates'],
  33. error_handler=handle_mako_error,
  34. module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
  35. input_encoding='utf-8', default_filters=['escape'],
  36. imports=['from webhelpers.html import escape'])
  37. # Setup the SQLAlchemy database engine
  38. engine = engine_from_config(config, 'sqlalchemy.')
  39. init_model(engine)
  40. # CONFIGURATION OPTIONS HERE (note: all config options will override
  41. # any Pylons config options)
  42. return config