Thank you On Saturday, July 18, 2020 at 10:16:09 PM UTC+2, Dave S wrote: > > > > On Friday, July 17, 2020 at 2:38:43 AM UTC-7, mostwanted wrote: >> >> Hey Dave, thanks for replying, >> This below is what I tried & it seems to be working, idont know if the >> best solution but please help e where u think I could improve it: >> >> def my_validator(form): >> details=db(db.lecture).select() >> for d in details: >> if form.vars.lecturer==d.lecturer.id and form.vars.lecture_time== >> d.lecture_time: >> form.errors.lecturer=SPAN("There is a conflict with these >> values!", _style="font-weight: bold;") >> form.errors.lecture_time=SPAN("There is a conflict with >> these values!", _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() >> >> >> >> > Looks good to me. > > /dps > > >> >> On Friday, July 17, 2020 at 8:12:17 AM UTC+2, Dave S wrote: >>> >>> >>> >>> On Thursday, July 16, 2020 at 7:56:47 AM UTC-7, mostwanted wrote: >>>> >>>> I have created a calendar that assigns lesson_times & class_rooms >>>> randomly. So far it has been working properly until a conflic arose, one >>>> lecturer being assigned 2 classes at the same time, another one one >>>> class_room being assigned different lectures at the same time! I wanna >>>> avoid these >>>> *. * >>>> >>>> *How can I avoid entering 2 critical & determinant details that are >>>> similar to other critical & determinant ones that already exist in the >>>> database?* >>>> >>>> Time on its own being similar to another recorded time value is ok, a >>>> single classroom_number value being similar to another one recorded is ok, >>>> the problem is having both time and classroom_number being similar or time >>>> & a lecturer being similar to ones recorded because that means a clash in >>>> lessons! >>>> >>>> If the generated time & classroom number are similar to those that >>>> already exists I want the form to fail to submit with a flag message that >>>> warns the system user of a conflict thats causing failure to submit. (I >>>> have it in my head but i'm failing to put it on code) >>>> >>>> Regards; >>>> >>>> Mostwanted >>>> >>> >>> What you want is related to the standard validator IS_NOT_IN_DB() . See >>> <URL: >>> https://web2py.com/books/default/chapter/29/07/forms-and-validators#Database-validators >>> > >>> That only checks one field at a time and I think it is really a tuple of >>> fields that you are concerned about. After all, there can be several >>> classes at 10 on Tuesday, and it is only the combination of 10 on Tuesday >>> with Room 310 that has to be unique, or the combination of 10 on Tuesday >>> with Professor Fusspot . >>> >>> I would look at one of two approaches: >>> >>> 1) creating a calculated field from the fields of concern, and applying >>> IS_NOT_IN_DB() to that. >>> >>> or >>> >>> 2) Using the onvalidation() call backs to check further. >>> <URL: >>> https://web2py.com/books/default/chapter/29/07/forms-and-validators#onvalidation >>> > >>> >>> >>> You can also write a custom validator (the discussion is just down the >>> page from IS_NOT_IN_DB()), but I'm not sure that is helpful here. >>> >>> /dps >>> >>>
-- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/de7904a6-82d4-41f5-83f9-56bc1622b264o%40googlegroups.com.