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
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()
--
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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/8ae4d738-3954-441e-807c-6957229ebb56o%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to web...@googlegroups.com.
def my_form_processing(form):
times=dict({'single_session_times':['0830-0930hrs', '0930-1030hrs', '1100-1200','1200-1300', '1400-1500', '1500-1600', '1600-1700'], 'evening_single_session_times':['1730-1830', '1830-1930'],'double_session_times':['0830-1030', '1100-1300', '1400-1700'],'evening_double_session_times':['1730-1930']})
if form.vars.class_session=='single session':
the_time=random.choice(times['single_session_times'])
form.vars.the_time2=the_time
if form.vars.class_session=='evening single session':
the_time=random.choice(times['evening_single_session_times'])
form.vars.the_time2=the_time
if form.vars.class_session=='double session':
the_time2=random.choice(times['double_session_times'])
form.vars.the_time2=the_time2
if form.vars.class_session=='evening double session':
the_time=random.choice(times['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()
def my_form_processing(form):
times = {
'single session':['0830-0930hrs', '0930-1030hrs', '1100-1200','1200-1300', '1400-1500', '1500-1600', '1600-1700'],
'evening single':['1730-1830', '1830-1930'],
'double session':['0830-1030', '1100-1300', '1400-1700'],
'evening double':['1730-1930']
}
form.vars.the_time2 =
random.choice(times[
form.vars.class_session
])