Flask + Vue rewrite of the classic-ASP shopdb, built as a plugin framework so sister GE Aerospace sites can adopt it. Product version 0.7.0-pre-0.8.0, plugin contract 0.11.0, 966 backend tests. Key entry points: - docs/INSTALL-WINDOWS-IIS.md - tested Windows + IIS install runbook (own-site and subpath deployment methods) - docs/PILOT-DEPLOY.md - production pilot: stand up + import + verify - docs/IMPORT-API.md - schema-agnostic legacy data import contract - scripts/site_imports/wjf/ - West Jefferson reference import loader - docs/adr/ - twelve accepted architecture decision records
44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
"""Pagination utilities."""
|
|
|
|
from flask import request, current_app
|
|
from typing import Tuple
|
|
|
|
|
|
def get_pagination_params(request_obj=None) -> Tuple[int, int]:
|
|
"""
|
|
Extract pagination parameters from request.
|
|
|
|
Returns:
|
|
Tuple of (page, per_page)
|
|
"""
|
|
if request_obj is None:
|
|
request_obj = request
|
|
|
|
default_size = current_app.config.get('DEFAULT_PAGE_SIZE', 20)
|
|
max_size = current_app.config.get('MAX_PAGE_SIZE', 100)
|
|
|
|
try:
|
|
page = max(1, int(request_obj.args.get('page', 1)))
|
|
except (TypeError, ValueError):
|
|
page = 1
|
|
|
|
try:
|
|
per_page = int(request_obj.args.get('perpage', request_obj.args.get('per_page', default_size)))
|
|
per_page = max(1, min(per_page, max_size))
|
|
except (TypeError, ValueError):
|
|
per_page = default_size
|
|
|
|
return page, per_page
|
|
|
|
|
|
def paginate_query(query, page: int, per_page: int):
|
|
"""
|
|
Apply pagination to a SQLAlchemy query.
|
|
|
|
Returns:
|
|
Tuple of (items, total)
|
|
"""
|
|
total = query.count()
|
|
items = query.offset((page - 1) * per_page).limit(per_page).all()
|
|
return items, total
|