On Apr 26, 10:11 am, Johann Spies <[email protected]> wrote:
> But none of those variables are available.  When I try
> form = SQLFORM(db.navrae)
>     message = T("form has errors")
>     if request.vars.begindatum > request.vars.einddatum:
>         message = T("end date before start date")
>         form.errors == True
>     if form.errors:
>         response.flash = message
>     elif form.accepts(request.vars, session):
>         form.vars.id = db.navrae.insert(**dict(form.vars))
>         response.flash = 'form accepted'
>     else:
>         response.flash = 'please fill out the form'

form.errors are set by the fields validators during accepts,
the check: if form.errors is true when it has entries, false if it
empty
you should specify which particular one you want to set, as in:
form.errors.begindatum=T('...')

The regular way to create and process the form is:

form=SQLFORM(...) #or similar
if form.accepts:
  # here record has been add/upd/del-ed in  DB if using SQLFORM
  # additional processing
  # set flash msg and redirect usually
elif form.errors:
  # set flash msg and let user fix input
else:
  # optional, maybe flash msg saying 'please fill form'

Note that when form.accepts is true the record has already been
processed.
So how do you get around this to perform additional checks?
One way is to use the onvalidation parameter of accepts,
see section 7.1 in the book for an example.

> I get no error message and the form is accepted even when einddatum <
> begindatum.
>
> I also tried this in the model:
>
> db.navrae.einddatum.requires= (db.navrae.einddatum >= db.navrae.begindatum)
>
> but get a TypeError: 'Query' object is not callable
>
> So how do I do it?

you can refer to request.vars here too, so:
db.navrae.einddatum.requires=
IS_EXPR('request.vars.einddatum >= request.vars.begindatum',
error_message=T('...') )

About winpdb, add this to your code where you want to start tracing:
import rpdb2; rpdb2.start_embedded_debugger('your_password')
then start winpdb and file/attach to the waiting script using
your_password.

Denes.

Reply via email to