Hello Massimo and Dexter,
I've a fix for this issue. I've tested it and attached the diff
file. PFA.
Let me know if I missed anything.
Btw Can I send pull request?
On Saturday, October 25, 2014 at 5:17:24 AM UTC+5:30, Massimo Di Pierro
wrote:
>
> Hello Dexter, I think your are right. I will review this asap. Meanwhile,
> would you be able to open an issue with a link to this thread so we can
> more easily keep track. Thanks!.
>
> Massimo
>
> On Thursday, 23 October 2014 13:23:16 UTC-5, 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 [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py
index 28c3761..6e32aa2 100644
--- a/gluon/sqlhtml.py
+++ b/gluon/sqlhtml.py
@@ -2326,7 +2326,7 @@ class SQLFORM(FORM):
expcolumns.append(str(field))
if export_type in exportManager and exportManager[export_type]:
- if keywords:
+ if keywords and not callable(searchable):
try:
#the query should be constructed using searchable
#fields but not virtual fields
@@ -2339,6 +2339,19 @@ class SQLFORM(FORM):
except Exception, e:
response.flash = T('Internal Error')
rows = []
+ elif callable(searchable):
+ #use custom_query using 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(searchable(sfields, 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)