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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/c8ce259d-756f-42d6-b429-485b0ce71e4do%40googlegroups.com.