How can I access the rows that resulted from the query made by the SQLFORM.grid from the onvalidation function?
Thanks,
JM
def onvalidation(form):
current_record = db.mytable(request.args(-1))
I need the records from the grid itself.The objective is to be able to compare the modified_on field from the record of the grid with the same record on the db at the moment of the save (onvalidation) to detect if there was a record change between those 2 moments.Like the detect_record_change of the form, but for the grid.I found that the grid has a attribute rows which are the records and was able to make it work.
def my_grid():
def onvalidation(form):
if request.post_vars.modified_on != str(form.record.modified_on):
form.errors['modified_on'] = True
response.flash = 'Record change detected.'
grid = SQLFORM.grid(db.mytable, ...)
if 'edit' in request.args:
form = grid.update_form
form['hidden'].update(modified_on=form.record.modified_on)
return dict(grid=grid)
if grid.rows:
session.grid_rows = grid.rows.as_dict()
if request.args and request.args[0] == 'new':
...
elif (session.grid_rows[int(request.vars.id)]['modified_on']
!= db.manual_lang(request.vars.id).modified_on):
form.errors.name = T('The record was changed while you were editing. '
'Go back to the grid to see the updated record.')
else: # Edit/delete from edit form, after checking the record was not modified while editing.
...
if request.args and request.args[0] == 'new':
...
elif form.record.modified_on != db.manual_lang(request.vars.id).modified_on:
form.errors.name = T('The record was changed while you were editing. '
'Go back to the grid to see the updated record.')
else: # Edit/delete from edit form, after checking the record was not modified while editing.
...
Spoke too soon. Doesn't work.had to revert to my previous solution (save grid.rows to session ....).
if 'edit' in request.args:
form = grid.
update_form
session.modified_on = form.record.modified_on
if request.args and request.args[0] == 'new':
...
elif session.modified_on != db.client(request.vars.id).modified_on:
form.errors.code = T('The record was changed while you were editing. '
'Press F5 to refresh.')
else: # Edit/delete from edit form, after checking the record was not modified while editing.
...
session.modified_on
form['hidden'].update(modified_on=form.record.modified_on)
request.post_vars.modified_on
What is the more secure way to transfer the modified_on?Using
session.modified_onor
form['hidden'].update(modified_on=form.record.modified_on)and then
request.post_vars.modified_on?I ask this because there is an option to make session secure when using HTTPS.