On Tue, 2005-11-15 at 17:31 -0500, Jonathan LaCour wrote:
> Maybe this could be handled sort of like validators?
>
> @turbogears.expose(transaction=True,
> err_map={Exception : 'generic msg',
> SQLObjectNotFound : 'specific msg'}
> def my_method(self):
> frob = frobbler.frobble()
> return dict(frob=frob)
>
> On an exception being raised, the transaction would automatically be
> rolled back, and the appropriate error message would be flashed on
> the page. Just thinking out loud, and this obviously isn't perfect.
> But, its an important wrinkle to figure out.
I would recommend you put this in a separate decorator like this:
@turbogears.expose(...)
@exception_flash({Exception: 'generic msg'})
def mymethod(self):
... etc ...
It may be cool to have an exception_flash decorator built in to
turbogears. Though I really wish cherrypy had an event system or better
filtering system so we didn't have to push all of this functionality
into decorators.
Sean