fixed issue with grid and groupby

This commit is contained in:
niphlod
2013-08-07 15:39:54 +02:00
parent ae4d9dab10
commit ad2f177592
+11 -6
View File
@@ -26,7 +26,7 @@ from html import FORM, INPUT, LABEL, OPTION, SELECT
from html import TABLE, THEAD, TBODY, TR, TD, TH, STYLE from html import TABLE, THEAD, TBODY, TR, TD, TH, STYLE
from html import URL, truncate_string, FIELDSET from html import URL, truncate_string, FIELDSET
from dal import DAL, Field, Table, Row, CALLABLETYPES, smart_query, \ from dal import DAL, Field, Table, Row, CALLABLETYPES, smart_query, \
bar_encode, Reference, REGEX_TABLE_DOT_FIELD bar_encode, Reference, REGEX_TABLE_DOT_FIELD, Expression
from storage import Storage from storage import Storage
from utils import md5_hash from utils import md5_hash
from validators import IS_EMPTY_OR, IS_NOT_EMPTY, IS_LIST_OF, IS_DATE, \ from validators import IS_EMPTY_OR, IS_NOT_EMPTY, IS_LIST_OF, IS_DATE, \
@@ -1834,9 +1834,9 @@ class SQLFORM(FORM):
## if it's not an integer ## if it's not an integer
if cache_count is None or isinstance(cache_count, tuple): if cache_count is None or isinstance(cache_count, tuple):
if groupby: if groupby:
c = 'count(*) _tmp' c = 'count(*)'
nrows = db.executesql( nrows = db.executesql(
'select count(*) from (%s);' % 'select count(*) from (%s) _tmp;' %
dbset._select(c, left=left, cacheable=True, dbset._select(c, left=left, cacheable=True,
groupby=groupby, groupby=groupby,
cache=cache_count)[:-1])[0][0] cache=cache_count)[:-1])[0][0]
@@ -1932,11 +1932,16 @@ class SQLFORM(FORM):
columns.append(f) columns.append(f)
fields.append(f) fields.append(f)
if not field_id: if not field_id:
field_id = tables[0]._id if groupby is None:
if not any(str(f)==str(field_id) for f in fields): field_id = tables[0]._id
fields = [f for f in fields]+[field_id] elif groupby and isinstance(groupby, Field):
field_id = groupby #take the field passed as groupby
elif groupby and isinstance(groupby, Expression):
field_id = groupby.first #take the first groupby field
table = field_id.table table = field_id.table
tablename = table._tablename tablename = table._tablename
if not any(str(f)==str(field_id) for f in fields):
fields = [f for f in fields]+[field_id]
if upload == '<default>': if upload == '<default>':
upload = lambda filename: url(args=['download', filename]) upload = lambda filename: url(args=['download', filename])
if request.args(-2) == 'download': if request.args(-2) == 'download':