diff --git a/VERSION b/VERSION index 7e59d385..af25b765 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.2.1 (2012-11-08 10:04:19) stable +Version 2.2.1 (2012-11-08 10:05:43) stable diff --git a/gluon/dal.py b/gluon/dal.py index 463a74d2..66533eb2 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -4588,7 +4588,7 @@ class GoogleDatastoreAdapter(NoSQLAdapter): processor = attributes.get('processor',self.parse) return processor(rows,fields,colnames,False) - def count(self,query,distinct=None): + def count(self,query,distinct=None,limit=None): if distinct: raise RuntimeError("COUNT DISTINCT not supported") (items, tablename, fields) = self.select_raw(query) @@ -4596,7 +4596,7 @@ class GoogleDatastoreAdapter(NoSQLAdapter): try: return len(items) except TypeError: - return items.count(limit=None) + return items.count(limit=limit) def delete(self,tablename, query): """ diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index 8c3e83d4..772e0e10 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -2017,6 +2017,9 @@ class SQLFORM(FORM): c = 'count(*)' nrows = dbset.select(c, left=left, cacheable=True, groupby=groupby).first()[c] + elif dbset._db._adapter.dbengine=='google:datastore': + #if we don't set a limit, this can timeout for a large table + nrows = dbset.db._adapter.count(dbset.query, limit=1000) else: nrows = dbset.count() except: @@ -2078,8 +2081,64 @@ class SQLFORM(FORM): head = TR(*headcols, _class=ui.get('header')) + cursor = True + #figure out what page we are one to setup the limitby + if paginate and dbset._db._adapter.dbengine=='google:datastore': + cursor = request.vars.cursor or True + limitby = (0, paginate) + try: page = int(request.vars.page or 1)-1 + except ValueError: page = 0 + elif paginate and paginate=1000: + message = T('at least %(nrows)s records found') % dict(nrows=nrows) + else: + message = T('%(nrows)s records found') % dict(nrows=nrows) + console.append(DIV(message,_class='web2py_counter')) + paginator = UL() - if paginate and paginate < nrows: + if paginate and dbset._db._adapter.dbengine=='google:datastore': + #this means we may have a large table with an unknown number of rows. + try: + page = int(request.vars.page or 1)-1 + except ValueError: + page = 0 + paginator.append(LI('page %s'%(page+1))) + if next_cursor: + d = dict(page=page+2, cursor=next_cursor) + if order: d['order']=order + if request.vars.keywords: d['keywords']=request.vars.keywords + paginator.append(LI( + A('next',_href=url(vars=d),_class=trap_class()))) + elif paginate and paginate