Richard, Thanks for the hints.
You can pass the response object to a module directly, without using current. I have other modules that work this way; the only problem is the long parms list. I know the html imports are working correctly because the form renders. I suspect the http imports are working because no exception gets raised and the the traceback points to gluon/http.py. So it must be imported. On Mar 8, 11:21 am, Richard Vézina <[email protected]> wrote: > You may check if those import are working properly : > > from html import FORM, H2, P, BR, INPUT, URL > from http import HTTP, redirect > > Could it be possible that it should be import like this : > > from gluon.html import FORM?? > > Richard > > On Thu, Mar 8, 2012 at 11:09 AM, Richard Vézina <[email protected] > > > > > > > > > wrote: > > I think you will need to read a bit about current, current.response, > > current.request, etc. > > > Richard > > > On Thu, Mar 8, 2012 at 11:04 AM, Cliff <[email protected]> wrote: > > >> What am I doing wrong? > > >> This code works fine in a controller. When moved to a module it fails > >> with a 303 error. > >> Here is the code: > > >> ### Controller: > >> def trash(): > >> import trash_it > >> return trash_it.trashit(request, session,response, db) > > >> ## module trash_it.py > >> from html import FORM, H2, P, BR, INPUT, URL > >> from http import HTTP, redirect > > >> def trashit(request, session, response, db): > >> import crumbs > >> crumb_trail = crumbs.do_crumbs(session, request, db) > >> form = FORM( > >> H2('Are you sure?'), > >> P('Do you really want to move the item to the trash?'), > >> BR(), > >> INPUT(_type='submit', _name='yes', _value='Yes, trash it', > >> _style='margin-right:1em' > >> ), > >> INPUT(_type='submit', _name='no', _value='No'), > >> ) > >> response.view = 'are_you_sure.html' > > >> if form.accepts(request, session): > >> if 'yes' in request.post_vars: > >> db[request.controller][request.args(0)] = > >> dict(is_active=False) > >> session.flash = 'Item moved to trash.' > >> redirect(URL(request.application, request.controller, > >> 'index')) > >> elif 'no' in request.post_vars: > >> session.flash = 'Trash cancelled.' > >> redirect(URL(request.application, request.controller, > >> 'index')) > >> else: > >> response.flash = 'Just checking.' > > >> return dict( form=form, crumb_trail=crumb_trail) > > >> # The traceback > > >> Traceback (most recent call last): > >> File "/media/Myfiles/3-o/gluon/main.py", line 493, in wsgibase > >> serve_controller(request, response, session) > >> File "/media/Myfiles/3-o/gluon/main.py", line 202, in > >> serve_controller > >> page = run_controller_in(request.controller, request.function, > >> environment) > >> File "/media/Myfiles/3-o/gluon/compileapp.py", line 537, in > >> run_controller_in > >> restricted(code, environment, filename) > >> File "/media/Myfiles/3-o/gluon/restricted.py", line 204, in > >> restricted > >> exec ccode in environment > >> File "/media/Myfiles/3-o/applications/operations/controllers/ > >> buckslips.py", line 344, in <module> > >> File "/media/Myfiles/3-o/gluon/globals.py", line 172, in <lambda> > >> self._caller = lambda f: f() > >> File "/media/Myfiles/3-o/applications/operations/controllers/ > >> buckslips.py", line 341, in trash > >> return trash_it.trashit(request, session,response, db) > >> File "applications/operations/modules/trash_it.py", line 22, in > >> trashit > >> redirect(URL(request.application, request.controller, 'index'), > >> File "/media/Myfiles/3-o/gluon/http.py", line 128, in redirect > >> Location=location) > >> HTTP: 303 SEE OTHER

