Adds pagination to feed

Fixes #68
This commit is contained in:
Mouse Reeve 2020-04-01 15:36:35 -07:00
parent 575419cc5a
commit 4538a60490
3 changed files with 39 additions and 1 deletions

View file

@ -619,3 +619,10 @@ a .icon {
.book-row .book-cover {
float: none;
}
.pagination a {
text-decoration: none;
}
.pagination .next {
text-align: right;
}

View file

@ -15,6 +15,26 @@
{% include 'snippets/status.html' with status=activity %}
</div>
{% endfor %}
<div class="content-container pagination row">
{% if prev %}
<p>
<a href="{{ prev }}">
<span class="icon icon-arrow-left"></span>
Previous
</a>
</p>
{% endif %}
{% if next %}
<p class="next">
<a href="{{ next }}">
Next
<span class="icon icon-arrow-right"></span>
</a>
</p>
{% endif %}
</div>
</div>
{% endblock %}

View file

@ -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)