Paginates user activity feed

This commit is contained in:
Mouse Reeve 2020-11-11 10:43:47 -08:00
parent 91a32c014e
commit 90d0d721dd
2 changed files with 40 additions and 1 deletions

View file

@ -54,6 +54,26 @@
<p>No activities yet!</a>
</div>
{% endif %}
<nav class="pagination" role="navigation" aria-label="pagination">
{% if prev %}
<p class="pagination-previous">
<a href="{{ prev }}">
<span class="icon icon-arrow-left"></span>
Previous
</a>
</p>
{% endif %}
{% if next %}
<p class="pagination-next">
<a href="{{ next }}">
Next
<span class="icon icon-arrow-right"></span>
</a>
</p>
{% endif %}
</nav>
</div>
{% endblock %}

View file

@ -327,6 +327,11 @@ def user_page(request, username):
return JsonResponse(user.to_activity(), encoder=ActivityEncoder)
# otherwise we're at a UI view
try:
page = int(request.GET.get('page', 1))
except ValueError:
page = 1
shelf_preview = []
# only show other shelves that should be visible
@ -351,13 +356,27 @@ def user_page(request, username):
if len(shelf_preview) > 2:
break
# user's posts
activities = get_activity_feed(user, 'self')
paginated = Paginator(activities, PAGE_LENGTH)
activity_page = paginated.page(page)
prev_page = next_page = None
if activity_page.has_next():
next_page = '/user/%s/?page=%d' % \
(username, activity_page.next_page_number())
if activity_page.has_previous():
prev_page = '/user/%s/?page=%d' % \
(username, activity_page.previous_page_number())
data = {
'title': user.name,
'user': user,
'is_self': is_self,
'shelves': shelf_preview,
'shelf_count': shelves.count(),
'activities': get_activity_feed(user, 'self')[:15],
'activities': activity_page.object_list,
'next': next_page,
'prev': prev_page,
}
return TemplateResponse(request, 'user.html', data)