Thanks for the tip. I was using this (it's included in the above code)
elif request.post_vars.modified_on != str(db.client(request.vars.id). modified_on): form.errors.code = T('Record was changed while you were editing. ' 'Press F5 to refresh and press Resend in the ' 'browser question.') which I changed now to this elif request.post_vars.modified_on != str(db.client(request.vars.id). modified_on): session.flash = T('Record was changed while you were editing. ' 'This is the updated record.') redirect(URL(args=request.args, vars=request.get_vars, user_signature=True)) quinta-feira, 28 de Março de 2019 às 01:57:29 UTC, Anthony escreveu: > > I don't see any code that checks for record change, but you could do > something like: > > elif request.args and request.args[0] == 'edit': > if request.vars.modified_on != str(form.record.modified_on): > session.flash = 'Record change detected. Please try again.' > redirect(URL(args=request.args, vars=request.get_vars)) > > That will redirect to the same URL, which will load the same record (with > the updated data), and show the message after redirect. > > Anthony > > On Wednesday, March 27, 2019 at 3:06:16 PM UTC-4, João Matos wrote: >> >> This is my code for the another table (it has the same situation, but >> without using a SQLFORM.factory). >> I posted this instead of the SQLFORM.factory, because it is simpler code. >> >> My index function contains the grid >> >> grid = SQLFORM.grid( >> query, >> csv=False, deletable=False, details=False, >> links=[ >> lambda row: A( >> SPAN(T('Delete'), _class='buttontext button', _title= >> 'Delete'), >> _href=URL('get_approval', args=[row.id], >> user_signature=True), >> _class='button btn btn-default btn-secondary', >> ), >> ], >> onvalidation=on_validation, # Form only. >> orderby=db.client.name, >> paginate=session.auth.user.pagination, >> # represent_none='', # Grid and view form only. >> ) >> >> >> if 'edit' in request.args: >> form = grid.update_form >> form['hidden'].update(modified_on=form.record.modified_on) >> >> My onvalidation function >> >> if request.args and request.args[0] == 'new': >> # Fix for SQLite instead of for_update=True. When for_update is >> # fixed for SQLite, only the first SELECT in the function should >> # have for_update=True. >> while True: >> try: >> # SQLite only does database lock. >> db.executesql('BEGIN IMMEDIATE TRANSACTION') >> break >> except sqlite3.OperationalError: >> sleep(0.5) >> elif not db.client(request.vars.id).is_active: >> session.flash = T('Record was deleted while you were editing.') >> redirect(URL(user_signature=True)) >> elif request.post_vars.modified_on != str(db.client(request.vars.id). >> modified_on): >> form.errors.code = T('Record was changed while you were editing. >> ' >> 'Press F5 to refresh and press Resend in >> the ' >> 'browser question.') >> elif form.vars.delete_this_record: >> # Fix for SQLite instead of for_update=True. When for_update is >> # fixed for SQLite, only the first SELECT in the function should >> # have for_update=True. >> while True: >> try: >> # SQLite only does database lock. >> db.executesql('BEGIN IMMEDIATE TRANSACTION') >> break >> except sqlite3.OperationalError: >> sleep(0.5) >> >> db.client(request.vars.id).update_record( >> cancel_approved_by=auth.user_id, >> canceled_by=auth.user_id, >> canceled_on=request.now, >> is_active=False, >> ) >> >> db.commit() >> >> session.flash = T('Done.') >> redirect(URL(user_signature=True)) >> elif request.args and request.args[0] == 'edit': >> # Fix for SQLite instead of for_update=True. When for_update is >> # fixed for SQLite, only the first SELECT in the function should >> # have for_update=True. >> while True: >> try: >> # SQLite only does database lock. >> db.executesql('BEGIN IMMEDIATE TRANSACTION') >> break >> except sqlite3.OperationalError: >> sleep(0.5) >> >> >> >> quarta-feira, 27 de Março de 2019 às 18:47:33 UTC, Anthony escreveu: >>> >>> Need to see your code. >>> >>> On Wednesday, March 27, 2019 at 2:47:01 PM UTC-4, João Matos wrote: >>>> >>>> You mean to update the editing form with the new values from the record >>>> on the db without telling the user to press F5? >>>> How can I do it? >>>> >>>> Thanks. >>>> >>> -- 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.