do "request.vars.clear()" instead of response.vars = ''

Richard




On Mon, May 5, 2014 at 12:59 PM, LoveWeb2py <[email protected]> wrote:

> I figured it out, but its not the most pythonic way of doing things. I had
> to specify db.users['dictKey'].default = request.vars['dictKey] for all 20
> fields.
>
> Again it works, just not sure why the for loop was throwing it off. Thanks
> so much for your help, Richard!!
>
>
> On Monday, May 5, 2014 12:27:16 PM UTC-4, LoveWeb2py wrote:
>>
>> I created a clean function and removed the      "for f, v in
>> request.vars.iteritems():db.users[f].default = v" and the form works
>> fine and properly redirects upon submit. So it has to be something with the
>> for loop?
>> def transition_form():
>>     form = SQLFORM(db.users)
>>     response.vars = ''
>>     if form.process().accepted:
>>        response.flash = 'form accepted'
>>        redirect(URL('users_list'))
>>     elif form.errors:
>>         response.flash = 'errors on page'
>>     else:
>>         response.flash = 'facepalm'
>>
>>     return dict(form=form)
>>
>> On Monday, May 5, 2014 12:21:29 PM UTC-4, LoveWeb2py wrote:
>>>
>>> I tried adding
>>> def transition_form():
>>>     for f, v in request.vars.iteritems():
>>>        db.users[f].default = v
>>>     form = SQLFORM(db.users)
>>>     response.vars = ''
>>>     if form.process().accepted:
>>>        response.flash = 'form accepted'
>>>        redirect(URL('users_list'))
>>>     elif form.errors:
>>>         response.flash = 'errors on page'
>>>     else:
>>>         response.flash = 'facepalm'
>>>
>>>     return dict(form=form)
>>>
>>> but the same issue of 'Table' object has no attribute '_formkey' still
>>> exist. I checked with firebug and the _formkey is under hidden values so it
>>> is posting, but for some reason the page isn't picking it up...
>>>
>>> On Monday, May 5, 2014 12:12:29 PM UTC-4, Richard wrote:
>>>>
>>>> You got 'facepalm' because it's not process the form when you get
>>>> redirected... Since you don't redirect once the form get accepted and
>>>> process web2py return the same function once the form validate and get
>>>> process. Now maybe you should delete the request.vars once you have assign
>>>> them as default value... An other issue maybe related to the fact that your
>>>> vars names are the same of form.vars... I had issue with name collision in
>>>> the pass deleting the request.vars after iteratio on it may help.
>>>>
>>>> Richard
>>>>
>>>>
>>>> On Mon, May 5, 2014 at 11:57 AM, LoveWeb2py <[email protected]> wrote:
>>>>
>>>>> Controllers:
>>>>> @auth.requires_login()
>>>>> def users_list():
>>>>>     grid=SQLFROM.smartgrid(db.users, paginate=20,
>>>>> links_placement='left',
>>>>>          links=[dict(header='', body=lambda row: A(I(_class='icon
>>>>> retweet icon-retweet'),
>>>>>
>>>>>          _href=URL('transition_form', vars=dict((f, row[f]) for f in
>>>>> db.users.fields))))], user_signature=True)
>>>>>     return dict(grid=grid)
>>>>>
>>>>> @auth.requires_login()
>>>>>
>>>>> def transition_form():
>>>>>     for f, v in request.vars.iteritems():
>>>>>        db.users[f].default = v
>>>>>     form = SQLFORM(db.users)
>>>>>
>>>>>     if form.process().accepted:
>>>>>        response.flash = 'form accepted'
>>>>>     elif form.errors:
>>>>>         response.flash = 'errors on page'
>>>>>     else:
>>>>>         response.flash = 'facepalm'
>>>>>
>>>>>     return dict(form=form)
>>>>>
>>>>> It populates the transition_form properly it just doesn't insert the
>>>>> new record when I click submit. It just doubles the record and returns the
>>>>> response in the view. Also, when loading the transition_form page it
>>>>> automatically flashes with 'facepalm' which means its processing the form
>>>>> on load.
>>>>>
>>>>> --
>>>>> Resources:
>>>>> - http://web2py.com
>>>>> - http://web2py.com/book (Documentation)
>>>>> - http://github.com/web2py/web2py (Source code)
>>>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>>>> ---
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "web2py-users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>  --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to