[web2py] Re: How to prevent submitting form details that already exist as a record in the database

2020-07-31 Thread Asad Rashid
The more simplest way is to set UNIQUE to the column of the database you 
want it to stay unique. That way a duplicate record will not be inserted 
and the insert query will return an error stating "record already exist". 
Check how to set your required column(s) "unique". This way is the fastest 
and easiest.  

On Friday, July 17, 2020 at 2:38:43 PM UTC+5 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()
>
>
>
>
> 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
>> > 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.
>> > 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/162199b1-a37e-4ecd-af69-4bb101ea715dn%40googlegroups.com.


[web2py] Re: How to prevent submitting form details that already exist as a record in the database

2020-07-23 Thread mostwanted
Thank you Villas, you've been much helpful

On Thursday, July 23, 2020 at 2:05:49 PM UTC+2, villas wrote:
>
> As you've discovered, random doesn't work in this context.  Make an array 
> of class attendee numbers and then allocate the class which has the fewest 
> students.  
>
>
> On Thursday, 23 July 2020 12:50:00 UTC+1, mostwanted wrote:
>>
>> Well the whole concept behind this application was that allocation of 
>> spaces in time, days & class rooms should be automatic, the user should 
>> just select the lecturer, the subject & the period the subject takes 
>> (Double session=2hrs, Single session=1hr) from there after the user submits 
>> that information its allocated time, day & class room automatically. 
>>
>> To determine the whole automatic process I used the random() method, the 
>> problem with it is that after a while of entering details some random 
>> determinants start to repeat & alot more than desired causing conflict & 
>> triggering (conflict handling methods) in my validation function!
>>
>> With the above code I wanted to just keep up with the whole automatic 
>> notion of it!
>>
>> On Thursday, July 23, 2020 at 1:12:17 PM UTC+2, villas wrote:
>>>
>>> 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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/474f2a31-021e-4a17-8fb3-5294622dc7a3o%40googlegroups.com.


[web2py] Re: How to prevent submitting form details that already exist as a record in the database

2020-07-23 Thread villas
As you've discovered, random doesn't work in this context.  Make an array 
of class attendee numbers and then allocate the class which has the fewest 
students.  


On Thursday, 23 July 2020 12:50:00 UTC+1, mostwanted wrote:
>
> Well the whole concept behind this application was that allocation of 
> spaces in time, days & class rooms should be automatic, the user should 
> just select the lecturer, the subject & the period the subject takes 
> (Double session=2hrs, Single session=1hr) from there after the user submits 
> that information its allocated time, day & class room automatically. 
>
> To determine the whole automatic process I used the random() method, the 
> problem with it is that after a while of entering details some random 
> determinants start to repeat & alot more than desired causing conflict & 
> triggering (conflict handling methods) in my validation function!
>
> With the above code I wanted to just keep up with the whole automatic 
> notion of it!
>
> On Thursday, July 23, 2020 at 1:12:17 PM UTC+2, villas wrote:
>>
>> 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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/664fd0fb-3708-4c72-8b00-8f2f1df906fao%40googlegroups.com.


[web2py] Re: How to prevent submitting form details that already exist as a record in the database

2020-07-23 Thread mostwanted
Well the whole concept behind this application was that allocation of 
spaces in time, days & class rooms should be automatic, the user should 
just select the lecturer, the subject & the period the subject takes 
(Double session=2hrs, Single session=1hr) from there after the user submits 
that information its allocated time, day & class room automatically. 

To determine the whole automatic process I used the random() method, the 
problem with it is that after a while of entering details some random 
determinants start to repeat & alot more than desired causing conflict & 
triggering (conflict handling methods) in my validation function!

With the above code I wanted to just keep up with the whole automatic 
notion of it!

On Thursday, July 23, 2020 at 1:12:17 PM UTC+2, villas wrote:
>
> 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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/c8ce259d-756f-42d6-b429-485b0ce71e4do%40googlegroups.com.


[web2py] Re: How to prevent submitting form details that already exist as a record in the database

2020-07-23 Thread villas
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/c5ae6c62-d8a4-4b5d-9768-fa3c573b7264o%40googlegroups.com.


[web2py] Re: How to prevent submitting form details that already exist as a record in the database

2020-07-22 Thread mostwanted
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/9613268d-f125-4358-9fde-d932cb92eb81o%40googlegroups.com.


[web2py] Re: How to prevent submitting form details that already exist as a record in the database

2020-07-22 Thread Dave S


On Tuesday, July 21, 2020 at 3:16:29 AM UTC-7, 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;")
>
>
Ah, thank you.  I thought I was overlooking something, but late-night code 
reviews can be a challenge.

/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/d9b4e112-1606-423d-8bed-e5ff99d39dd1o%40googlegroups.com.


[web2py] Re: How to prevent submitting form details that already exist as a record in the database

2020-07-21 Thread mostwanted
Impressive outlook Villas, thank you.

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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/ea0ee397-ef21-4930-bab4-fa203443e913o%40googlegroups.com.


[web2py] Re: How to prevent submitting form details that already exist as a record in the database

2020-07-21 Thread villas
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/a703262b-14ee-4e2a-84e3-274a97fb2024o%40googlegroups.com.


[web2py] Re: How to prevent submitting form details that already exist as a record in the database

2020-07-19 Thread mostwanted
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
>>> >> 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.
>>> >> 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.


[web2py] Re: How to prevent submitting form details that already exist as a record in the database

2020-07-18 Thread Dave S


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
>> > 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.
>> > 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/9a43c502-83b7-4250-8f53-f25dbe151baao%40googlegroups.com.


[web2py] Re: How to prevent submitting form details that already exist as a record in the database

2020-07-17 Thread mostwanted
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()




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
>  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.
>  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/eb988cf7-c8f4-46e8-bc57-97e72b6aa10bo%40googlegroups.com.


[web2py] Re: How to prevent submitting form details that already exist as a record in the database

2020-07-17 Thread Dave S


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
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.
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/dc2d5465-1683-4a0d-a05e-96d745ae9beco%40googlegroups.com.