Looks like you might have some unbalanced parentheses here and there (and a
missing comma in the returned dict). Also, in Python, instead of:
if len(something) == 0:
your can generally just do:
if not something:
Empty and zero length objects (as well as None) evaluate to False.
Finally, note that the "flight" variable is not defined unless the form is
submitted and accepted, so the "records" variable should be defined
conditionally.
Anthony
On Wednesday, January 16, 2013 7:59:55 AM UTC-5, Mihir Lade wrote:
>
> Hi Anthony,
>
> As mentioned on Stack Overflow:
>
> I am currently working with the FORM because this is very frustrating that
> the query isn't working properly or I can't seen to figure out how to get
> it working properly..
>
> with the form this is the code that I am using.. this is just a prototype
> to see if the form even works.. however i get an error stating, unexpected
> indent.. I've corrected the spacing and i still keep getting the same
> error.. i've tried the line on every space after and still get the same
> error.
>
> def display():
> form=FORM(TABLE(TR("Departure Location: ", INPUT(_type="text",
> _name="DepartureLocation", IS_IN_SET(states))))),
> TR("Arrival Location: ", INPUT(_type="text",
> _name="ArrivalLocation", IS_IN_SET(states))),
> TR("", INPUT(_type="submit", _value="Submit"))
>
> if form.accepts(request.vars, session):
> ##check to see if flight present in the database.
> if
> len(db(db.Flight.DepartureLocation==form.vars.DepartureLocation).select()==0:
> form.errors.DepartureLocation="No flights available"
>
> if len(form.errors)==0:
>
> flight=db((db.Flight.DepartureLocation==form.vars.DepartureLocation)&
>
> (db.Flight.ArrivalLocation==form.vars.ArrivalLocation)).select()
>
> records=db(flight).select(db.Flight.DepartureLocation,
> db.Flight.ArrivalLocation, db.Flight.DepartureDate, db.Flight.ArrivalDate)
>
> return dict(form=form records=SQLTABLE(Flight), vars=form.vars,
> vars2=request.vars)
>
>
--