here is my db.py

db.define_table('time_table',
    Field('time_in','time'),
    Field('time_out','time')
)

db.define_table('years',
    Field('year_number','string')
)

db.define_table('buildings',
    Field('b_number','string')
)

db.define_table('levels',
    Field('l_number','string')
)

db.define_table('room',
    Field('building_number',db.buildings),
    Field('level','string'),
    Field('room_number','string'),
    Field('area','string')
)

db.define_table('module',
    Field('name','string'),
    Field('module_number','string'),
    Field('year',db.years)
)

db.define_table('reservation',
    Field('room',db.room),
    Field('module',db.module),
    Field('Time_IN',db.time_table),
    Field('Time_OUT',db.time_table),
    Field('Date','date')
    )

db.module.year.requires=IS_IN_DB(db,'years.id','years.year_number')
db.room.building_number.requires=IS_IN_DB(db,'buildings.id','buildings.b_number')
db.room.level.requires=IS_IN_DB(db,'levels.id','levels.l_number')
db.reservation.room.requires=IS_IN_DB(db,'room.id','room.room_number')
db.reservation.module.requires=IS_IN_DB(db,'module.id','module.name')
db.reservation.Time_IN.requires=IS_IN_DB(db,'time_table.id','time_table.time_in')
db.reservation.Time_OUT.requires=IS_IN_DB(db,'time_table.id','time_table.time_out')

and here is my default.py in controler:
def index():

    return dict(message="")

def room_reg():
    form=SQLFORM(db.room)
    if form.accepts(request.vars,session):
        response.flash='new record inserted'
    records=SQLTABLE(db().select(db.room.ALL))

    return dict(form=form,records=records)

def module_reg():
    form=SQLFORM(db.module)
    if form.accepts(request.vars,session):
        response.flash='new record inserted'
    records=SQLTABLE(db().select(db.module.ALL))

    return dict(form=form,records=records)

def validation(form):

    st1=form.vars.Time_IN
    en1=form.vars.Time_OUT
    dbselect=db(db.reservation.Date==form.vars.Date).select()

    if en1<st1 :
        form.errors.Time_OUT='الرجاء تعديل الوقت'

    for i in dbselect:
        st2=i.Time_IN
        en2=i.Time_OUT
        if st1==st2 or en1==en2:
            form.errors.Time_OUT='الرجاء تعديل الوقت'
        elif st2>st1 and en2>en1:
            if st2>en1:
                pass
            else:
                form.errors.Time_OUT='الرجاء تعديل الوقت'
        elif st2<st1 and en2<en1:
            if en2<st1:
                pass
            else:
                form.errors.Time_OUT='الرجاء تعديل الوقت'
        elif st2>st1 and en2<en1:
            form.errors.Time_OUT='الرجاء تعديل الوقت'
        else:
            pass

def reservation():
    form=SQLFORM(db.reservation)
    if form.accepts(request.vars,session, onvalidation=validation):
        response.flash='new record inserted'
    records=SQLTABLE(db().select(db.reservation.ALL))
    dt=db(db.reservation.Date==form.vars.Date).select()
    return dict(form=form,records=records,dt=dt)

My issue is in the Validation function for the form processing in the
function reservation()
first I am validating if the user has input a time in later than time
out:

    st1=form.vars.Time_IN
    en1=form.vars.Time_OUT

    if en1<st1 :
        form.errors.Time_OUT='الرجاء تعديل الوقت'

and it works fine.

then I tried to do extra validation at which I select from the
database the same date inputed by the user:

dbselect=db(db.reservation.Date==form.vars.Date).select()

then do some logic to see if there is a conflicting time already in
the database in that same particular date:

 for i in dbselect:
        st2=i.Time_IN
        en2=i.Time_OUT
        if st1==st2 or en1==en2:
            form.errors.Time_OUT='الرجاء تعديل الوقت'
        elif st2>st1 and en2>en1:
            if st2>en1:
                pass
            else:
                form.errors.Time_OUT='الرجاء تعديل الوقت'
        elif st2<st1 and en2<en1:
            if en2<st1:
                pass
            else:
                form.errors.Time_OUT='الرجاء تعديل الوقت'
        elif st2>st1 and en2<en1:
            form.errors.Time_OUT='الرجاء تعديل الوقت'
        else:
            pass

the problem is that the validation is completely ignored.

can any one help?

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.

Reply via email to