mirror of
https://github.com/ProjectSynthoria/SynthoriaArchive.git
synced 2025-03-12 23:36:54 +02:00

* Update isort settings * Apply import sorting (isort) on all files in nyaa/ * Fixed Flake8 errors in nyaa/ (see PR for list) * Add isort to lint.sh and requirements.txt
27 lines
683 B
Python
27 lines
683 B
Python
from flask import abort
|
|
from flask_sqlalchemy import BaseQuery, Pagination
|
|
|
|
|
|
def paginate_faste(self, page=1, per_page=50, max_page=None, step=5, count_query=None):
|
|
if page < 1:
|
|
abort(404)
|
|
|
|
if max_page and page > max_page:
|
|
abort(404)
|
|
|
|
# Count all items
|
|
if count_query is not None:
|
|
total_query_count = count_query.scalar()
|
|
else:
|
|
total_query_count = self.count()
|
|
|
|
# Grab items on current page
|
|
items = self.limit(per_page).offset((page - 1) * per_page).all()
|
|
|
|
if not items and page != 1:
|
|
abort(404)
|
|
|
|
return Pagination(self, page, per_page, total_query_count, items)
|
|
|
|
|
|
BaseQuery.paginate_faste = paginate_faste
|