Spoke too soon. Doesn't work. had to revert to my previous solution (save grid.rows to session ....).
terça-feira, 26 de Março de 2019 às 14:38:31 UTC, João Matos escreveu: > > @Anthony > Just realized by your solution that form has a record struct that I can > use. > So the solution became much simpler. > > No need to copy the grid.rows to session. > > And onvalidation function became > > 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. > ... > > Thank you all. > Feedback welcome on this solution,of course. > > > terça-feira, 26 de Março de 2019 às 13:42:53 UTC, Anthony escreveu: >> >> On Monday, March 25, 2019 at 7:58:56 PM UTC-4, João Matos wrote: >>> >>> 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. >>> >> >> The grid.rows object is None during requests that create and process the >> forms, so not sure how you could be accessing grid.rows from onvalidation >> during the processing of an edit form. In any case, you want to compare the >> submitted record with the version that was presented in the edit form (not >> the version that was presented in the grid, which could possibly differ). >> My original means of accessing the current record is not necessary, as you >> can actually get it via form.record within the onvalidation function. If >> you want to compare the modified_on field, you also need to pass that to >> the edit form (as a hidden field) when it is first created so the original >> value gets submitted back with the form. To do that, you can take Val K's >> approach, or to save an extra fetch of the record from the database, you >> can do the following: >> >> 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) >> >> Anthony >> >>> -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.