tags:

views:

63

answers:

1

I'm trying to implement a decorator for custom error pages in web2py as per one of the haiti Todos. Ref - http://web2py.com/AlterEgo/default/show/75

I'm trying to keep it as a module in /modules directory so that I can import it into the controllers and place the decorator appropriately.

I have kept error handling decorator as /modules/onerror.py

and am importing it like this from a controller say (or.py)-

exec('from applications.%s.modules.onerror import onerror as onerror'
                                                       % request.application)

HTTP object wasn't available in onerror.py so i did a -

from gluon.http import *

But then I readlized that the request object is also not available to the decorator as in the line -

filename=os.path.join(request.folder,'views/errors/error%i.html'%status)

I have some doubts -

  1. Is /modules directory a good place to keep such a reusable component?

  2. Are the modules in the /modules directory automatically loaded as a new web2py instance is created? If so how can I access them in a controller?

  3. Is there a way I can pass the request object to this decorator from my controller? Hints are welcome.

My current onerror.py - http://paste.pocoo.org/show/186165/ The way I'm trying to use in a controller - http://paste.pocoo.org/show/186167/

Let me know if I'm doing it in an unobvious way.