Made the changes you suggested. Thanks Anthony. This is an example of my new onvalidation, just in case you have other tips :)
def on_validation(form: SQLFORM) -> None: """Used in the edit form, including when creating and deleting. :param form: Form. """ # 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) if request.args and request.args[0] == 'new': if db.wo_counter(year_=request.now.year): form.errors.last_assigned = T('Counter already exists') else: # Edit/delete. if (not form.record.is_active and not form.vars.delete_this_record and auth.has_membership(SUPERVISOR_ROLE)): db.wo_counter(request.vars.id).update_record( cancel_approved_by=None, canceled_by=None, canceled_on=None, is_active=True, ) db.commit() session.flash = T('Record was activated.') redirect(URL('index', user_signature=True)) elif not form.record.is_active: session.flash = T('Record was deleted while you were editing.') redirect(URL('index', user_signature=True)) elif (request.post_vars.modified_on != str(form.record.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)) elif db.wo_counter(request.args[-1]).last_assigned > form.vars. last_assigned: form.errors.last_assigned = T('New value must >= than old.') elif form.vars.delete_this_record: db.wo_counter(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)) quinta-feira, 28 de Março de 2019 às 13:01:46 UTC, Anthony escreveu: > > 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)) >> > > Why not put the above inside the "edit" condition, as it is not relevant > otherwise (and won't work on record creation)? Also, given that this is in > the onvalidation function, why not use form.record rather than > unnecessarily re-selecting the record via db.client(request.vars.id)? > > 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.