Re: [web2py] 'Table' object has no attribute 'attr'

26 views
Skip to first unread message

Carlos Costa

unread,
Apr 16, 2014, 5:57:53 PM4/16/14
to web...@googlegroups.com
The book says in http://web2py.com/books/default/chapter/29/07/forms-and-validators
"causes the hidden fields to be passed with the submission, no more, no less. form.accepts(...) is not intended to read the received hidden fields and move them into form.vars. The reason is security. Hidden fields can be tampered with. So you have to explicitly move hidden fields from the request to the form:
form.vars.a = request.vars.a
"

So I think you do not have attr field in the table activity, do you?
If so, you should do something like that:
values=request.vars
del values['attr']
db(db.activity._id == request.vars['id']).update(**dict(values))




2014-04-16 13:36 GMT-03:00 Richard <richard....@planet.nl>:
I have used a form in a view and want to update a record after submit:
 
View:
    {{=SQLFORM(db.activity, record = a.id, deletable = True,  hidden=dict(attr='chgact'))}}
 
 
controller:
 
    if (request.vars['attr'] == 'chgact') and (request.vars['delete_this_record'] != 'on'):
        db(db.activity._id == request.vars['id']).update(**dict(request.vars)) 
 
I use the convention in the controller because is is described in the manual in chapter 6:

The update of record with given id can be done with:

Inserting and updating from a dictionary

A common issue consists of needing to insert or update records in a table where the name of the table, the field to be updated, and the value for the field are all stored in variables. For example: tablename, fieldname, and value.

The insert can be done using the following syntax:

db[tablename].insert(**{fieldname:value})

The update of record with given id can be done with:

db(db[tablename]._id==id).update(**{fieldname:value})

Notice we used table._id instead of table.id. In this way the query works even for tables with a field of type "id" which has a name other than "id".


What is going wrong? 

--
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 web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Att.

Carlos J. Costa
Cientista da Computação
Esp. Gestão em Telecom

EL MELECH NEEMAN!
אָמֵן

Reply all
Reply to author
Forward
0 new messages