add pages to /followers /following /blockers and order them all by most recent first

master
Aevann1 2022-11-27 02:59:16 +02:00
parent 14828bd9f4
commit a46b62db0b
6 changed files with 99 additions and 12 deletions

View File

@ -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("/@<username>/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("/@<username>/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("/@<username>/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]

View File

@ -1,7 +1,7 @@
{% extends "default.html" %}
{% block pagetitle %}@{{u.username}}'s blockers{% endblock %}
{% block content %}
<h5 class="mt-3">@{{u.username}}'s blockers</h5>
<h5 class="my-3">@{{u.username}}'s blockers</h5>
<div class="overflow-x-auto mt-1"><table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
@ -24,3 +24,24 @@
<script defer src="{{'js/blockers.js' | asset}}"></script>
{% endblock %}
{% block pagenav %}
<nav aria-label="Page navigation">
<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 %}

View File

@ -1,7 +1,7 @@
{% extends "default.html" %}
{% block pagetitle %}@{{u.username}}'s followers{% endblock %}
{% block content %}
<h5 class="mt-2">@{{u.username}}'s followers</h5>
<h5 class="my-3">@{{u.username}}'s followers</h5>
<div class="overflow-x-auto mt-1"><table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
@ -30,3 +30,24 @@
<script defer src="{{'js/followers.js' | asset}}"></script>
{% endblock %}
{% block pagenav %}
<nav aria-label="Page navigation">
<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 %}

View File

@ -1,7 +1,7 @@
{% extends "default.html" %}
{% block pagetitle %}Users followed by @{{u.username}}{% endblock %}
{% block content %}
<h5 class="mt-3 mb-1">Users followed by @{{u.username}}</h5>
<h5 class="my-3">Users followed by @{{u.username}}</h5>
<div class="overflow-x-auto"><table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
@ -28,3 +28,24 @@
<script defer src="{{'js/following.js' | asset}}"></script>
{% endblock %}
{% block pagenav %}
<nav aria-label="Page navigation">
<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 %}

View File

@ -13,6 +13,6 @@
</div>
</div>
</div>
{% endif %}
{% endif %}
</div>
{% endblock %}

View File

@ -1,7 +1,7 @@
{% extends "default.html" %}
{% block pagetitle %}{{name2}}{% endblock %}
{% block content %}
<h3 class="mt-3" style="text-align: center">{{name2}}</h3>
<h3 class="my-3" style="text-align: center">{{name2}}</h3>
<h5 class="font-weight-bold text-center mt-3">Total: {{total}}</h5>
<div class="mt-1 overflow-x-auto"><table class="table table-striped mb-5">
<thead class="bg-primary text-white">