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
>

Reply via email to