forked from rDrama/rDrama
add page numbers to the frontpage
parent
cad9847bf9
commit
558be41b3d
|
@ -1568,7 +1568,7 @@ nav
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
border: 1px solid #dee2e6;
|
border: 1px solid #dee2e6;
|
||||||
}
|
}
|
||||||
.page-link:hover {
|
.page-link:not(.dots):hover {
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
color: var(--primary);
|
color: var(--primary);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
@ -4437,7 +4437,11 @@ small, .small {
|
||||||
background-color: var(--dark);
|
background-color: var(--dark);
|
||||||
border: 0.1px solid #343a40;
|
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);
|
background-color: var(--gray-100);
|
||||||
}
|
}
|
||||||
.page-item.disabled .page-link {
|
.page-item.disabled .page-link {
|
||||||
|
|
|
@ -42,6 +42,10 @@ body, .navbar-light, .navbar-dark, .card, .modal-content, .comment-write textare
|
||||||
background-color: #ccc;
|
background-color: #ccc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.page-link.active {
|
||||||
|
color: #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
.sidebar
|
.sidebar
|
||||||
{
|
{
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
from sqlalchemy import or_, not_
|
from sqlalchemy import or_, not_
|
||||||
|
from sqlalchemy.orm import load_only
|
||||||
|
|
||||||
from files.classes.submission import Submission
|
from files.classes.submission import Submission
|
||||||
from files.classes.votes import Vote
|
from files.classes.votes import Vote
|
||||||
|
@ -50,7 +51,7 @@ def front_all(v, sub=None, subdomain=None):
|
||||||
pins = session.get(sort, default)
|
pins = session.get(sort, default)
|
||||||
holes = session.get('holes', True)
|
holes = session.get('holes', True)
|
||||||
|
|
||||||
ids, next_exists = frontlist(sort=sort,
|
ids, next_exists, size = frontlist(sort=sort,
|
||||||
page=page,
|
page=page,
|
||||||
t=t,
|
t=t,
|
||||||
v=v,
|
v=v,
|
||||||
|
@ -69,7 +70,7 @@ def front_all(v, sub=None, subdomain=None):
|
||||||
award_timers(v)
|
award_timers(v)
|
||||||
|
|
||||||
if v and v.client: return {"data": [x.json(g.db) for x in posts], "next_exists": next_exists}
|
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')
|
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
|
if v: size = v.frontsize or 0
|
||||||
else: size = PAGE_SIZE
|
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:
|
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 = []
|
to_remove = []
|
||||||
for h in LIMITED_WPD_HOLES:
|
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]
|
posts = [x for x in posts if x.id not in to_remove]
|
||||||
else:
|
else:
|
||||||
posts = posts.offset(size * (page - 1)).limit(size+1).all()
|
posts = posts.limit(size).all()
|
||||||
|
|
||||||
next_exists = (len(posts) > size)
|
|
||||||
posts = posts[:size]
|
|
||||||
|
|
||||||
if pins and page == 1 and not gt and not lt:
|
if pins and page == 1 and not gt and not lt:
|
||||||
if sub:
|
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:
|
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:
|
if v:
|
||||||
pins = pins.filter(or_(Submission.sub == None, Submission.sub.notin_(v.all_blocks)))
|
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
|
posts = pins + posts
|
||||||
|
|
||||||
if ids_only: posts = [x.id for x in posts]
|
if ids_only: posts = [x.id for x in posts]
|
||||||
return posts, next_exists
|
return posts, next_exists, size
|
||||||
|
|
||||||
|
|
||||||
@app.get("/random_post")
|
@app.get("/random_post")
|
||||||
|
|
|
@ -162,19 +162,45 @@
|
||||||
{% if listing %}
|
{% if listing %}
|
||||||
<nav>
|
<nav>
|
||||||
<ul class="pagination pagination-sm mb-0">
|
<ul class="pagination pagination-sm mb-0">
|
||||||
{% if page>1 %}
|
{% set num_pages = (next_exists / size) | round(0, 'ceil') | int %}
|
||||||
<li class="page-item">
|
|
||||||
<small><a class="page-link" href="?sort={{sort}}&page={{page-1}}&t={{t}}" tabindex="-1">Prev</a></small>
|
{% set start_point = page - 2 %}
|
||||||
</li>
|
{% if start_point < 1 %}
|
||||||
{% else %}
|
{% set start_point = 1 %}
|
||||||
<li class="page-item disabled"><span class="page-link">Prev</span></li>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if next_exists %}
|
|
||||||
|
{% 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">
|
<li class="page-item">
|
||||||
<small><a class="page-link" href="?sort={{sort}}&page={{page+1}}&t={{t}}">Next</a></small>
|
<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>
|
</li>
|
||||||
{% else %}
|
|
||||||
<li class="page-item disabled"><span class="page-link">Next</span></li>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
Loading…
Reference in New Issue