I sent a patch that allows this:
form, results = crud.search(db.test,
queries = ['equals', 'not equal', 'contains'],
query_labels={'equals':'Equals',
'not equal':'Not equal'},
fields = ['id', 'children'],
field_labels = {'id':'ID','children':'Children'},
zero='Please choose',
query = (db.test.id > 0)&(db.test.id != 3) )
On Jun 17, 6:59 pm, rochacbruno <[email protected]> wrote:
> I found a way
>
> I made a hard edit in the /gluon/tools.py
>
> I'm trying now to find a way to override that in the Controller
> and translate the texts/ change the HTML that renders
>
> will great if there is an API to do this
>
> {{ }}' s
> ---
>
> def get_query(self, field, op, value, refsearch=False):
> try:
> if refsearch: format = self.get_format(field)
> if op == 'equals':
> return field == value if not refsearch else \
> lambda row: row[field.name][format] == value
> elif op == 'not equal':
> return field != value if not refsearch else \
> lambda row: row[field.name][format] != value
> elif op == 'greater than':
> return field > value if not refsearch else \
> lambda row: row[field.name][format] > value
> elif op == 'less than':
> return field < value if not refsearch else \
> lambda row: row[field.name][format] < value
> elif op == 'starts with':
> return field.like(value+'%') if not refsearch else \
> lambda row: str(row[field.name]
> [format]).startswith(value)
> elif op == 'ends with':
> return field.like('%'+value) if not refsearch else \
> lambda row: str(row[field.name]
> [format]).endswith(value)
> elif op == 'contains':
> return field.like('%'+value+'%') if not refsearch else
> \
> lambda row: value in row[field.name]
> [format]
> except:
> return None
>
> def search(self, *tables, **args):
> table=tables[0]
> fields=args.get('fields',None)
> request = self.environment.request
> db = self.db
> if not (isinstance(table, db.Table) or table in db.tables):
> raise HTTP(404)
> tbl = TABLE()
> selected = []; refsearch = []; results = []
> ops = ['', 'equals', 'not equal', 'greater than', 'less than',
> 'starts with', 'ends with', 'contains']
> query = table.id > 0
> for fieldname in fields or table.fields:
> field = table[fieldname]
> chkval = request.vars.get('chk' + fieldname, None)
> txtval = request.vars.get('txt' + fieldname, None)
> opval = request.vars.get('op' + fieldname, None)
> row = TR(TD(INPUT(_type = "checkbox", _name = "chk" +
> fieldname,
> value = chkval == 'on')),
> TD(field),TD(SELECT(ops, _name = "op" +
> fieldname,
> value = opval)),
> TD(INPUT(_type = "text", _name = "txt" +
> fieldname,
> _value = txtval, _id='txt' + fieldname,
> _class = str(field.type))))
> tbl.append(row)
> if chkval:
> if txtval and opval != '':
> if field.type[0:10] == 'reference ':
> refsearch.append(self.get_query(field,
> opval, txtval, refsearch=True))
> else:
> value, error = field.validate(txtval)
> if not error:
> ### TODO deal with 'starts with', 'ends
> with', 'contains' on GAE
> query &= self.get_query(field, opval,
> value)
> else:
> row[3].append(DIV(error,_class='error'))
> selected.append(field)
> form = FORM(tbl,INPUT(_type="submit"))
> if selected:
> try:
> results = db(query).select(*selected, **args)
> for r in refsearch:
> results = results.find(r)
> except: # hmmm, we should do bettere here
> results = None
> return form, results
>
> On Jun 17, 8:41 pm, "mr.freeze" <[email protected]> wrote:
>
>
>
> > I will make a patch to enable this.
>
> > On Jun 17, 4:24 pm, rochacbruno <[email protected]> wrote:
>
> > > Sorry, I answered only to the author..
>
> > > This code:
> > > def crudsearch():
> > > form=crud.search(db.posts)
> > > return dict(form=form)
>
> > > returns a form like that:http://twitpic.com/1xmrao/full
>
> > > I know how to deal with the forms that way, but I'm talking about the
> > > search controls that holds operators ( greater, equals, starts.. etc)
> > > is there any way to access and modify these controls, just as we do
> > > with form controls?
>
> > > tks
>
> > > {{ }}'s
>
> > > On Jun 17, 12:30 pm, mdipierro <[email protected]> wrote:
>
> > > > crud.settings.formstyle='table2cols' or 'table3cols' or 'divs' or 'ul'
>
> > > > and for every field you have
>
> > > > db.table.field.label='...'
> > > > db.table.field.comment='...'
> > > > db.table.field.wdiget=....
>
> > > > On Jun 17, 8:35 am, rochacbruno <[email protected]> wrote:
>
> > > > > hello I did not find any documentation or example explaining how to
> > > > > customize a form created with crud.search()
> > > > > I would like to change the text displayed on the operators (dropdown)
> > > > > and change layout that other controls are displayed
>
> > > > > I can do that with Jquery and CSS, but I want to know which options I
> > > > > have in Action level,
>
> > > > > I tried consulting the crud.search on shell, some properties are
> > > > > displayed and I will play a lot with them, before doing that, I want
> > > > > to know if someone has any example or a resource link.
>
> > > > > anybody does?
>
> > > > > Thanks
>
> > > > > { }'s
> > > > > --http://rochacbruno.com.br