Massimo,

Is there any method that we can check if the instance is valid instead
of checking with the form instance?

On Feb 8, 10:56 pm, Johann Spies <[email protected]> wrote:
> I want to use a form to build a query for a search function and do not
> understand the communication between the different functions.  I have:
>
> def index():
>     form = FORM(TABLE(TR('Field:','',
>                          SELECT(
>                              OPTION('title', _field = 1),
>                              OPTION('affiliation', field = 2),
>                              OPTION('country', field = 3),
>                              OPTION('year', field = 4),
>                              OPTION('research_field', field = 5),
>                              OPTION('journal', field = 6),
>                              OPTION('keywords', field = 7),
>                              OPTION('author',field = 8),
>                              OPTION('source', field= 8), field = 1)),
>                       TR('Operator:', '',
>                          SELECT(
>                              OPTION('equals', operator = 1),
>                              OPTION('starts with', operator = 2),
>                              OPTION('contains', operator = 3), operator =1)),
>                        TR('Value:', '',
>                          INPUT(_searchfor = '')),
>                       TR('', '', INPUT(_type = 'submit' ))))
>     if form.accepts(request.vars, session):
>         redirect(URL(r=request, f='list_records'))
>     elif form.errors:
>         response.flash = 'form has errors'
>     else:
>         response.flash = 'Please select the field, operator and type
> in the search field'
>     return dict(form=form)
>
> And
> def list_records():
>     db.sarua.id.represent = lambda value: UL(
>         LI(A(T('edit'),_href=URL(r=request,
> c='default',f='data/update/sarua', args=str(value)))),
>         LI(A(T('remove'),_href=URL(r=request,
> c='default',f='data/delete/sarua', args=str(value)))))
>
>     try:
>         ss = session.vars.searchfor.upper()
>     except:
>         ss = session.vars.searchfor
>     if not ss :
>         query = ''
>     elif session.vars.operator == 'equals':
>         query = "db.sarua.%s == %s" % (session.vars.field, ss)
>     elif session.vars.operator == 'starts with':
>         query = "db.sarua.%s >= %s" % (session.vars.field, ss)
>     else:
>         query = "db.sarua.%s.like( '%' + %s + '%')" % (session.vars.field, ss)
>     session.flash = query
>     rows = db(query).select(db.sarua.ALL,limitby = (0,25))
>     records = SQLTABLE(rows, headers=dict([('sarua.'+f,db.sarua[f].label)
>                                      for f in db.sarua.fields]))
>     return dict(records=records)
>
> But the variables do not arrive in list_records().  I am missing
> something about request vars, return(form) and session vars().
>
> If I replace "session" in list_records with "response" I do not get
> any error but also no query content.
>
> How am I supposed to do it?
>
> Regards
> Johann

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.

Reply via email to