| 84 | | If you want to you can just copy and paste this in as a replacement for your environment.py file:: |
|---|
| 85 | | |
|---|
| 86 | | """TurboGears environment configuration""" |
|---|
| 87 | | import os |
|---|
| 88 | | |
|---|
| 89 | | from pylons import config |
|---|
| 90 | | |
|---|
| 91 | | from pylons.i18n import ugettext |
|---|
| 92 | | from genshi.filters import Translator |
|---|
| 93 | | from tg import setup |
|---|
| 94 | | from sqlalchemy import engine_from_config |
|---|
| 95 | | |
|---|
| 96 | | import pyamftest.lib.app_globals as app_globals |
|---|
| 97 | | |
|---|
| 98 | | from routes import Mapper ##### Add this line ######### |
|---|
| 99 | | |
|---|
| 100 | | def make_map(): |
|---|
| 101 | | """Create, configure and return the routes Mapper""" |
|---|
| 102 | | map = Mapper(directory=config['pylons.paths']['controllers'], |
|---|
| 103 | | always_scan=config['debug']) |
|---|
| 104 | | |
|---|
| 105 | | # This route connects your root controller |
|---|
| 106 | | map.connect('gateway', controller = 'gateway') ####### Add this line ######## |
|---|
| 107 | | map.connect('*url', controller='root', action='route') |
|---|
| 108 | | |
|---|
| 109 | | # The ErrorController route (handles 404/500 error pages); it should |
|---|
| 110 | | # likely stay at the top, ensuring it can always be resolved |
|---|
| 111 | | map.connect('error/:action/:id', controller='error') |
|---|
| 112 | | |
|---|
| 113 | | # CUSTOM ROUTES HERE |
|---|
| 114 | | # map.connect(':controller/:action/:id') |
|---|
| 115 | | map.connect('*url', controller='template', action='view') |
|---|
| 116 | | |
|---|
| 117 | | return map |
|---|
| 118 | | |
|---|
| 119 | | def template_loaded(template): |
|---|
| 120 | | "Plug-in our i18n function to Genshi." |
|---|
| 121 | | template.filters.insert(0, Translator(ugettext)) |
|---|
| 122 | | |
|---|
| 123 | | def load_environment(global_conf, app_conf): |
|---|
| 124 | | """Configure the Pylons environment via the ``pylons.config`` |
|---|
| 125 | | object |
|---|
| 126 | | """ |
|---|
| 127 | | # Pylons paths |
|---|
| 128 | | root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
|---|
| 129 | | paths = dict(root=root, |
|---|
| 130 | | controllers=os.path.join(root, 'controllers'), |
|---|
| 131 | | static_files=os.path.join(root, 'public'), |
|---|
| 132 | | templates=[os.path.join(root, 'templates')]) |
|---|
| 133 | | |
|---|
| 134 | | # This setups up a set of default route that enables a standard |
|---|
| 135 | | # TG2 style object dispatch. Fell free to overide it with |
|---|
| 136 | | # custom routes. TODO: Link to TG2+routes doc. |
|---|
| 137 | | |
|---|
| 138 | | # Initialize config with the basic options |
|---|
| 139 | | config.init_app(global_conf, app_conf, package='pyamftest', |
|---|
| 140 | | template_engine='genshi', paths=paths) |
|---|
| 141 | | config['routes.map'] = make_map() |
|---|
| 142 | | config['pylons.g'] = app_globals.Globals() |
|---|
| 143 | | config['pylons.g'].sa_engine = engine_from_config(config, 'sqlalchemy.') |
|---|
| 144 | | |
|---|
| 145 | | # Customize templating options via this variable |
|---|
| 146 | | tmpl_options = config['buffet.template_options'] |
|---|
| 147 | | tmpl_options['genshi.loader_callback'] = template_loaded |
|---|
| 148 | | |
|---|
| 149 | | # CONFIGURATION OPTIONS HERE (note: all config options will override |
|---|
| 150 | | # any Pylons config options) |
|---|
| 151 | | |
|---|
| 152 | | from pyamftest import model |
|---|
| 153 | | model.DBSession.configure(bind=config['pylons.g'].sa_engine) |
|---|
| 154 | | model.metadata.bind = config['pylons.g'].sa_engine |
|---|