Suppose you’ve 2 SQLFORMs to create/update records in a database table
def reprs(value): result = A(value, _href=URL(r=request, f='index', args=value)) return result def index(): keepvalues=True/False if not request.args: form = SQLFORM(db.my_table) if form.accepts(request.vars, session, keepvalues=keepvalues): response.flash = T('record created') else: form = SQLFORM(db.my_table, request.args(0), deletable=True) if form.accepts(request.vars, session): response.flash = T('record created') db.my_table.id.represent = reprs records = db().select(db.my_table.ALL) return dict(form=form, records=records)
keepvalues when set to True when creating a record then the form will keep the values after successful creation of the new record and vice versa.
keepvalues=True is very useful in successive insertion of similar data
and this makes sense actually, you want to see the updated data after
updating it.And any way this’s easily can be changed in the code in case you’ve another opinion.
or to refer to another link [This depends on your needs]
In the current situation you could do something like that by making a query based on the value of the field which is useless unless the field value is unique , so it’s more useful to be used with id fields in general.
Moreover it could have taken the record, one will not be forced to make an extra query.
Of course something like this can be done in other ways.
If you’ve an argue about my point of view, let me know.
In my openion this’s not a good idea in fact, and needs to be fixed because it’s really tempting to see the variables still in the form and makes one clicks the [‘submit’] button again to see what would happen
and it returns ‘object not found’ error message
One way to overcome this issue is to explicitly check whether user have asked to delete a record or not in the accepts() function.
if form.accepts(request.vars, session): if form.vars.delete_this_record: #record is deleted then redirect user to the same page without arguments [without the last argument if page takes many arguments] redirect(URL(r=request, f=....))