I don't know why you're having the problems you are.
Regarding the lambda issue, I too have noticed the change, but thought
it worked throughout web2py to always pass the row argument. However,
I'm no longer using crud so I wouldn't notice that.
Linked tables are working for me. What do you mean when you say it
doesn't work for view and edit?
Constraints has been working for me - here is a sample:
# Build query
queries = []
constraints = None
if searchText and searchText .strip() != '':
queries.append(db.asset.description.contains(searchText))
if assetTypeId and assetTypeId > 0:
queries.append(db.asset.assetTypeId==assetTypeId)
if len(queries) > 0:
query = reduce(lambda a,b:(a&b),queries)
constraints={'asset':query}
# Setup search forms
searchForms = {'asset':assetSearch}
grid = SQLFORM.smartgrid(db.asset, fields=fields,
constraints=constraints, orderby=orderby,
create=create, details=details,
editable=editable, deletable=deletable,
csv=False,
search_widget={'asset':assetSearch},
searchable=True,
paginate=15, maxtextlength=45)
All of these work ok for me. Possibly your use cases are different that
mine. Could you share some detail about what you are seeing that isn't
working for you?
-Jim
On 12/26/2011 8:23 AM, Alexandre Andrade wrote:
I'm trying to use smartgrid in a app, and could be sucessful in most
parts.
But there are some things stopping, so I'm here asking for help
1. The old way of use lambda in represent was
represent = lambda field: get_atividade(field)
and now, in some parts of smartgrid and book V4, look as:
represent = lambda field,row : get_atividade(field)
the last works with the grid, but not in form to view and crud.
I solved this using a if statement, but I think that could be
implemented one way to do use represent without setting it every time.
2. The linked_tables settings works for grid, but not for form (view
and edit) . I looked at code (gluon/sqlhtml.py#..smartgrid)
, and found this:
if linked_tables is None or referee in linked_tables:
field.represent = lambda
id,r=None,referee=referee,rep=field.represent: A(callable(rep) and
rep(id) or
id,_class=trap_class(),_href=URL(args=request.args[:nargs]+['view',referee,id],
user_signature=user_signature))
i think referee is a way to know if is viewing or edit form, but it
always show all the linked_tables, so linked_tables settings is
uselless. I think it could remove the second part of if to properly
use the settings way.
3. I need to show only some registers in a grid. But whiles the docs
talk about the constraints settings, i cant find a example of query to
make it work. A workaround was use the keywords (as in user made
query, but it has the disavantage of show the query in the search field.
Could someone provide a example of using constraints?
--
Atenciosamente
Alexandre Andrade
Hipercenter.com Classificados Gratuitos