X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=bluechips%2Flib%2Fbase.py;h=259bb0dd5613f8c1c43980ef1964ddf7dda08a8c;hb=1e4dfac7ed0c6a2c8d23f82d2ca071a27401abcf;hp=d33cfc2034b901e29bfa09a2b895270045c538a8;hpb=f8814994349f84b9636c22e75c75e02511a8eb36;p=bluechips.git diff --git a/bluechips/lib/base.py b/bluechips/lib/base.py index d33cfc2..259bb0d 100644 --- a/bluechips/lib/base.py +++ b/bluechips/lib/base.py @@ -2,11 +2,20 @@ Provides the BaseController class for subclassing. """ +from pylons import tmpl_context as c from pylons.controllers import WSGIController +from pylons.i18n import _, ungettext, N_ from pylons.templating import render_mako as render +from tw.mods.pylonshf import validate, valid + +import bluechips.lib.helpers as h +from bluechips import model from bluechips.model import meta +from paste.request import construct_url +from paste.httpexceptions import HTTPMovedPermanently + class BaseController(WSGIController): def __call__(self, environ, start_response): @@ -14,8 +23,26 @@ class BaseController(WSGIController): # WSGIController.__call__ dispatches to the Controller method # the request is routed to. This routing information is # available in environ['pylons.routes_dict'] + if environ['pylons.routes_dict']['controller'] != 'error': + if environ['PATH_INFO'].endswith('/index'): + environ['PATH_INFO'] = environ['PATH_INFO'][:-5] + raise HTTPMovedPermanently(construct_url(environ)) + if not environ['PATH_INFO'].endswith('/') and \ + environ['pylons.routes_dict']['action'] == 'index': + environ['PATH_INFO'] += '/' + raise HTTPMovedPermanently(construct_url(environ)) try: return WSGIController.__call__(self, environ, start_response) finally: meta.Session.remove() - \ No newline at end of file + +def update_sar(record, form_result): + """ + Update a SQLAlchemy record with the results of a validated form submission + """ + for key, value in form_result.items(): + setattr(record, key, value) + +__all__ = ['c', 'h', 'render', 'validate', 'valid', + 'model', 'meta', '_', 'ungettext', 'N_', 'BaseController', + 'update_sar']