forked from MarseyWorld/MarseyWorld
paginate /admin/image_posts
parent
a76c12205d
commit
ade4323edb
|
@ -4,6 +4,7 @@ from math import floor
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
from sqlalchemy.orm import load_only
|
||||||
from psycopg2.errors import UniqueViolation
|
from psycopg2.errors import UniqueViolation
|
||||||
|
|
||||||
from files.__main__ import app, cache, limiter
|
from files.__main__ import app, cache, limiter
|
||||||
|
@ -298,13 +299,19 @@ def image_posts_listing(v):
|
||||||
try: page = int(request.values.get('page', 1))
|
try: page = int(request.values.get('page', 1))
|
||||||
except: 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)
|
firstrange = PAGE_SIZE * (page - 1)
|
||||||
secondrange = firstrange + PAGE_SIZE + 1
|
secondrange = firstrange + PAGE_SIZE
|
||||||
posts = [x.id for x in posts if x.is_image][firstrange:secondrange]
|
posts = posts[firstrange:secondrange]
|
||||||
next_exists = (len(posts) > PAGE_SIZE)
|
|
||||||
posts = get_posts(posts[:PAGE_SIZE], v=v)
|
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")
|
return render_template("admin/image_posts.html", v=v, listing=posts, next_exists=next_exists, page=page, sort="new")
|
||||||
|
|
||||||
|
|
|
@ -17,22 +17,5 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block pagenav %}
|
{% block pagenav %}
|
||||||
<nav>
|
{% include "pagination.html" %}
|
||||||
<ul class="pagination pagination-sm py-3 pl-3 mb-0">
|
|
||||||
{% if page>1 %}
|
|
||||||
<li class="page-item">
|
|
||||||
<small><a class="page-link" href="?page={{page-1}}" tabindex="-1">Prev</a></small>
|
|
||||||
</li>
|
|
||||||
{% else %}
|
|
||||||
<li class="page-item disabled"><span class="page-link">Prev</span></li>
|
|
||||||
{% endif %}
|
|
||||||
{% if next_exists %}
|
|
||||||
<li class="page-item">
|
|
||||||
<small><a class="page-link" href="?page={{page+1}}">Next</a></small>
|
|
||||||
</li>
|
|
||||||
{% else %}
|
|
||||||
<li class="page-item disabled"><span class="page-link">Next</span></li>
|
|
||||||
{% endif %}
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue