CORRECTION: I got the boolean wrong below... In fact, I fixed it by editing sqlhtml.py to force the exporter to condition on (request.vars.keywords *and not callable(searchable)*) before setting up the rows object to export. That is, if searchable is not defined, then SQLFORM.build_query gets called, else use the query as defined by searchable. Here is the correct working code:
if request.vars.keywords *and not callable(searchable)*: try: #the query should be constructed using searchable fields but not virtual fields sfields = reduce(lambda a, b: a + b, [[f for f in t if f.readable and not isinstance(f, Field.Virtual)] for t in tables]) dbset = dbset(SQLFORM.build_query( sfields, request.vars.get('keywords', ''))) rows = dbset.select(left=left, orderby=orderby, cacheable=True, *selectable_columns) except Exception, e: response.flash = T('Internal Error') rows = [] else: rows = dbset.select(left=left, orderby=orderby, cacheable=True, *selectable_columns) My question still stands... Is this a bug or is there a better way to do an export of customized search results using SQLFORM.grid? THx, dex* On Thursday, October 23, 2014 11:23:16 AM UTC-7, Dexter Hadley wrote: > > Hi All, > > This is my first time posting a question, so thanks to Massimo and they > whole community for making web2py. Its great! > > I am trying to export results from a customized full-text search using > SQLFORM.grid. My backend is a Postgres db, and I successfully define > "search_widget" and "searchable" functions that are passed to the > SQLFORM.grid to do the full-text search. It will works pretty well on the > web app. However, once I click the export button, SQLFORM.grid apparently > recreates the query using the default SQLFORM.build_query and ignores the > correct query which I define in searchable. After poking around in > sqlhtml.py, I found this is so because the exporter only conditions on > request.vars.keywords before calling SQLFORM.build_query, and it does not > check for callable(searchable) which I think it should do. In fact, I > fixed it by editing sqlhtml.py to force the exporter to condition on > (request.vars.keywords *and callable(searchable)*) before setting up the > rows object to export. The code I added is in bold below (on line 2298 of > sqlhtml.py): > > if request.vars.keywords *and callable(searchable)*: > try: > #the query should be constructed using searchable > fields but not virtual fields > sfields = reduce(lambda a, b: a + b, > [[f for f in t if f.readable and not > isinstance(f, Field.Virtual)] for t in tables]) > dbset = dbset(SQLFORM.build_query( > sfields, request.vars.get('keywords', ''))) > rows = dbset.select(left=left, orderby=orderby, > cacheable=True, > *selectable_columns) > except Exception, e: > response.flash = T('Internal Error') > rows = [] > else: > rows = dbset.select(left=left, orderby=orderby, > cacheable=True, > *selectable_columns) > > Is this a bug or is there a better way to do an export of customized > search results using SQLFORM.grid? I'm using the current version of > everything (web2py 2.9.11, Postgres 9.3, Python 2.7.8). Thx again, > > dex* > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.