The code is a little confusing (although it is indented OK at Google Groups web site).
You can do "if request.args(0):" What does this do: if not session.timedelta2==timedelta(days=0): This really confused me: if item_id.vars.begindate < previousenddate: item_id = request.args[0] so I don't know how it would have any vars. Where does previousenddate come from? I don't see it referenced anywhere. Where does period come from? If you're just redirecting at the end, it doesn't look like the code is really doing anything.