Commit ad488876 authored by Pietro Albini's avatar Pietro Albini

Fix pagination

parent db1a1c78
Pipeline #88 passed with stage
in 0 seconds
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import math
import time import time
import flask import flask
...@@ -21,7 +22,7 @@ import flask ...@@ -21,7 +22,7 @@ import flask
from uitwww import auth from uitwww import auth
ACTIONS_PER_PAGE = 5 ACTIONS_PER_PAGE = 25
class PageNotFoundError(BaseException): class PageNotFoundError(BaseException):
...@@ -59,12 +60,12 @@ def list_actions(page=None, session=None): ...@@ -59,12 +60,12 @@ def list_actions(page=None, session=None):
"SELECT COUNT(*) FROM actions %s;" % where, *args "SELECT COUNT(*) FROM actions %s;" % where, *args
)[0][0] )[0][0]
if page < 0 or page > total % ACTIONS_PER_PAGE: if page < 0 or page >= math.ceil(total / ACTIONS_PER_PAGE):
raise PageNotFoundError raise PageNotFoundError
result["current_page"] = page + 1 result["current_page"] = page + 1
result["has_prev"] = page != 0 result["has_prev"] = page != 0
result["has_next"] = page < total % ACTIONS_PER_PAGE result["has_next"] = page + 1 < math.ceil(total / ACTIONS_PER_PAGE)
limit = "LIMIT ? OFFSET ?" limit = "LIMIT ? OFFSET ?"
args += [ACTIONS_PER_PAGE, page * ACTIONS_PER_PAGE] args += [ACTIONS_PER_PAGE, page * ACTIONS_PER_PAGE]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment