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 %} {% load humanize %}
{% block title %} {% block title %}
Brutaldon - {{ timeline }} timelime Brutaldon - {{ timeline_name }} timelime
{% endblock %} {% endblock %}
{% block content %} {% block content %}
@ -13,7 +13,7 @@
</div> </div>
<hr class="is-hidden"> <hr class="is-hidden">
{% endif %} {% endif %}
<h1 class="title">Your {{ timeline }} timeline</h1> <h1 class="title">Your {{ timeline_name }} timeline</h1>
{% for toot in toots %} {% for toot in toots %}
<div class="box"> <div class="box">
{% if toot.reblog %} {% if toot.reblog %}
@ -25,4 +25,14 @@
<hr class="is-hidden"> <hr class="is-hidden">
{% endfor %} {% 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 %} {% endblock %}

View File

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

View File

@ -2,7 +2,7 @@ from django.http import HttpResponse, Http404
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.views.decorators.cache import never_cache from django.views.decorators.cache import never_cache
from django.urls import reverse from django.urls import reverse
from django.core.files.uploadhandler import TemporaryFileUploadHandler from django.core.files.uploadhandler import TemporaryFileUploadHandler
from brutaldon.forms import LoginForm, OAuthLoginForm, SettingsForm, PostForm from brutaldon.forms import LoginForm, OAuthLoginForm, SettingsForm, PostForm
from brutaldon.models import Client, Account from brutaldon.models import Client, Account
from mastodon import Mastodon from mastodon import Mastodon
@ -51,25 +51,37 @@ def fullbrutalism_p(request):
fullbrutalism = False fullbrutalism = False
return fullbrutalism 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: try:
mastodon = get_mastodon(request) mastodon = get_mastodon(request)
except NotLoggedInException: except NotLoggedInException:
return redirect(login) return redirect(login)
data = mastodon.timeline(timeline) data = mastodon.timeline(timeline, limit=100, max_id=max_id, since_id=since_id)
form = PostForm() form = PostForm()
return render(request, 'main/timeline.html', try:
{'toots': data, 'form': form, 'timeline': timeline_name, prev = data[0]._pagination_prev
'fullbrutalism': fullbrutalism_p(request)}) 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): def home(request, next=None, prev=None):
return timeline(request, 'home', 'Home') return timeline(request, 'home', 'Home', max_id=next, since_id=prev)
def local(request): def local(request, next=None, prev=None):
return timeline(request, 'local', 'Local') return timeline(request, 'local', 'Local', max_id=next, since_id=prev)
def fed(request): def fed(request, next=None, prev=None):
return timeline(request, 'public', 'Federated') return timeline(request, 'public', 'Federated', max_id=next, since_id=prev)
def tag(request, tag): def tag(request, tag):
try: try: