use new pagination system everywhere it isnt used

master
Aevann 2023-05-06 00:44:24 +03:00
parent e2e767a472
commit 92f0154e67
16 changed files with 167 additions and 228 deletions

View File

@ -37,18 +37,15 @@ class OauthApp(Base):
return f"{SITE_FULL}/admin/app/{self.id}"
@lazy
def idlist(self, db:scoped_session, page=1):
posts = db.query(Submission.id).filter_by(app_id=self.id)
posts=posts.order_by(Submission.created_utc.desc())
posts=posts.offset(100*(page-1)).limit(101)
return [x[0] for x in posts.all()]
def idlist(self, cls, page=1):
items = db.query(cls).options(load_only(cls.id)).filter_by(app_id=self.id)
total = items.count()
@lazy
def comments_idlist(self, db:scoped_session, page=1):
posts = db.query(Comment.id).filter_by(app_id=self.id)
posts=posts.order_by(Comment.id.desc())
posts=posts.offset(100*(page-1)).limit(101)
return [x[0] for x in posts.all()]
items = items.order_by(cls.created_utc.desc())
items = items.offset(100*(page-1)).limit(100)
items = [x.id for x in items.all()]
return items, total
class ClientAuth(Base):

View File

@ -50,7 +50,7 @@ def dm_images(v):
with open(f"{LOG_DIRECTORY}/dm_images.log", "r", encoding="utf-8") as f:
items=f.read().split("\n")[:-1]
next_exists = len(items)
total = len(items)
items = [x.split(", ") for x in items]
items.reverse()
@ -61,7 +61,7 @@ def dm_images(v):
secondrange = firstrange + PAGE_SIZE
items = items[firstrange:secondrange]
return render_template("admin/dm_images.html", v=v, items=items, next_exists=next_exists, page=page)
return render_template("admin/dm_images.html", v=v, items=items, total=total, page=page)
@app.get('/admin/edit_rules')
@limiter.limit(DEFAULT_RATELIMIT)
@ -305,7 +305,7 @@ def image_posts_listing(v):
posts = [x.id for x in posts if x.is_image]
next_exists = len(posts)
total = len(posts)
firstrange = PAGE_SIZE * (page - 1)
secondrange = firstrange + PAGE_SIZE
@ -313,7 +313,7 @@ def image_posts_listing(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, total=total, page=page, sort="new")
@app.get("/admin/reported/posts")
@ -329,14 +329,14 @@ def reported_posts(v):
deleted_utc=0
).join(Submission.flags)
next_exists = listing.count()
total = listing.count()
listing = listing.order_by(Submission.id.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE)
listing = [p.id for p in listing]
listing = get_posts(listing, v=v)
return render_template("admin/reported_posts.html",
next_exists=next_exists, listing=listing, page=page, v=v)
total=total, listing=listing, page=page, v=v)
@app.get("/admin/reported/comments")
@ -352,14 +352,14 @@ def reported_comments(v):
deleted_utc=0
).join(Comment.flags)
next_exists = listing.count()
total = listing.count()
listing = listing.order_by(Comment.id.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE)
listing = [c.id for c in listing]
listing = get_comments(listing, v=v)
return render_template("admin/reported_comments.html",
next_exists=next_exists,
total=total,
listing=listing,
page=page,
v=v,
@ -738,7 +738,7 @@ def admin_removed(v):
listing = g.db.query(Submission).options(load_only(Submission.id)).join(Submission.author).filter(
or_(Submission.is_banned==True, User.shadowbanned != None))
next_exists = listing.count()
total = listing.count()
listing = listing.order_by(Submission.id.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
listing = [x.id for x in listing]
@ -748,7 +748,7 @@ def admin_removed(v):
v=v,
listing=posts,
page=page,
next_exists=next_exists
total=total
)
@ -762,7 +762,7 @@ def admin_removed_comments(v):
listing = g.db.query(Comment).options(load_only(Comment.id)).join(Comment.author).filter(
or_(Comment.is_banned==True, User.shadowbanned != None))
next_exists = listing.count()
total = listing.count()
listing = listing.order_by(Comment.id.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
listing = [x.id for x in listing]
@ -772,7 +772,7 @@ def admin_removed_comments(v):
v=v,
listing=comments,
page=page,
next_exists=next_exists
total=total
)

View File

@ -15,7 +15,7 @@ from files.__main__ import app
def feeds_user(sort='hot', t='all'):
page = get_page()
ids, next_exists, size = frontlist(
ids, total, size = frontlist(
sort=sort,
page=page,
t=t,

View File

@ -48,7 +48,7 @@ def front_all(v, sub=None, subdomain=None):
pins = session.get(sort, default)
ids, next_exists, size = frontlist(sort=sort,
ids, total, size = frontlist(sort=sort,
page=page,
t=t,
v=v,
@ -65,8 +65,8 @@ def front_all(v, sub=None, subdomain=None):
if v.hidevotedon: posts = [x for x in posts if not hasattr(x, 'voted') or not x.voted]
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, size=size)
if v and v.client: return {"data": [x.json(g.db) for x in posts], "total": total}
return render_template("home.html", v=v, listing=posts, total=total, sort=sort, t=t, page=page, sub=sub, home=True, pins=pins, size=size)
LIMITED_WPD_HOLES = ('gore', 'aftermath', 'selfharm', 'meta', 'discussion', 'social', 'music', 'request')
@ -107,7 +107,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
word = word.replace('\\', '').replace('_', '\_').replace('%', '\%').strip()
posts=posts.filter(not_(Submission.title.ilike(f'%{word}%')))
next_exists = posts.count()
total = posts.count()
posts = sort_objects(sort, posts, Submission)
@ -149,7 +149,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, size
return posts, total, size
@app.get("/random_post")
@ -201,11 +201,11 @@ def comment_idlist(v=None, page=1, sort="new", t="day", gt=0, lt=0):
if not gt and not lt:
comments = apply_time_filter(t, comments, Comment)
next_exists = comments.count()
total = comments.count()
comments = sort_objects(sort, comments, Comment)
comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
return [x.id for x in comments], next_exists
return [x.id for x in comments], total
@app.get("/comments")
@limiter.limit(DEFAULT_RATELIMIT)
@ -222,7 +222,7 @@ def all_comments(v:User):
try: lt=int(request.values.get("before", 0))
except: lt=0
idlist, next_exists = comment_idlist(v=v,
idlist, total = comment_idlist(v=v,
page=page,
sort=sort,
t=t,
@ -233,4 +233,4 @@ def all_comments(v:User):
comments = get_comments(idlist, v=v)
if v.client: return {"data": [x.json(g.db) for x in comments]}
return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, next_exists=next_exists, size = PAGE_SIZE)
return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, total=total, size = PAGE_SIZE)

View File

@ -65,7 +65,7 @@ def hats(v:User):
sales = g.db.query(func.sum(User.coins_spent_on_hats)).scalar()
num_of_hats = g.db.query(HatDef).filter(HatDef.submitter_id == None).count()
return render_template("hats.html", owned_hat_ids=owned_hat_ids, hats=hats, v=v, sales=sales, num_of_hats=num_of_hats, next_exists=num_of_hats, page=page, sort=sort)
return render_template("hats.html", owned_hat_ids=owned_hat_ids, hats=hats, v=v, sales=sales, num_of_hats=num_of_hats, total=num_of_hats, page=page, sort=sort)
@app.post("/buy_hat/<int:hat_id>")
@limiter.limit('1/second', scope=rpath)
@ -160,15 +160,16 @@ def hat_owners(v:User, hat_id):
page = get_page()
users = g.db.query(User).join(Hat.owners).filter(Hat.hat_id == hat_id).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE+1).all()
users = g.db.query(User).join(Hat.owners).filter(Hat.hat_id == hat_id)
next_exists = (len(users) > PAGE_SIZE)
users = users[:PAGE_SIZE]
total = users.count()
users = users.order_by(Hat.created_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
return render_template("user_cards.html",
v=v,
users=users,
next_exists=next_exists,
total=total,
page=page,
user_cards_title="Hat Owners",
)

View File

@ -65,7 +65,7 @@ def notifications_modmail(v):
level=1,
)
next_exists = comments.count()
total = comments.count()
listing = comments.order_by(Comment.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all()
g.db.flush()
@ -75,7 +75,7 @@ def notifications_modmail(v):
return render_template("notifications.html",
v=v,
notifications=listing,
next_exists=next_exists,
total=total,
page=page,
standalone=True,
render_replies=True,
@ -137,7 +137,7 @@ def notifications_messages(v:User):
list_to_perserve_unread_attribute.append(c)
next_exists = message_threads.count()
total = message_threads.count()
listing = message_threads.order_by(thread_order.c.created_utc.desc()) \
.offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all()
@ -146,7 +146,7 @@ def notifications_messages(v:User):
return render_template("notifications.html",
v=v,
notifications=listing,
next_exists=next_exists,
total=total,
page=page,
standalone=True,
render_replies=True,
@ -174,7 +174,7 @@ def notifications_posts(v:User):
Submission.author_id.notin_(v.userblocks)
).options(load_only(Submission.id))
next_exists = listing.count()
total = listing.count()
listing = listing.order_by(Submission.created_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
listing = [x.id for x in listing]
@ -193,7 +193,7 @@ def notifications_posts(v:User):
return render_template("notifications.html",
v=v,
notifications=listing,
next_exists=next_exists,
total=total,
page=page,
standalone=True,
render_replies=True,
@ -225,7 +225,7 @@ def notifications_modactions(v:User):
if cls == SubAction:
listing = listing.filter(cls.sub.in_(v.moderated_subs))
next_exists = listing.count()
total = listing.count()
listing = listing.order_by(cls.id.desc())
listing = listing.offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all()
@ -239,7 +239,7 @@ def notifications_modactions(v:User):
return render_template("notifications.html",
v=v,
notifications=listing,
next_exists=next_exists,
total=total,
page=page,
standalone=True,
render_replies=True,
@ -262,7 +262,7 @@ def notifications_reddit(v:User):
Comment.author_id == AUTOJANNY_ID
)
next_exists = listing.count()
total = listing.count()
listing = listing.order_by(Comment.created_utc.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all()
for ma in listing:
@ -277,7 +277,7 @@ def notifications_reddit(v:User):
return render_template("notifications.html",
v=v,
notifications=listing,
next_exists=next_exists,
total=total,
page=page,
standalone=True,
render_replies=True,
@ -323,7 +323,7 @@ def notifications(v:User):
Comment.deleted_utc == 0,
)
next_exists = comments.count()
total = comments.count()
comments = comments.order_by(Notification.created_utc.desc(), Comment.id.desc())
comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
@ -413,7 +413,7 @@ def notifications(v:User):
return render_template("notifications.html",
v=v,
notifications=listing,
next_exists=next_exists,
total=total,
page=page,
standalone=True,
render_replies=True,

View File

@ -248,24 +248,20 @@ def admin_app_reject(v, aid):
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
@admin_level_required(PERMS['APPS_MODERATION'])
def admin_app_id_posts(v, aid):
aid=aid
oauth = g.db.get(OauthApp, aid)
if not oauth: abort(404)
page = get_page()
pids=oauth.idlist(g.db, page=page)
pids, total = oauth.idlist(Submission, page=page)
next_exists=len(pids)==101
pids=pids[:100]
posts=get_posts(pids, v=v)
posts = get_posts(pids, v=v)
return render_template("admin/app.html",
v=v,
app=oauth,
listing=posts,
next_exists=next_exists
total=total
)
@app.get("/admin/app/<int:aid>/comments")
@ -274,26 +270,21 @@ def admin_app_id_posts(v, aid):
@admin_level_required(PERMS['APPS_MODERATION'])
def admin_app_id_comments(v, aid):
aid=aid
oauth = g.db.get(OauthApp, aid)
if not oauth: abort(404)
page = get_page()
cids=oauth.comments_idlist(g.db, page=page)
cids, total = oauth.idlist(Comment, page=page)
next_exists=len(cids)==101
cids=cids[:100]
comments=get_comments(cids, v=v)
comments = get_comments(cids, v=v)
return render_template("admin/app.html",
v=v,
app=oauth,
comments=comments,
next_exists=next_exists,
total=total,
standalone=True
)

View File

@ -3,6 +3,7 @@ import time
from calendar import timegm
from sqlalchemy import *
from sqlalchemy.orm import load_only
from files.helpers.regex import *
from files.helpers.sorting_and_time import *
@ -60,7 +61,7 @@ def searchposts(v:User):
criteria=searchparse(query)
posts = g.db.query(Submission.id) \
posts = g.db.query(Submission).options(load_only(Submission.id)) \
.join(Submission.author) \
.filter(Submission.author_id.notin_(v.userblocks))
@ -84,7 +85,6 @@ def searchposts(v:User):
listing=[],
sort=sort,
t=t,
next_exists=False,
domain=None,
domain_obj=None,
error=f"@{author.username}'s profile is private; You can't use the 'author' syntax on them."
@ -148,16 +148,13 @@ def searchposts(v:User):
posts = apply_time_filter(t, posts, Submission)
posts = sort_objects(sort, posts, Submission)
total = posts.count()
posts = posts.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE+1).all()
posts = sort_objects(sort, posts, Submission)
ids = [x[0] for x in posts]
posts = posts.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
next_exists = (len(ids) > PAGE_SIZE)
ids = ids[:PAGE_SIZE]
ids = [x.id for x in posts]
posts = get_posts(ids, v=v, eager=True)
@ -166,12 +163,11 @@ def searchposts(v:User):
return render_template("search.html",
v=v,
query=query,
total=total,
page=page,
listing=posts,
sort=sort,
t=t,
next_exists=next_exists
total=total
)
@app.get("/search/comments")
@ -190,7 +186,7 @@ def searchcomments(v:User):
criteria = searchparse(query)
comments = g.db.query(Comment.id).outerjoin(Comment.post) \
comments = g.db.query(Comment).options(load_only(Comment.id)).outerjoin(Comment.post) \
.filter(
or_(Comment.parent_submission != None, Comment.wall_user_id != None),
Comment.author_id.notin_(v.userblocks),
@ -210,7 +206,7 @@ def searchcomments(v:User):
if v.client:
abort(403, f"@{author.username}'s profile is private; You can't use the 'author' syntax on them")
return render_template("search_comments.html", v=v, query=query, total=0, page=page, comments=[], sort=sort, t=t, next_exists=False, error=f"@{author.username}'s profile is private; You can't use the 'author' syntax on them!"), 403
return render_template("search_comments.html", v=v, query=query, total=0, page=page, comments=[], sort=sort, t=t, error=f"@{author.username}'s profile is private; You can't use the 'author' syntax on them!"), 403
else: comments = comments.filter(Comment.author_id == author.id)
@ -260,21 +256,18 @@ def searchcomments(v:User):
except: abort(400)
comments = comments.filter(Comment.created_utc < before)
comments = sort_objects(sort, comments, Comment)
total = comments.count()
comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE+1).all()
comments = sort_objects(sort, comments, Comment)
ids = [x[0] for x in comments]
comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
next_exists = (len(ids) > PAGE_SIZE)
ids = ids[:PAGE_SIZE]
ids = [x.id for x in comments]
comments = get_comments(ids, v=v)
if v.client: return {"total":total, "data":[x.json(db=g.db) for x in comments]}
return render_template("search_comments.html", v=v, query=query, total=total, page=page, comments=comments, sort=sort, t=t, next_exists=next_exists, standalone=True)
return render_template("search_comments.html", v=v, query=query, page=page, comments=comments, sort=sort, t=t, total=total, standalone=True)
@app.get("/search/messages")
@ -297,7 +290,7 @@ def searchmessages(v:User):
if v.admin_level >= PERMS['VIEW_MODMAIL']:
dm_conditions.append(Comment.sentto == MODMAIL_ID),
comments = g.db.query(Comment) \
comments = g.db.query(Comment).options(load_only(Comment.id)) \
.filter(
Comment.sentto != None,
Comment.parent_submission == None,
@ -311,7 +304,7 @@ def searchmessages(v:User):
if v.client:
abort(403, f"@{author.username}'s profile is private; You can't use the 'author' syntax on them")
return render_template("search_comments.html", v=v, query=query, total=0, page=page, comments=[], sort=sort, t=t, next_exists=False, error=f"@{author.username}'s profile is private; You can't use the 'author' syntax on them!"), 403
return render_template("search_comments.html", v=v, query=query, total=0, page=page, comments=[], sort=sort, t=t, error=f"@{author.username}'s profile is private; You can't use the 'author' syntax on them!"), 403
else: comments = comments.filter(Comment.author_id == author.id)
@ -350,21 +343,18 @@ def searchmessages(v:User):
abort(400, "The `sentto` field must contain a user's username!")
comments = comments.filter(Comment.sentto == sentto.id)
comments = sort_objects(sort, comments, Comment)
total = comments.count()
comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE+1).all()
comments = sort_objects(sort, comments, Comment)
next_exists = (len(comments) > PAGE_SIZE)
comments = comments[:PAGE_SIZE]
comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
for x in comments: x.unread = True
comments = [x.top_comment for x in comments]
if v.client: return {"total":total, "data":[x.json(db=g.db) for x in comments]}
return render_template("search_comments.html", v=v, query=query, total=total, page=page, comments=comments, sort=sort, t=t, next_exists=next_exists, standalone=True, render_replies=True)
return render_template("search_comments.html", v=v, query=query, page=page, comments=comments, sort=sort, t=t, total=total, standalone=True, render_replies=True)
@app.get("/search/users")
@limiter.limit(DEFAULT_RATELIMIT)
@ -411,10 +401,7 @@ def searchusers(v:User):
total = users.count()
users = users.offset(PAGE_SIZE * (page-1)).limit(PAGE_SIZE+1).all()
next_exists = (len(users)>PAGE_SIZE)
users = users[:PAGE_SIZE]
users = users.offset(PAGE_SIZE * (page-1)).limit(PAGE_SIZE).all()
if v.client: return {"data": [x.json for x in users]}
return render_template("search_users.html", v=v, query=query, total=total, page=page, users=users, next_exists=next_exists)
return render_template("search_users.html", v=v, query=query, page=page, users=users, total=total)

View File

@ -53,7 +53,7 @@ def marseys(v:User):
marseys = g.db.query(Emoji, User).join(User, Emoji.author_id == User.id).filter(Emoji.kind == "Marsey", Emoji.submitter_id==None)
next_exists = marseys.count()
total = marseys.count()
sort = request.values.get("sort", "usage")
if sort == "author":
@ -79,7 +79,7 @@ def marseys(v:User):
marsey.og = f'{marsey.name}.{x}'
break
return render_template("marseys.html", v=v, marseys=marseys, page=page, next_exists=next_exists, sort=sort)
return render_template("marseys.html", v=v, marseys=marseys, page=page, total=total, sort=sort)
@cache.cached(key_prefix="emojis")
@ -178,7 +178,7 @@ def log(v:User):
if kind and kind not in types:
kind = None
actions = []
next_exists = 0
total = 0
else:
actions = g.db.query(ModAction)
if v.admin_level < PERMS['USER_SHADOWBAN']:
@ -194,12 +194,12 @@ def log(v:User):
if k in kinds: types2[k] = val
types = types2
if kind: actions = actions.filter_by(kind=kind)
next_exists = actions.count()
total = actions.count()
actions = actions.order_by(ModAction.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all()
admins = [x[0] for x in g.db.query(User.username).filter(User.admin_level >= PERMS['ADMIN_MOP_VISIBLE']).order_by(User.username).all()]
return render_template("log.html", v=v, admins=admins, types=types, admin=admin, type=kind, actions=actions, next_exists=next_exists, page=page, single_user_url='admin')
return render_template("log.html", v=v, admins=admins, types=types, admin=admin, type=kind, actions=actions, total=total, page=page, single_user_url='admin')
@app.get("/log/<int:id>")
@limiter.limit(DEFAULT_RATELIMIT)
@ -225,7 +225,7 @@ def log_item(id, v):
types = MODACTION_TYPES__FILTERED
else: types = MODACTION_TYPES_FILTERED
return render_template("log.html", v=v, actions=[action], next_exists=1, page=1, action=action, admins=admins, types=types, single_user_url='admin')
return render_template("log.html", v=v, actions=[action], total=1, page=1, action=action, admins=admins, types=types, single_user_url='admin')
@app.get("/directory")
@limiter.limit(DEFAULT_RATELIMIT)
@ -379,7 +379,7 @@ def transfers_id(id, v):
if not transfer: abort(404)
return render_template("transfers.html", v=v, page=1, comments=[transfer], standalone=True, next_exists=1)
return render_template("transfers.html", v=v, page=1, comments=[transfer], standalone=True, total=1)
@app.get("/transfers")
@limiter.limit(DEFAULT_RATELIMIT)
@ -391,13 +391,13 @@ def transfers(v:User):
page = get_page()
next_exists = comments.count()
total = comments.count()
comments = comments.order_by(Comment.id.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
if v.client:
return {"data": [x.json(g.db) for x in comments]}
else:
return render_template("transfers.html", v=v, page=page, comments=comments, standalone=True, next_exists=next_exists)
return render_template("transfers.html", v=v, page=page, comments=comments, standalone=True, total=total)
@app.get('/donate')

View File

@ -866,7 +866,7 @@ def hole_log(v:User, sub):
if kind and kind not in types:
kind = None
actions = []
next_exists=0
total=0
else:
actions = g.db.query(SubAction).filter_by(sub=sub.name)
@ -878,13 +878,13 @@ def hole_log(v:User, sub):
if k in kinds: types2[k] = val
types = types2
if kind: actions = actions.filter_by(kind=kind)
next_exists = actions.count()
total = actions.count()
actions = actions.order_by(SubAction.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all()
mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(sub=sub.name).all()]
mods = [x[0] for x in g.db.query(User.username).filter(User.id.in_(mods)).order_by(User.username).all()]
return render_template("log.html", v=v, admins=mods, types=types, admin=mod, type=kind, actions=actions, next_exists=next_exists, page=page, sub=sub, single_user_url='mod')
return render_template("log.html", v=v, admins=mods, types=types, admin=mod, type=kind, actions=actions, total=total, page=page, sub=sub, single_user_url='mod')
@app.get("/h/<sub>/log/<int:id>")
@limiter.limit(DEFAULT_RATELIMIT)
@ -906,4 +906,4 @@ def hole_log_item(id, v, sub):
types = SUBACTION_TYPES
return render_template("log.html", v=v, actions=[action], next_exists=1, page=1, action=action, admins=mods, types=types, sub=sub, single_user_url='mod')
return render_template("log.html", v=v, actions=[action], total=1, page=1, action=action, admins=mods, types=types, sub=sub, single_user_url='mod')

View File

@ -38,11 +38,19 @@ def upvoters_downvoters(v, username, uid, cls, vote_cls, vote_dir, template, sta
page = get_page()
listing = g.db.query(cls).join(vote_cls).filter(cls.ghost == False, cls.is_banned == False, cls.deleted_utc == 0, vote_cls.vote_type==vote_dir, cls.author_id==id, vote_cls.user_id==uid).order_by(cls.created_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).all()
listing = [p.id for p in listing]
next_exists = len(listing) > PAGE_SIZE
listing = listing[:PAGE_SIZE]
listing = g.db.query(cls).options(load_only(cls.id)).join(vote_cls).filter(
cls.ghost == False,
cls.is_banned == False,
cls.deleted_utc == 0,
vote_cls.vote_type==vote_dir,
cls.author_id==id,
vote_cls.user_id==uid,
)
total = listing.count()
listing = listing.order_by(cls.created_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
listing = [x.id for x in listing]
if cls == Submission:
listing = get_posts(listing, v=v, eager=True)
@ -51,7 +59,7 @@ def upvoters_downvoters(v, username, uid, cls, vote_cls, vote_dir, template, sta
else:
listing = []
return render_template(template, next_exists=next_exists, listing=listing, page=page, v=v, standalone=standalone)
return render_template(template, total=total, listing=listing, page=page, v=v, standalone=standalone)
@app.get("/@<username>/upvoters/<int:uid>/posts")
@limiter.limit(DEFAULT_RATELIMIT)
@ -96,11 +104,19 @@ def upvoting_downvoting(v, username, uid, cls, vote_cls, vote_dir, template, sta
page = get_page()
listing = g.db.query(cls).join(vote_cls).filter(cls.ghost == False, cls.is_banned == False, cls.deleted_utc == 0, vote_cls.vote_type==vote_dir, vote_cls.user_id==id, cls.author_id==uid).order_by(cls.created_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).all()
listing = [p.id for p in listing]
next_exists = len(listing) > PAGE_SIZE
listing = listing[:PAGE_SIZE]
listing = g.db.query(cls).options(load_only(cls.id)).join(vote_cls).filter(
cls.ghost == False,
cls.is_banned == False,
cls.deleted_utc == 0,
vote_cls.vote_type==vote_dir,
vote_cls.user_id==id,
cls.author_id==uid,
)
total = listing.count()
listing = listing.order_by(cls.created_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
listing = [x.id for x in listing]
if cls == Submission:
listing = get_posts(listing, v=v, eager=True)
@ -109,7 +125,7 @@ def upvoting_downvoting(v, username, uid, cls, vote_cls, vote_dir, template, sta
else:
listing = []
return render_template(template, next_exists=next_exists, listing=listing, page=page, v=v, standalone=standalone)
return render_template(template, total=total, listing=listing, page=page, v=v, standalone=standalone)
@app.get("/@<username>/upvoting/<int:uid>/posts")
@limiter.limit(DEFAULT_RATELIMIT)
@ -155,11 +171,13 @@ def user_voted(v, username, cls, vote_cls, template, standalone):
cls.deleted_utc == 0,
cls.author_id != u.id,
vote_cls.user_id == u.id,
).order_by(cls.created_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).all()
)
total = listing.count()
listing = listing.order_by(cls.created_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
listing = [x.id for x in listing]
listing = [i.id for i in listing]
next_exists = len(listing) > PAGE_SIZE
listing = listing[:PAGE_SIZE]
if cls == Submission:
listing = get_posts(listing, v=v, eager=True)
elif cls == Comment:
@ -167,7 +185,7 @@ def user_voted(v, username, cls, vote_cls, template, standalone):
else:
listing = []
return render_template(template, next_exists=next_exists, listing=listing, page=page, v=v, standalone=standalone)
return render_template(template, total=total, listing=listing, page=page, v=v, standalone=standalone)
@app.get("/@<username>/voted/posts")
@limiter.limit(DEFAULT_RATELIMIT)
@ -271,10 +289,10 @@ def all_upvoters_downvoters(v:User, username:str, vote_dir:int, is_who_simps_hat
page = get_page()
users = users[PAGE_SIZE * (page-1):]
next_exists = (len(users) > PAGE_SIZE)
total = (len(users) > PAGE_SIZE)
users = users[:PAGE_SIZE]
return render_template("userpage/voters.html", v=v, users=users, pos=pos, name=vote_name, name2=name2, total=total, page=page, next_exists=next_exists)
return render_template("userpage/voters.html", v=v, users=users, pos=pos, name=vote_name, name2=name2, page=page, total=total)
@app.get("/@<username>/upvoters")
@limiter.limit(DEFAULT_RATELIMIT)
@ -730,12 +748,12 @@ def blockers(v:User, username:str):
users = g.db.query(UserBlock, User).join(UserBlock, UserBlock.target_id == u.id) \
.filter(UserBlock.user_id == User.id)
next_exists = users.count()
total = users.count()
users = users.order_by(UserBlock.created_utc.desc()) \
.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE ).all()
return render_template("userpage/blockers.html", v=v, u=u, users=users, page=page, next_exists=next_exists)
return render_template("userpage/blockers.html", v=v, u=u, users=users, page=page, total=total)
@app.get("/@<username>/followers")
@limiter.limit(DEFAULT_RATELIMIT)
@ -752,12 +770,12 @@ def followers(v:User, username:str):
users = g.db.query(Follow, User).join(Follow, Follow.target_id == u.id) \
.filter(Follow.user_id == User.id)
next_exists = users.count()
total = users.count()
users = users.order_by(Follow.created_utc.desc()) \
.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
return render_template("userpage/followers.html", v=v, u=u, users=users, page=page, next_exists=next_exists)
return render_template("userpage/followers.html", v=v, u=u, users=users, page=page, total=total)
@app.get("/@<username>/following")
@limiter.limit(DEFAULT_RATELIMIT)
@ -773,12 +791,12 @@ def following(v:User, username:str):
users = g.db.query(User).join(Follow, Follow.user_id == u.id) \
.filter(Follow.target_id == User.id)
next_exists = users.count()
total = users.count()
users = users.order_by(Follow.created_utc.desc()) \
.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
return render_template("userpage/following.html", v=v, u=u, users=users, page=page, next_exists=next_exists)
return render_template("userpage/following.html", v=v, u=u, users=users, page=page, total=total)
@app.get("/@<username>/views")
@limiter.limit(DEFAULT_RATELIMIT)
@ -790,10 +808,10 @@ def visitors(v:User, username:str):
page = get_page()
views = g.db.query(ViewerRelationship).filter_by(user_id=u.id)
next_exists = views.count()
total = views.count()
views = views.order_by(ViewerRelationship.last_view_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
return render_template("userpage/views.html", v=v, u=u, views=views, next_exists=next_exists, page=page)
return render_template("userpage/views.html", v=v, u=u, views=views, total=total, page=page)
@cache.memoize()
def userpagelisting(user:User, v=None, page:int=1, sort="new", t="all"):
@ -801,10 +819,10 @@ def userpagelisting(user:User, v=None, page:int=1, sort="new", t="all"):
if not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == user.id)):
posts = posts.filter_by(is_banned=False, private=False, ghost=False, deleted_utc=0)
posts = apply_time_filter(t, posts, Submission)
next_exists = posts.count()
total = posts.count()
posts = sort_objects(sort, posts, Submission)
posts = posts.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
return [x.id for x in posts], next_exists
return [x.id for x in posts], total
@app.get("/@<username>")
@limiter.limit(DEFAULT_RATELIMIT)
@ -842,7 +860,7 @@ def u_username_wall(v:Optional[User], username:str):
Comment.deleted_utc == 0
)
next_exists = comments.count()
total = comments.count()
comments = comments.order_by(Comment.created_utc.desc()) \
.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
if v:
@ -851,7 +869,7 @@ def u_username_wall(v:Optional[User], username:str):
if v and v.client:
return {"data": [c.json(g.db) for c in comments]}
return render_template("userpage/wall.html", u=u, v=v, listing=comments, page=page, next_exists=next_exists, is_following=is_following, standalone=True, render_replies=True, wall=True)
return render_template("userpage/wall.html", u=u, v=v, listing=comments, page=page, total=total, is_following=is_following, standalone=True, render_replies=True, wall=True)
@app.get("/@<username>/wall/comment/<int:cid>")
@ -900,7 +918,7 @@ def u_username_wall_comment(v:User, username:str, cid):
if v and v.client: return top_comment.json(db=g.db)
return render_template("userpage/wall.html", u=u, v=v, listing=[top_comment], page=1, is_following=is_following, standalone=True, render_replies=True, wall=True, comment_info=comment_info, next_exists=1)
return render_template("userpage/wall.html", u=u, v=v, listing=[top_comment], page=1, is_following=is_following, standalone=True, render_replies=True, wall=True, comment_info=comment_info, total=1)
@app.get("/@<username>/posts")
@ -934,7 +952,7 @@ def u_username(v:Optional[User], username:str):
t = request.values.get("t", "all")
page = get_page()
ids, next_exists = userpagelisting(u, v=v, page=page, sort=sort, t=t)
ids, total = userpagelisting(u, v=v, page=page, sort=sort, t=t)
if page == 1 and sort == 'new':
sticky = []
@ -957,7 +975,7 @@ def u_username(v:Optional[User], username:str):
page=page,
sort=sort,
t=t,
next_exists=next_exists,
total=total,
is_following=is_following)
if v and v.client:
@ -970,7 +988,7 @@ def u_username(v:Optional[User], username:str):
page=page,
sort=sort,
t=t,
next_exists=next_exists,
total=total,
is_following=is_following)
@ -1023,7 +1041,7 @@ def u_username_comments(username, v=None):
comments = apply_time_filter(t, comments, Comment)
next_exists = comments.count()
total = comments.count()
comments = sort_objects(sort, comments, Comment)
@ -1035,7 +1053,7 @@ def u_username_comments(username, v=None):
if v and v.client:
return {"data": [c.json(g.db) for c in listing]}
return render_template("userpage/comments.html", u=u, v=v, listing=listing, page=page, sort=sort, t=t,next_exists=next_exists, is_following=is_following, standalone=True)
return render_template("userpage/comments.html", u=u, v=v, listing=listing, page=page, sort=sort, t=t,total=total, is_following=is_following, standalone=True)
@app.get("/@<username>/info")
@ -1176,9 +1194,14 @@ def get_saves_and_subscribes(v, template, relationship_cls, page:int, standalone
cls = Comment
else:
raise TypeError("Relationships supported is SaveRelationship, Subscription, CommentSaveRelationship")
ids = [x[0] for x in g.db.query(query).join(join).filter(relationship_cls.user_id == v.id).order_by(cls.created_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).all()]
next_exists = len(ids) > PAGE_SIZE
ids = ids[:PAGE_SIZE]
listing = g.db.query(query).join(join).filter(relationship_cls.user_id == v.id)
total = listing.count()
listing = listing.order_by(cls.created_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
ids = [x[0] for x in listing]
extra = None
if not v.admin_level >= PERMS['POST_COMMENT_MODERATION']:
@ -1192,7 +1215,7 @@ def get_saves_and_subscribes(v, template, relationship_cls, page:int, standalone
raise TypeError("Only supports Submissions and Comments. This is probably the result of a bug with *this* function")
if v.client: return {"data": [x.json(g.db) for x in listing]}
return render_template(template, u=v, v=v, listing=listing, page=page, next_exists=next_exists, standalone=standalone)
return render_template(template, u=v, v=v, listing=listing, page=page, total=total, standalone=standalone)
@app.get("/@<username>/saved/posts")
@limiter.limit(DEFAULT_RATELIMIT)
@ -1275,15 +1298,16 @@ def bid_list(v:User, bid):
page = get_page()
users = g.db.query(User).join(User.badges).filter(Badge.badge_id==bid).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).all()
next_exists = (len(users) > PAGE_SIZE)
users = users[:PAGE_SIZE]
users = g.db.query(User).join(User.badges).filter(Badge.badge_id==bid)
total = users.count()
users = users.order_by(Badge.created_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
return render_template("user_cards.html",
v=v,
users=users,
next_exists=next_exists,
total=total,
page=page,
user_cards_title="Badge Owners",
)
@ -1444,15 +1468,16 @@ def users_list(v):
page = get_page()
users = g.db.query(User).order_by(User.id.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).all()
next_exists = (len(users) > PAGE_SIZE)
users = users[:PAGE_SIZE]
users = g.db.query(User)
total = users.count()
users = users.order_by(User.id.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
return render_template("user_cards.html",
v=v,
users=users,
next_exists=next_exists,
total=total,
page=page,
user_cards_title="Users Feed",
)

View File

@ -4,7 +4,7 @@
{% if not size %}
{% set size = PAGE_SIZE %}
{% endif %}
{% set num_pages = (next_exists / size) | round(0, 'ceil') | int %}
{% set num_pages = (total / size) | round(0, 'ceil') | int %}
{% set start_point = page - 2 %}
{% if start_point < 1 %}

View File

@ -201,16 +201,5 @@
</div>
{% endblock %}
{% block pagenav %}
<nav>
<ul class="pagination pagination-sm mb-0">
<li class="page-item{% if page==1 %} disabled{% endif %}">
<small><a class="page-link" href="?sort={{sort}}&q={{query | urlencode}}&t={{t}}&page={{page-1}}" tabindex="-1"{% if page==1 %}{% endif %}>Back</a></small>
</li>
<li class="page-item{% if not next_exists %} disabled{% endif %}">
<small><a class="page-link" href="?sort={{sort}}&q={{query | urlencode}}&t={{t}}&page={{page+1}}">Next</a></small>
</li>
</ul>
</nav>
{% include "pagination.html" %}
{% endblock %}

View File

@ -8,23 +8,6 @@
</div>
{% endblock %}
{% block pagenav %}
<nav>
<ul class="pagination pagination-sm mb-0">
{% if page>1 %}
<li class="page-item">
<small><a class="page-link" href="?kind={{kind}}&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="?kind={{kind}}&page={{page+1}}">Next</a></small>
</li>
{% else %}
<li class="page-item disabled"><span class="page-link">Next</span></li>
{% endif %}
</ul>
</nav>
{% include "pagination.html" %}
{% endblock %}
{% block navbar %}{% endblock %}

View File

@ -29,22 +29,5 @@
{% endblock %}
{% block pagenav %}
<nav>
<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>
{% include "pagination.html" %}
{% endblock %}

View File

@ -36,22 +36,5 @@
{% endblock %}
{% block pagenav %}
<nav>
<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>
{% include "pagination.html" %}
{% endblock %}