From a46b62db0b8935e67ed68e0e05dfef3cef6da882 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 27 Nov 2022 02:59:16 +0200 Subject: [PATCH] add pages to /followers /following /blockers and order them all by most recent first --- files/routes/users.py | 38 ++++++++++++++++---- files/templates/userpage/blockers.html | 23 +++++++++++- files/templates/userpage/followers.html | 23 +++++++++++- files/templates/userpage/following.html | 23 +++++++++++- files/templates/userpage/voted_comments.html | 2 +- files/templates/userpage/voters.html | 2 +- 6 files changed, 99 insertions(+), 12 deletions(-) diff --git a/files/routes/users.py b/files/routes/users.py index 32ad569ba..228802788 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -629,20 +629,36 @@ def followers(username, v): if not (v.id == u.id or v.admin_level >= PERMS['USER_FOLLOWS_VISIBLE']): abort(403) + try: page = int(request.values.get("page", 1)) + except: page = 1 + users = g.db.query(Follow, User).join(Follow, Follow.target_id == u.id) \ .filter(Follow.user_id == User.id) \ - .order_by(Follow.created_utc).all() - return render_template("userpage/followers.html", v=v, u=u, users=users) + .order_by(Follow.created_utc.desc()) \ + .offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).all() + + next_exists = (len(users) > PAGE_SIZE) + users = users[:PAGE_SIZE] + + return render_template("userpage/followers.html", v=v, u=u, users=users, page=page, next_exists=next_exists) @app.get("/@/blockers") @auth_required def blockers(username, v): u = get_user(username, v=v, include_shadowbanned=False) + try: page = int(request.values.get("page", 1)) + except: page = 1 + users = g.db.query(UserBlock, User).join(UserBlock, UserBlock.target_id == u.id) \ .filter(UserBlock.user_id == User.id) \ - .order_by(UserBlock.created_utc.desc()).all() - return render_template("userpage/blockers.html", v=v, u=u, users=users) + .order_by(UserBlock.created_utc.desc()) \ + .offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).all() + + next_exists = (len(users) > PAGE_SIZE) + users = users[:PAGE_SIZE] + + return render_template("userpage/blockers.html", v=v, u=u, users=users, page=page, next_exists=next_exists) @app.get("/@/following") @auth_required @@ -651,10 +667,18 @@ def following(username, v): if not (v.id == u.id or v.admin_level >= PERMS['USER_FOLLOWS_VISIBLE']): abort(403) + try: page = int(request.values.get("page", 1)) + except: page = 1 + users = g.db.query(User).join(Follow, Follow.user_id == u.id) \ .filter(Follow.target_id == User.id) \ - .order_by(Follow.created_utc).all() - return render_template("userpage/following.html", v=v, u=u, users=users) + .order_by(Follow.created_utc.desc()) \ + .offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).all() + + next_exists = (len(users) > PAGE_SIZE) + users = users[:PAGE_SIZE] + + return render_template("userpage/following.html", v=v, u=u, users=users, page=page, next_exists=next_exists) @app.get("/@/views") @auth_required @@ -664,7 +688,7 @@ def visitors(username, v:User): try: page = int(request.values.get("page", 1)) except: page = 1 - views = g.db.query(ViewerRelationship).filter_by(user_id=u.id).order_by(ViewerRelationship.last_view_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).limit(PAGE_SIZE + 1).all() + views = g.db.query(ViewerRelationship).filter_by(user_id=u.id).order_by(ViewerRelationship.last_view_utc.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).all() next_exists = (len(views) > PAGE_SIZE) views = views[:PAGE_SIZE] diff --git a/files/templates/userpage/blockers.html b/files/templates/userpage/blockers.html index f5d593c11..a9024ba94 100644 --- a/files/templates/userpage/blockers.html +++ b/files/templates/userpage/blockers.html @@ -1,7 +1,7 @@ {% extends "default.html" %} {% block pagetitle %}@{{u.username}}'s blockers{% endblock %} {% block content %} -
@{{u.username}}'s blockers
+
@{{u.username}}'s blockers
@@ -24,3 +24,24 @@ {% endblock %} + +{% block pagenav %} + +{% endblock %} diff --git a/files/templates/userpage/followers.html b/files/templates/userpage/followers.html index 75ef2d80c..6cbb94050 100644 --- a/files/templates/userpage/followers.html +++ b/files/templates/userpage/followers.html @@ -1,7 +1,7 @@ {% extends "default.html" %} {% block pagetitle %}@{{u.username}}'s followers{% endblock %} {% block content %} -
@{{u.username}}'s followers
+
@{{u.username}}'s followers
@@ -30,3 +30,24 @@ {% endblock %} + +{% block pagenav %} + +{% endblock %} diff --git a/files/templates/userpage/following.html b/files/templates/userpage/following.html index fcbcd18a3..b66b42cd6 100644 --- a/files/templates/userpage/following.html +++ b/files/templates/userpage/following.html @@ -1,7 +1,7 @@ {% extends "default.html" %} {% block pagetitle %}Users followed by @{{u.username}}{% endblock %} {% block content %} -
Users followed by @{{u.username}}
+
Users followed by @{{u.username}}
@@ -28,3 +28,24 @@ {% endblock %} + +{% block pagenav %} + +{% endblock %} diff --git a/files/templates/userpage/voted_comments.html b/files/templates/userpage/voted_comments.html index fa36d355b..c36a162d9 100644 --- a/files/templates/userpage/voted_comments.html +++ b/files/templates/userpage/voted_comments.html @@ -13,6 +13,6 @@ - {% endif %} + {% endif %} {% endblock %} diff --git a/files/templates/userpage/voters.html b/files/templates/userpage/voters.html index e9b6ea990..7ca404fe6 100644 --- a/files/templates/userpage/voters.html +++ b/files/templates/userpage/voters.html @@ -1,7 +1,7 @@ {% extends "default.html" %} {% block pagetitle %}{{name2}}{% endblock %} {% block content %} -

{{name2}}

+

{{name2}}

Total: {{total}}