1
0
mirror of https://gitlab.com/brutaldon/brutaldon.git synced 2024-11-02 16:37:19 -04:00

Home, local, and public timelines have simple pagination.

Notification and tag timelines should also have pagination, but they have
to be done separately.
This commit is contained in:
Jason McBrayer 2018-05-18 09:22:27 -04:00
parent ad334315dc
commit dd88bcea29
6 changed files with 67 additions and 14 deletions

View File

@ -0,0 +1 @@
{{% extends "main/timeline.html" %}

View File

@ -0,0 +1,12 @@
{% extends "main/timeline.html" %}
{% block pagination %}
<nav class="pagination is-centered" role="navigation" aria-label="pagination">
{% if prev %}
<a class="pagination-next" href="{% url 'local_prev' prev.since_id %}">Newer</a>
{% endif %}
{% if next %}
<a class="pagination-previous" href="{% url 'local_next' next.max_id %}">Older</a>
{% endif %}
</nav>
{% endblock %}

View File

@ -0,0 +1,12 @@
{% extends "main/timeline.html" %}
{% block pagination %}
<nav class="pagination is-centered" role="navigation" aria-label="pagination">
{% if prev %}
<a class="pagination-next" href="{% url 'fed_prev' prev.since_id %}">Newer</a>
{% endif %}
{% if next %}
<a class="pagination-previous" href="{% url 'fed_next' next.max_id %}">Older</a>
{% endif %}
</nav>
{% endblock %}

View File

@ -2,7 +2,7 @@
{% load humanize %}
{% block title %}
Brutaldon - {{ timeline }} timelime
Brutaldon - {{ timeline_name }} timelime
{% endblock %}
{% block content %}
@ -13,7 +13,7 @@
</div>
<hr class="is-hidden">
{% endif %}
<h1 class="title">Your {{ timeline }} timeline</h1>
<h1 class="title">Your {{ timeline_name }} timeline</h1>
{% for toot in toots %}
<div class="box">
{% if toot.reblog %}
@ -25,4 +25,14 @@
<hr class="is-hidden">
{% endfor %}
{% block pagination %}
<nav class="pagination is-centered" role="navigation" aria-label="pagination">
{% if prev %}
<a class="pagination-next" href="{% url 'home_prev' prev.since_id %}">Newer</a>
{% endif %}
{% if next %}
<a class="pagination-previous" href="{% url 'home_next' next.max_id %}">Older</a>
{% endif %}
</nav>
{% endblock %}
{% endblock %}

View File

@ -19,6 +19,8 @@ from brutaldon import views
urlpatterns = [
path('admin/', admin.site.urls),
path('home/next/<int:next>', views.home, name='home_next'),
path('home/prev/<int:prev>', views.home, name='home_prev'),
path('home', views.home, name='home'),
path('login', views.login, name="login"),
path('oldlogin', views.old_login, name="oldlogin"),
@ -27,7 +29,11 @@ urlpatterns = [
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('settings', views.settings, name='settings'),
path('thread/<int:id>', views.thread, name='thread'),
path('tags/<tag>', views.tag, name='tag'),

View File

@ -51,25 +51,37 @@ def fullbrutalism_p(request):
fullbrutalism = False
return fullbrutalism
def timeline(request, timeline='home', timeline_name='Home'):
def timeline(request, timeline='home', timeline_name='Home', max_id=None, since_id=None):
try:
mastodon = get_mastodon(request)
except NotLoggedInException:
return redirect(login)
data = mastodon.timeline(timeline)
data = mastodon.timeline(timeline, limit=100, max_id=max_id, since_id=since_id)
form = PostForm()
return render(request, 'main/timeline.html',
{'toots': data, 'form': form, 'timeline': timeline_name,
'fullbrutalism': fullbrutalism_p(request)})
try:
prev = data[0]._pagination_prev
if len(mastodon.timeline(since_id=prev['since_id'])) == 0:
prev = None
except IndexError:
prev = None
try:
next = data[-1]._pagination_next
except IndexError:
next = None
return render(request, 'main/%s_timeline.html' % timeline,
{'toots': data, 'form': form, 'timeline': timeline,
'timeline_name': timeline_name,
'fullbrutalism': fullbrutalism_p(request),
'prev': prev, 'next': next})
def home(request):
return timeline(request, 'home', 'Home')
def home(request, next=None, prev=None):
return timeline(request, 'home', 'Home', max_id=next, since_id=prev)
def local(request):
return timeline(request, 'local', 'Local')
def local(request, next=None, prev=None):
return timeline(request, 'local', 'Local', max_id=next, since_id=prev)
def fed(request):
return timeline(request, 'public', 'Federated')
def fed(request, next=None, prev=None):
return timeline(request, 'public', 'Federated', max_id=next, since_id=prev)
def tag(request, tag):
try: