Suggestion:
Your idea of overriding the user's selections with random choices seems 
strange.
Why not ask the user to specify a date and then show him which classes are 
available nearest that date/time?  
He can then choose one of those.


On Wednesday, 22 July 2020 19:04:27 UTC+1, mostwanted wrote:
>
> 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 E.G:
>
>
> 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;")
>
> The above code doesnt work but its the concept thats in my head, where can 
> I fix it?
>
>
> On Tuesday, July 21, 2020 at 12:16:29 PM UTC+2, villas wrote:
>>
>> Your my_validator function iterates through the whole table.  This is OK 
>> when you have a few records,  but very inefficient if you have 
>> thousands/millions.  Why not simply query the table?  Something like this...
>>
>> def my_validator(form):
>>     if db((db.lecture.id == form.vars.id) & (db.lecture.lecture_time == 
>> form.vars.lecture_time)
>>          ).count() >0:
>>         form.errors.lecturer=SPAN("Record already exists", 
>> _style="font-weight: 
>> bold;")
>>
>>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/c5ae6c62-d8a4-4b5d-9768-fa3c573b7264o%40googlegroups.com.

Reply via email to