Thanks for the replies. Pbreit, you pointed the real issue -- what should I call the arguments (addperiodform.vars.id), that are passed from the goal function to the addingperiod function?
from the controller file: ************ def goal(): ...some code... addperiodform = SQLFORM(db.period, fields=['begindate','enddate', 'planned'], labels={'begindate':'First day','enddate':'Last day','planned':'Goal'},submit_button='Submit',formstyle='table2cols') if addperiodform.accepts(request.post_vars, session): redirect(URL('default', 'addingperiod', args=addperiodform.vars.id)) ...some code... def addingperiod(): if request.args and request.args[0]: item_id=request.args[0] prerecords = db().select(db.period.ALL, orderby=db.period.begindate) for prerecord in prerecords: if prerecord.theauth==auth.user_id: accepted1="true" accepted2="true" ...some if-statements... if accepted1=="true": if accepted2=="true": db.period.insert(item_id) #this line creates an error redirect(URL(f='goal')) ************ On Saturday, April 14, 2012 10:44:28 AM UTC+2, backseat wrote: > > On Fri, 13 Apr 2012 11:38:25 -0700 (PDT), sababa.sab...@gmail.com said: > > > The > > function should only add periods that doesn't overlap any of the > > already registered ones. > > Let me try to help (I owe this group a lot of help). I've ignored your > code, and I don't know what schema you're using, but here's the pseudo > and untested code: > > def should_this_period_be_inserted(start,end): > # Check that all periods that started before this one > # also finished before this one started > q = ((db.period.begindate<start)&(db.period.enddate>start)) > if db(query).count(): > return False > # Check that no periods started while this one was in progress > q = ((db.period.begindate>=start)&(db.period.begindate<=end)) > if db(query).count(): > return False > # If we got this far, the period didn't overlap > return True > > Have I understood what you're trying to do? > -- > "You can have everything in life you want if you help enough other people > get what they want" - Zig Ziglar. > > Who did you help today? > >