From ade4323edb1e1110565f9564120ab3b2d0dc9241 Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 5 May 2023 06:52:53 +0300 Subject: [PATCH] paginate /admin/image_posts --- files/routes/admin.py | 17 ++++++++++++----- files/templates/admin/image_posts.html | 19 +------------------ 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/files/routes/admin.py b/files/routes/admin.py index 4cdb9d304..b334bdc0c 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -4,6 +4,7 @@ from math import floor import os from sqlalchemy.exc import IntegrityError +from sqlalchemy.orm import load_only from psycopg2.errors import UniqueViolation from files.__main__ import app, cache, limiter @@ -298,13 +299,19 @@ def image_posts_listing(v): try: page = int(request.values.get('page', 1)) except: page = 1 - posts = g.db.query(Submission).order_by(Submission.id.desc()) + posts = g.db.query(Submission).options( + load_only(Submission.id, Submission.url) + ).order_by(Submission.id.desc()) + + posts = [x.id for x in posts if x.is_image] + + next_exists = len(posts) firstrange = PAGE_SIZE * (page - 1) - secondrange = firstrange + PAGE_SIZE + 1 - posts = [x.id for x in posts if x.is_image][firstrange:secondrange] - next_exists = (len(posts) > PAGE_SIZE) - posts = get_posts(posts[:PAGE_SIZE], v=v) + secondrange = firstrange + PAGE_SIZE + posts = posts[firstrange:secondrange] + + posts = get_posts(posts, v=v) return render_template("admin/image_posts.html", v=v, listing=posts, next_exists=next_exists, page=page, sort="new") diff --git a/files/templates/admin/image_posts.html b/files/templates/admin/image_posts.html index f3ee50a99..6bd855152 100644 --- a/files/templates/admin/image_posts.html +++ b/files/templates/admin/image_posts.html @@ -17,22 +17,5 @@ {% endblock %} {% block pagenav %} - +{% include "pagination.html" %} {% endblock %}