forked from rDrama/rDrama
1
0
Fork 0

add pagination to simps/haters/simps for/hates lists and remove loop.index

master
Aevann1 2022-11-28 03:45:20 +02:00
parent d0047dcc5a
commit 73a78f0e97
2 changed files with 32 additions and 5 deletions

View File

@ -228,9 +228,18 @@ def all_upvoters_downvoters(v, username, vote_dir, is_who_simps_hates):
if total == 1: vote_str = vote_str[:-1] # we want to unpluralize if only 1 vote
total = f'{total} {vote_str} {received_given}'
name2 = f'Who @{username} {simps_haters}' if is_who_simps_hates else f'@{username} biggest {simps_haters}'
name2 = f'Who @{username} {simps_haters}' if is_who_simps_hates else f"@{username}'s {simps_haters}"
return render_template("userpage/voters.html", v=v, users=users[:PAGE_SIZE], pos=pos, name=vote_name, name2=name2, total=total)
try: page = int(request.values.get("page", 1))
except: page = 1
PAGE_SIZE = 2
users = users[PAGE_SIZE * (page-1):]
next_exists = (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)
@app.get("/@<username>/upvoters")
@auth_required

View File

@ -6,7 +6,6 @@
<div class="mt-1 overflow-x-auto"><table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th>#</th>
<th>Name</th>
<th>{{name}}votes</th>
</tr>
@ -14,14 +13,12 @@
<tbody id="followers-table">
{% for user, num in users %}
<tr {% if v.id == user.id %}class="self"{% endif %}>
<td>{{loop.index}}</td>
<td>{% include "user_in_table.html" %}</td>
<td><a href="{{request.path}}/{{user.id}}/posts">{{num}}</a></td>
</tr>
{% endfor %}
{% if pos and (pos[0] > 25 or not pos[1]) %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos[0]}}</td>
<td>
{% with user=v %}
{% include "user_in_table.html" %}
@ -34,3 +31,24 @@
</table>
{% 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 %}