pagination on instance people list

This commit is contained in:
rimu 2024-10-13 11:16:36 +13:00
parent 4d285e6871
commit f2af615d02
2 changed files with 21 additions and 4 deletions

View file

@ -80,11 +80,16 @@ def instance_people(instance_domain):
abort(404)
if current_user.is_admin():
people = User.query.filter_by(instance_id=instance.id, deleted=False, banned=False).order_by(desc(User.last_seen)).all()
people = User.query.filter_by(instance_id=instance.id, deleted=False, banned=False).order_by(desc(User.last_seen))
else:
people = User.query.filter_by(instance_id=instance.id, deleted=False, banned=False, searchable=True).order_by(desc(User.last_seen)).all()
people = User.query.filter_by(instance_id=instance.id, deleted=False, banned=False, searchable=True).order_by(desc(User.last_seen))
return render_template('instance/people.html', people=people, instance=instance,
# Pagination
people = people.paginate(page=page, per_page=100 if current_user.is_authenticated and not low_bandwidth else 50, error_out=False)
next_url = url_for('instance.instance_people', page=people.next_num, instance_domain=instance_domain) if people.has_next else None
prev_url = url_for('instance.instance_people', page=people.prev_num, instance_domain=instance_domain) if people.has_prev and page != 1 else None
return render_template('instance/people.html', people=people, instance=instance, next_url=next_url, prev_url=prev_url,
moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.get_id()),
menu_topics=menu_topics(), site=g.site,

View file

@ -25,7 +25,7 @@
<th>{{ _('Posts') }}</th>
<th>{{ _('Comments') }}</th>
</tr>
{% for person in people %}
{% for person in people.items %}
<tr>
<td valign="top">{{ render_username(person) }}</td>
<td>{{ person.about_html | safe if person.about_html }}</td>
@ -34,6 +34,18 @@
</tr>
{% endfor %}
</table>
<nav aria-label="Pagination" class="mt-4" role="navigation">
{% if prev_url -%}
<a href="{{ prev_url }}" class="btn btn-primary" rel='nofollow'>
<span aria-hidden="true">&larr;</span> {{ _('Previous page') }}
</a>
{% endif -%}
{% if next_url -%}
<a href="{{ next_url }}" class="btn btn-primary" rel='nofollow'>
{{ _('Next page') }} <span aria-hidden="true">&rarr;</span>
</a>
{% endif -%}
</nav>
{% else %}
<p>{{ _('No people to show') }}</p>
{% endif %}