From 4538a60490c6d58fa8f6b6026c1c1f94559bd747 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 1 Apr 2020 15:36:35 -0700 Subject: [PATCH] Adds pagination to feed Fixes #68 --- fedireads/static/format.css | 7 +++++++ fedireads/templates/feed.html | 20 ++++++++++++++++++++ fedireads/views.py | 13 ++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/fedireads/static/format.css b/fedireads/static/format.css index 9f63ab7fa..34a5e64ad 100644 --- a/fedireads/static/format.css +++ b/fedireads/static/format.css @@ -619,3 +619,10 @@ a .icon { .book-row .book-cover { float: none; } + +.pagination a { + text-decoration: none; +} +.pagination .next { + text-align: right; +} diff --git a/fedireads/templates/feed.html b/fedireads/templates/feed.html index f77865eab..96731ffe2 100644 --- a/fedireads/templates/feed.html +++ b/fedireads/templates/feed.html @@ -15,6 +15,26 @@ {% include 'snippets/status.html' with status=activity %} {% endfor %} + + {% endblock %} diff --git a/fedireads/views.py b/fedireads/views.py index 3fcb51df6..c8a69fe39 100644 --- a/fedireads/views.py +++ b/fedireads/views.py @@ -44,6 +44,12 @@ def home(request): @login_required def home_tab(request, tab): ''' user's homepage with activity feed ''' + page_size = 15 + try: + page = int(request.GET.get('page', 1)) + except ValueError: + page = 1 + shelves = [] shelves = get_user_shelf_preview( request.user, @@ -89,8 +95,11 @@ def home_tab(request, tab): # all activities from everyone you federate with activities = activities.filter(privacy='public') - activities = activities[:10] + activity_count = activities.count() + activities = activities[(page - 1) * page_size:page * page_size] + next_page = '/?page=%d' % (page + 1) + prev_page = '/?page=%d' % (page - 1) data = { 'user': request.user, 'shelves': shelves, @@ -104,6 +113,8 @@ def home_tab(request, tab): 'active_tab': tab, 'review_form': forms.ReviewForm(), 'comment_form': forms.CommentForm(), + 'next': next_page if activity_count > (page_size * page) else None, + 'prev': prev_page if page > 1 else None, } return TemplateResponse(request, 'feed.html', data)