Hahahaha sometimes you put in a single delimeter & it all comes down 
crumbling!

On Thursday, July 16, 2020 at 2:22:45 AM UTC+2, AGRogers wrote:
>
> >>>My motto is:  get something working and move on! 
>
> Haha. A modified version I need to remember: Get something working and 
> don't go back and break it! 
>
> On Thu, 16 Jul 2020, 7:20 am villas, <vill...@gmail.com <javascript:>> 
> wrote:
>
>> We all have our styles of programming.  I would probably create a dict of 
>> times. 
>> But any idea which works is fine. Everyone looks at their old code and 
>> sees a better way. 
>> My motto is:  get something working and move on!  
>>
>>
>>
>> On Wednesday, 15 July 2020 19:26:33 UTC+1, mostwanted wrote:
>>>
>>> Thank you Villas, i updated my controller like this & its giving 
>>> results. I a sure there is a better way to do this, a ore cleaner way & if 
>>> anyone cares to improve my code please dont hesitate so i could update mine 
>>> & learn more:
>>>   
>>> def my_form_processing(form):
>>>     if form.vars.class_session=='single session':
>>>         single_session_times=['0830-0930hrs', '0930-1030hrs', 
>>> '1100-1200','1200-1300', '1400-1500', '1500-1600', '1600-1700']
>>>         the_time=random.choice(single_session_times)
>>>         form.vars.the_time2=the_time
>>>
>>>     if form.vars.class_session=='evening single session':
>>>         evening_single_session_times=['1730-1830', '1830-1930']
>>>         the_time=random.choice(evening_single_session_times)
>>>         form.vars.the_time2=the_time
>>>
>>>     if form.vars.class_session=='double session':
>>>         double_session_times=['0830-1030', '1100-1300', '1400-1700']
>>>         the_time2=random.choice(double_session_times)
>>>         form.vars.the_time2=the_time2
>>>
>>>     if form.vars.class_session=='evening double session':
>>>         evening_double_session_times=['1730-1930']
>>>         the_time=random.choice(evening_double_session_times)
>>>         form.vars.the_time2=the_time
>>>
>>> @auth.requires_login()
>>> def index():
>>>     form=SQLFORM(db.lecture)
>>>     if form.process(onvalidation=my_form_processing).accepted:
>>>         response.flash=T('Lecture Entered')
>>>     return locals()
>>> Regards;
>>>
>>> Mostwanted
>>>
>>> On Wednesday, July 15, 2020 at 5:47:18 PM UTC+2, villas wrote:
>>>>
>>>> Before submission of form, use JS.
>>>> or
>>>> After submission,  allocate the time in the controller using 
>>>> *onvalidation*.  See  
>>>> http://www.web2py.com/books/default/chapter/29/07/forms-and-validators#onvalidation
>>>>
>>>> On Wednesday, 15 July 2020 13:58:28 UTC+1, mostwanted wrote:
>>>>>
>>>>> I thought it would be easy but its not, wrong values are being 
>>>>> selected from wrong lists! After submitting a form I wanna check to see 
>>>>> if 
>>>>> the session field is either a single_session, double_session, 
>>>>> evening_single_session or evening_double_session, depending on what it is 
>>>>> I 
>>>>> want time to be selected randomly from an appropriate list and inputted 
>>>>> into the session_time field but wrong values from wrong lists are 
>>>>> entered, 
>>>>> information gets mixed up!
>>>>>
>>>>> model code:
>>>>> db.define_table('lecture',
>>>>>                 Field('subject_name', 'reference subject'),
>>>>>                 Field('department', 'reference departments'), #HERE
>>>>>                 Field('theLevels', label=SPAN('Levels'), requires=
>>>>> IS_IN_SET(['1.1', '1.2', '2.1', '2.2', '3.1', '3.2', '4.1', '4.2'], 
>>>>> zero='---Select A Level---')), #HERE
>>>>>                 Field('lecturer', 'reference lecturer'),
>>>>>                 Field('class_session', requires=IS_IN_SET(['single 
>>>>> session', 'double session', 'evening single session', 'evening double 
>>>>> session'], zero='----Select A Session Period----')),
>>>>>                 Field('session_time', readable=False, writable=False),
>>>>>                 Field('class_room', readable=False, writable=False),
>>>>>                 Field('controller', readable=False, writable=False)
>>>>>                )
>>>>>
>>>>> single_session_times=['0830-0930hrs', '0930-1030hrs', '1100-1200',
>>>>> '1200-1300', '1400-1500', '1500-1600', '1600-1700']
>>>>> double_session_times=['0830-1030', '1100-1300', '1400-1700']
>>>>>
>>>>> evening_single_session_times=['1730-1830', '1830-1930']
>>>>> evening_double_session_times=['1730-1930']
>>>>> '''
>>>>> After submitting the form, have system scheck the session, if the 
>>>>> session is any of whats defined give it a proper time
>>>>> '''
>>>>> if db.lecture.class_session=='single session':
>>>>>     the_time=random.choice(single_session_times)
>>>>>     db.lecture.session_time.default=the_time
>>>>>
>>>>>     
>>>>> elif db.lecture.class_session=='evening single session':
>>>>>     the_time=random.choice(evening_single_session_times)
>>>>>     db.lecture.session_time.default=the_time
>>>>>
>>>>>     
>>>>> elif db.lecture.class_session=='double session':
>>>>>     the_time=random.choice(double_session_times)
>>>>>     db.lecture.session_time.default=the_time
>>>>>
>>>>>     
>>>>> elif db.lecture.class_session=='evening double session':
>>>>>     the_time=random.choice(evening_double_session_times)
>>>>>     db.lecture.session_time.default=the_time
>>>>>
>>>>>
>>>>>
>>>>> How can i achieve this with proper results from the intended list
>>>>>
>>>>> Mostwanted
>>>>>
>>>> -- 
>> 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 web...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/web2py/8ae4d738-3954-441e-807c-6957229ebb56o%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/web2py/8ae4d738-3954-441e-807c-6957229ebb56o%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/8bdec24e-065e-4a48-856d-bf5cfe6fccd3o%40googlegroups.com.

Reply via email to