Merge pull request #163 from niphlod/issue/grid_and_groupby

fixed issue with grid and groupby
This commit is contained in:
mdipierro
2013-08-07 07:30:48 -07:00
+13 -8
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,11 +1834,11 @@ 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]
elif left: elif left:
c = 'count(*)' c = 'count(*)'
@@ -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':
@@ -2630,7 +2635,7 @@ class SQLFORM(FORM):
if isinstance(item,Table) and item._tablename in check: if isinstance(item,Table) and item._tablename in check:
tablename = item._tablename tablename = item._tablename
linked_fieldnames = check[tablename] linked_fieldnames = check[tablename]
td = item td = item
elif isinstance(item,str) and item in check: elif isinstance(item,str) and item in check:
tablename = item tablename = item
linked_fieldnames = check[item] linked_fieldnames = check[item]