15 lines
445 B
Python
15 lines
445 B
Python
"""Shared page/per_page parsing (Chapter 11: consistent across every
|
|
Grid.js-backed endpoint)."""
|
|
from __future__ import annotations
|
|
|
|
from flask import Request
|
|
|
|
DEFAULT_PER_PAGE = 20
|
|
MAX_PER_PAGE = 100
|
|
|
|
|
|
def parse_pagination(request: Request) -> tuple[int, int]:
|
|
page = max(1, request.args.get("page", 1, type=int))
|
|
per_page = request.args.get("per_page", DEFAULT_PER_PAGE, type=int)
|
|
return page, max(1, min(per_page, MAX_PER_PAGE))
|