From f2af615d025f1792f55e5e83e19d8666e3a6adf2 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 13 Oct 2024 11:16:36 +1300 Subject: [PATCH] pagination on instance people list --- app/instance/routes.py | 11 ++++++++--- app/templates/instance/people.html | 14 +++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/instance/routes.py b/app/instance/routes.py index 0d498d9c..b1c6830c 100644 --- a/app/instance/routes.py +++ b/app/instance/routes.py @@ -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, diff --git a/app/templates/instance/people.html b/app/templates/instance/people.html index f70b5d66..69ec903d 100644 --- a/app/templates/instance/people.html +++ b/app/templates/instance/people.html @@ -25,7 +25,7 @@ {{ _('Posts') }} {{ _('Comments') }} - {% for person in people %} + {% for person in people.items %} {{ render_username(person) }} {{ person.about_html | safe if person.about_html }} @@ -34,6 +34,18 @@ {% endfor %} + {% else %}

{{ _('No people to show') }}

{% endif %}