Altering details of a rejected form automatically for another save attempt without the user's interference

12 views
Skip to first unread message

mostwanted

unread,
Jul 23, 2020, 2:40:50 AM7/23/20
to web2py-users
I asked this in a previous question I posted but felt it may not be picked up quick enough, I dont mean to be repetitive i just need help on it immediately!

After a form has failed to save because that information already exists in the database I wanna try & alter the value that determines a day where the info is saved in the db for the form to be saved in a different day that does not contain similar form details currently attempting to be saved and this should be done automatically without the engaging the user, I then tried this below but I feel I didnt write it correctly;
CODE:

def my_validator(form):
    control
=['1', '2', '3', '4' ,'5']
    form
.vars.controller = random.choice(control)
    if db((db.lecture.id == form.vars.id) & (d.controller==form.vars.controller) & (db.lecture.lecture_time == form.vars.lecture_time)).count() >0:

   
if int(form.vars.controller) < int(control[4]):
           
int(form.vars.controller) +1
            response
.flash=T('Saved in',' ', int(form.vars.controller) +1)
               
   
if int(form.vars.controller) > int(control[4]):
           
int(form.vars.controller) -1
            repsonse
.flash=T('Saved in',' ', int(form.vars.controller) -1)

   
else:

        form
.errors.lecturer=SPAN("Record already exists in the whole database", _style="font-weight: bold;")

def index():
    details=db(db.lecture).select()

    form=SQLFORM(db.lecture)
    if form.process(onvalidation=my_validator).accepted:
        response.flash=T('Submitted')
    return locals()


This is the concept thats in my head, where can I fix it?

Regards;

Mostwanted
Reply all
Reply to author
Forward
0 new messages