Add paging to notifications. Untested

This commit is contained in:
Jason McBrayer 2018-06-24 14:19:35 -04:00
parent 320164a5d3
commit 52e83814b6
3 changed files with 30 additions and 4 deletions

View File

@ -75,5 +75,15 @@ mastodon.notifications()[0]
<hr class="is-hidden">
{% endif %}
{% endfor %}
{% block pagination %}
<nav class="pagination is-centered" role="navigation" aria-label="pagination">
{% if prev %}
<a class="pagination-next" href="{% url 'note_prev' prev.since_id %}">Newer</a>
{% endif %}
{% if next %}
<a class="pagination-previous" href="{% url 'note_next' next.max_id %}">Older</a>
{% endif %}
</nav>
{% endblock %}
{% endblock %}

View File

@ -29,13 +29,15 @@ urlpatterns = [
path('logout', views.logout, name='logout'),
path('oauth_callback', views.oauth_callback, name="oauth_callback"),
path('error', views.error, name='error'),
path('note', views.note, name='note'),
path('local', views.local, name='local'),
path('local/next/<int:next>', views.local, name='local_next'),
path('local/prev/<int:prev>', views.local, name='local_prev'),
path('fed', views.fed, name='fed'),
path('fed/next/<int:next>', views.fed, name='fed_next'),
path('fed/prev/<int:prev>', views.fed, name='fed_prev'),
path('note', views.note, name='note'),
path('note/next<int:next>', views.note, name='note_next'),
path('note/prev/<int:prev>', views.note, name='note_prev'),
path('settings', views.settings, name='settings'),
path('thread/<int:id>', views.thread, name='thread'),
path('tags/<tag>', views.tag, name='tag'),

View File

@ -244,11 +244,25 @@ def logout(request):
def error(request):
return render(request, 'error.html', { 'error': "Not logged in yet."})
def note(request):
mastodon = get_mastodon(request)
notes = mastodon.notifications()
def note(request, next=None, prev=None):
try:
mastodon = get_mastodon(request)
except NotLoggedInException:
return redirect(about)
notes = mastodon.notifications(limit=100, max_id=next, since_id=prev)
try:
prev = notes[0]._pagination_prev
if len(mastodon.timeline(since_id=prev['since_id'])) == 0:
prev = None
except IndexError:
prev = None
try:
next = notes[-1]._pagination_next
except IndexError:
next = None
return render(request, 'main/notifications.html',
{'notes': notes,'timeline': 'Notifications',
'timeline_name': 'Notifications',
'own_username': request.session['user'].acct,
'fullbrutalism': fullbrutalism_p(request)})