Hello I am trying to make a controller function upon submission of the form 
validate against existing entries in the database

*this is the function:*

@auth.requires(auth.has_membership('second_year') or 
auth.has_membership('admin'))
def second_year_checkout():
    check_id = request.args(0)
    check = db(db.product.id == check_id).select()
    project_date = db(db.checkout.id>0).select()
    for valid in check:
        db.checkout.product.default=valid.id
        form = SQLFORM(db.checkout)           
        if form.process().accepted:    
            for project in project_date:
                start = project.date_in
                end = project.date_out
                user_start = 
datetime.datetime.strptime(request.vars.date_in, '%Y-%m-%d').date()
                user_end = 
datetime.datetime.strptime(request.vars.date_out, '%Y-%m-%d').date()  
                if start <= user_start <= end or start <= user_end <= 
end:   
                    session.flash = 'Those dates have been reserved for 
that item, please try another'
                    return dict(form=form)
                else:
                    session.flash = 'form accepted'
                    return redirect(URL('default', 'next'))        
        elif form.errors:
            response.flash = 'form has errors'
        else:
            response.flash = 'please fill the form' 
            return dict(form=form)

what I am hoping to accomplish is have this if statement work in that 
function (basically exit out of form submission)

                if start <= user_start <= end or start <= user_end <= 
end:   
                    session.flash = 'Those dates have been reserved for 
that item, please try another'
                    return dict(form=form)
                else:
                    session.flash = 'form accepted'
                    return redirect(URL('default', 'next')) 

any idea how I can rewrite my controller function to validate using that 
statement

*cheers

and ty

-- 



Reply via email to