add page numbers to the frontpage

master
Aevann 2023-05-01 22:50:32 +03:00
parent cad9847bf9
commit 558be41b3d
4 changed files with 59 additions and 24 deletions

View File

@ -1568,7 +1568,7 @@ nav
background-color: #fff;
border: 1px solid #dee2e6;
}
.page-link:hover {
.page-link:not(.dots):hover {
z-index: 2;
color: var(--primary);
text-decoration: none;
@ -4437,7 +4437,11 @@ small, .small {
background-color: var(--dark);
border: 0.1px solid #343a40;
}
.page-link:hover {
.page-link.active {
background-color: var(--primary);
color: var(--dark);
}
.page-link:not(.dots):hover {
background-color: var(--gray-100);
}
.page-item.disabled .page-link {

View File

@ -42,6 +42,10 @@ body, .navbar-light, .navbar-dark, .card, .modal-content, .comment-write textare
background-color: #ccc;
}
.page-link.active {
color: #ccc;
}
.sidebar
{
border-radius: 6px;

View File

@ -1,5 +1,6 @@
from sqlalchemy import or_, not_
from sqlalchemy.orm import load_only
from files.classes.submission import Submission
from files.classes.votes import Vote
@ -50,7 +51,7 @@ def front_all(v, sub=None, subdomain=None):
pins = session.get(sort, default)
holes = session.get('holes', True)
ids, next_exists = frontlist(sort=sort,
ids, next_exists, size = frontlist(sort=sort,
page=page,
t=t,
v=v,
@ -69,7 +70,7 @@ def front_all(v, sub=None, subdomain=None):
award_timers(v)
if v and v.client: return {"data": [x.json(g.db) for x in posts], "next_exists": next_exists}
return render_template("home.html", v=v, listing=posts, next_exists=next_exists, sort=sort, t=t, page=page, sub=sub, home=True, pins=pins, holes=holes)
return render_template("home.html", v=v, listing=posts, next_exists=next_exists, sort=sort, t=t, page=page, sub=sub, home=True, pins=pins, holes=holes, size=size)
LIMITED_WPD_HOLES = ('gore', 'aftermath', 'selfharm', 'meta', 'discussion', 'social', 'music', 'request')
@ -118,8 +119,11 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
if v: size = v.frontsize or 0
else: size = PAGE_SIZE
next_exists = posts.count()
posts = posts.options(load_only(Submission.id)).offset(size * (page - 1))
if SITE_NAME == 'WPD' and sort == "hot" and sub == None:
posts = posts.offset(size * (page - 1)).limit(201).all()
posts = posts.limit(200).all()
to_remove = []
for h in LIMITED_WPD_HOLES:
@ -127,16 +131,13 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
posts = [x for x in posts if x.id not in to_remove]
else:
posts = posts.offset(size * (page - 1)).limit(size+1).all()
next_exists = (len(posts) > size)
posts = posts[:size]
posts = posts.limit(size).all()
if pins and page == 1 and not gt and not lt:
if sub:
pins = g.db.query(Submission).filter(Submission.sub == sub.name, Submission.hole_pinned != None)
pins = g.db.query(Submission).options(load_only(Submission.id)).filter(Submission.sub == sub.name, Submission.hole_pinned != None)
else:
pins = g.db.query(Submission).filter(Submission.stickied != None, Submission.is_banned == False)
pins = g.db.query(Submission).options(load_only(Submission.id)).filter(Submission.stickied != None, Submission.is_banned == False)
if v:
pins = pins.filter(or_(Submission.sub == None, Submission.sub.notin_(v.all_blocks)))
@ -154,7 +155,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
posts = pins + posts
if ids_only: posts = [x.id for x in posts]
return posts, next_exists
return posts, next_exists, size
@app.get("/random_post")

View File

@ -162,19 +162,45 @@
{% if listing %}
<nav>
<ul class="pagination pagination-sm mb-0">
{% if page>1 %}
<li class="page-item">
<small><a class="page-link" href="?sort={{sort}}&page={{page-1}}&t={{t}}" tabindex="-1">Prev</a></small>
</li>
{% else %}
<li class="page-item disabled"><span class="page-link">Prev</span></li>
{% set num_pages = (next_exists / size) | round(0, 'ceil') | int %}
{% set start_point = page - 2 %}
{% if start_point < 1 %}
{% set start_point = 1 %}
{% endif %}
{% if next_exists %}
<li class="page-item">
<small><a class="page-link" href="?sort={{sort}}&page={{page+1}}&t={{t}}">Next</a></small>
</li>
{% else %}
<li class="page-item disabled"><span class="page-link">Next</span></li>
{% set end_point = start_point+4 %}
{% if end_point > num_pages %}
{% set start_point = start_point-(end_point-num_pages) %}
{% set end_point = num_pages %}
{% endif %}
{% if start_point > 1 %}
<li class="page-item">
<small><a class="page-link" href="?sort={{sort}}&page=1&t={{t}}">1</a></small>
</li>
{% if start_point != 2 %}
<li class="page-item">
<small><a class="page-link dots">...</a></small>
</li>
{% endif %}
{% endif %}
{% for x in range(start_point, end_point+1) %}
<li class="page-item">
<small><a class="page-link {% if x == page %}active{% endif %}" href="?sort={{sort}}&page={{x}}&t={{t}}">{{x}}</a></small>
</li>
{% endfor %}
{% if end_point < num_pages %}
{% if end_point != num_pages-1 %}
<li class="page-item">
<small><a class="page-link dots">...</a></small>
</li>
{% endif %}
<li class="page-item">
<small><a class="page-link" href="?sort={{sort}}&page={{num_pages}}&t={{t}}">{{num_pages}}</a></small>
</li>
{% endif %}
</ul>
</nav>