Files
shopdb-flask/shopdb/utils/pagination.py
cproudlock 9efdb5f52d Add print badges, pagination, route splitting, JWT auth fixes, and list page alignment
- Fix equipment badge barcode not rendering (loading race condition)
- Fix printer QR code not rendering on initial load (same race condition)
- Add model image to equipment badge via imageurl from Model table
- Fix white-on-white machine number text on badge, tighten barcode spacing
- Add PaginationBar component used across all list pages
- Split monolithic router into per-plugin route modules
- Fix 25 GET API endpoints returning 401 (jwt_required -> optional=True)
- Align list page columns across Equipment, PCs, and Network pages
- Add print views: EquipmentBadge, PrinterQRSingle, PrinterQRBatch, USBLabelBatch
- Add PC Relationships report, migration docs, and CLAUDE.md project guide
- Various plugin model, API, and frontend refinements

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 07:32:44 -05:00

44 lines
1.0 KiB
Python

"""Pagination utilities."""
from flask import request, current_app
from typing import Tuple
def get_pagination_params(req=None) -> Tuple[int, int]:
"""
Extract pagination parameters from request.
Returns:
Tuple of (page, per_page)
"""
if req is None:
req = 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(req.args.get('page', 1)))
except (TypeError, ValueError):
page = 1
try:
per_page = int(req.args.get('perpage', req.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