Fix grid bug if "current page" becomes invalid
sometimes it was possible to fall outside the valid page range, in which case grid would stop showing results!
This commit is contained in:
parent
69778a4682
commit
cb6b093a2a
|
@ -698,11 +698,11 @@ class Grid(object):
|
|||
page = self.request.GET.get('page')
|
||||
if page is not None:
|
||||
if page.isdigit():
|
||||
settings['page'] = page
|
||||
settings['page'] = int(page)
|
||||
else:
|
||||
page = self.request.session.get('grid.{}.page'.format(self.key))
|
||||
if page is not None:
|
||||
settings['page'] = page
|
||||
settings['page'] = int(page)
|
||||
|
||||
def persist_settings(self, settings, to='session'):
|
||||
"""
|
||||
|
@ -775,12 +775,26 @@ class Grid(object):
|
|||
Paginate the given data set according to current settings, and return
|
||||
the result.
|
||||
"""
|
||||
if self.model_class:
|
||||
return SqlalchemyOrmPage(data,
|
||||
items_per_page=self.pagesize,
|
||||
page=self.page,
|
||||
url_maker=URLMaker(self.request))
|
||||
return data
|
||||
if not self.model_class:
|
||||
return data
|
||||
|
||||
# we of course assume our current page is correct, at first
|
||||
pager = self.make_pager(data)
|
||||
|
||||
# if pager has detected that our current page is outside the valid
|
||||
# range, we must re-orient ourself around the "new" (valid) page
|
||||
if pager.page != self.page:
|
||||
self.page = pager.page
|
||||
self.request.session['grid.{}.page'.format(self.key)] = self.page
|
||||
pager = self.make_pager(data)
|
||||
|
||||
return pager
|
||||
|
||||
def make_pager(self, data):
|
||||
return SqlalchemyOrmPage(data,
|
||||
items_per_page=self.pagesize,
|
||||
page=self.page,
|
||||
url_maker=URLMaker(self.request))
|
||||
|
||||
def make_visible_data(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue