Merge pull request #591 from prasadmuley/issue2006_export_customize_query_defined_in_searchable

Fix: Exporting from a SQLFORM.grid with customized search queries
This commit is contained in:
mdipierro committed 2015-01-16 13:06:26 -06:00
commit fe34d78578
1 file changed
+1 -14
+1 -14
View File
@@ -2326,7 +2326,7 @@ class SQLFORM(FORM):
expcolumns.append(str(field)) expcolumns.append(str(field))
if export_type in exportManager and exportManager[export_type]: if export_type in exportManager and exportManager[export_type]:
if keywords and not callable(searchable): if keywords:
try: try:
#the query should be constructed using searchable #the query should be constructed using searchable
#fields but not virtual fields #fields but not virtual fields
@@ -2343,19 +2343,6 @@ class SQLFORM(FORM):
except Exception, e: except Exception, e:
response.flash = T('Internal Error') response.flash = T('Internal Error')
rows = [] 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: else:
rows = dbset.select(left=left, orderby=orderby, rows = dbset.select(left=left, orderby=orderby,
cacheable=True, *selectable_columns) cacheable=True, *selectable_columns)