Start adding pagniation to timelines
This commit is contained in:
parent
63ab492439
commit
b7c7c66013
|
@ -2,7 +2,7 @@ from django import forms
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.template.defaultfilters import linebreaks_filter
|
from django.template.defaultfilters import linebreaks_filter
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.generic import FormView, TemplateView
|
from django.views.generic import FormView, ListView
|
||||||
|
|
||||||
from activities.models import Post, PostInteraction, TimelineEvent
|
from activities.models import Post, PostInteraction, TimelineEvent
|
||||||
from users.decorators import identity_required
|
from users.decorators import identity_required
|
||||||
|
@ -57,47 +57,46 @@ class Home(FormView):
|
||||||
return redirect(".")
|
return redirect(".")
|
||||||
|
|
||||||
|
|
||||||
class Local(TemplateView):
|
class Local(ListView):
|
||||||
|
|
||||||
template_name = "activities/local.html"
|
template_name = "activities/local.html"
|
||||||
|
extra_context = {"current_page": "local"}
|
||||||
|
paginate_by = 50
|
||||||
|
|
||||||
def get_context_data(self):
|
def get_queryset(self):
|
||||||
context = super().get_context_data()
|
return (
|
||||||
context["posts"] = (
|
|
||||||
Post.objects.filter(visibility=Post.Visibilities.public, author__local=True)
|
Post.objects.filter(visibility=Post.Visibilities.public, author__local=True)
|
||||||
.select_related("author")
|
.select_related("author")
|
||||||
.prefetch_related("attachments")
|
.prefetch_related("attachments")
|
||||||
.order_by("-created")[:50]
|
.order_by("-created")[:50]
|
||||||
)
|
)
|
||||||
context["current_page"] = "local"
|
|
||||||
return context
|
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(identity_required, name="dispatch")
|
@method_decorator(identity_required, name="dispatch")
|
||||||
class Federated(TemplateView):
|
class Federated(ListView):
|
||||||
|
|
||||||
template_name = "activities/federated.html"
|
template_name = "activities/federated.html"
|
||||||
|
extra_context = {"current_page": "federated"}
|
||||||
|
paginate_by = 50
|
||||||
|
|
||||||
def get_context_data(self):
|
def get_queryset(self):
|
||||||
context = super().get_context_data()
|
return (
|
||||||
context["posts"] = (
|
|
||||||
Post.objects.filter(visibility=Post.Visibilities.public)
|
Post.objects.filter(visibility=Post.Visibilities.public)
|
||||||
.select_related("author")
|
.select_related("author")
|
||||||
.prefetch_related("attachments")
|
.prefetch_related("attachments")
|
||||||
.order_by("-created")[:50]
|
.order_by("-created")[:50]
|
||||||
)
|
)
|
||||||
context["current_page"] = "federated"
|
|
||||||
return context
|
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(identity_required, name="dispatch")
|
@method_decorator(identity_required, name="dispatch")
|
||||||
class Notifications(TemplateView):
|
class Notifications(ListView):
|
||||||
|
|
||||||
template_name = "activities/notifications.html"
|
template_name = "activities/notifications.html"
|
||||||
|
extra_context = {"current_page": "notifications"}
|
||||||
|
paginate_by = 50
|
||||||
|
|
||||||
def get_context_data(self):
|
def get_queryset(self):
|
||||||
context = super().get_context_data()
|
return (
|
||||||
context["events"] = (
|
|
||||||
TimelineEvent.objects.filter(
|
TimelineEvent.objects.filter(
|
||||||
identity=self.request.identity,
|
identity=self.request.identity,
|
||||||
type__in=[
|
type__in=[
|
||||||
|
@ -110,5 +109,3 @@ class Notifications(TemplateView):
|
||||||
.order_by("-created")[:50]
|
.order_by("-created")[:50]
|
||||||
.select_related("subject_post", "subject_post__author", "subject_identity")
|
.select_related("subject_post", "subject_post__author", "subject_identity")
|
||||||
)
|
)
|
||||||
context["current_page"] = "notifications"
|
|
||||||
return context
|
|
||||||
|
|
|
@ -559,8 +559,8 @@ form p+.buttons {
|
||||||
margin: 5px 10px 5px 0;
|
margin: 5px 10px 5px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
form button,
|
button,
|
||||||
form .button {
|
.button {
|
||||||
padding: 5px 10px;
|
padding: 5px 10px;
|
||||||
margin: 0 0 0 5px;
|
margin: 0 0 0 5px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
|
@ -572,39 +572,39 @@ form .button {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
form button.delete,
|
button.delete,
|
||||||
form .button.delete {
|
.button.delete {
|
||||||
background: var(--color-delete);
|
background: var(--color-delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
form button.secondary,
|
button.secondary,
|
||||||
form .button.secondary {
|
.button.secondary {
|
||||||
background: var(--color-bg-menu);
|
background: var(--color-bg-menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
form button.toggle,
|
button.toggle,
|
||||||
form .button.toggle {
|
.button.toggle {
|
||||||
background: var(--color-bg-main);
|
background: var(--color-bg-main);
|
||||||
}
|
}
|
||||||
|
|
||||||
form button.left,
|
button.left,
|
||||||
form .button.left {
|
.button.left {
|
||||||
float: left;
|
float: left;
|
||||||
margin: 0 5px 0 0;
|
margin: 0 5px 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
form button.toggle.enabled,
|
button.toggle.enabled,
|
||||||
form .button.toggle.enabled {
|
.button.toggle.enabled {
|
||||||
background: var(--color-highlight);
|
background: var(--color-highlight);
|
||||||
}
|
}
|
||||||
|
|
||||||
form button:hover,
|
button:hover,
|
||||||
form .button:hover {
|
.button:hover {
|
||||||
border: 3px solid rgba(255, 255, 255, 0.3);
|
border: 3px solid rgba(255, 255, 255, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.right-column form button,
|
.right-column button,
|
||||||
.right-column form .button {
|
.right-column .button {
|
||||||
padding: 2px 6px;
|
padding: 2px 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,6 +810,10 @@ h1.identity small {
|
||||||
margin-right: 4px;
|
margin-right: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.load-more {
|
||||||
|
margin: 10px 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@media (max-width: 920px) or (display-mode: standalone) {
|
@media (max-width: 920px) or (display-mode: standalone) {
|
||||||
|
|
|
@ -1,11 +1,3 @@
|
||||||
{% extends "base.html" %}
|
{% extends "activities/local.html" %}
|
||||||
|
|
||||||
{% block title %}Federated Timeline{% endblock %}
|
{% block title %}Federated Timeline{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
{% for post in posts %}
|
|
||||||
{% include "activities/_post.html" %}
|
|
||||||
{% empty %}
|
|
||||||
No posts yet.
|
|
||||||
{% endfor %}
|
|
||||||
{% endblock %}
|
|
||||||
|
|
|
@ -3,9 +3,13 @@
|
||||||
{% block title %}Local Timeline{% endblock %}
|
{% block title %}Local Timeline{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% for post in posts %}
|
{% for post in page_obj %}
|
||||||
{% include "activities/_post.html" %}
|
{% include "activities/_post.html" %}
|
||||||
{% empty %}
|
{% empty %}
|
||||||
No posts yet.
|
No posts yet.
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if page_obj.has_next %}
|
||||||
|
<div class="load-more"><a class="button" href=".?page={{ page_obj.next_page_number }}">Next Page</a></div>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -3,9 +3,13 @@
|
||||||
{% block title %}Notifications{% endblock %}
|
{% block title %}Notifications{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% for event in events %}
|
{% for event in page_obj %}
|
||||||
{% include "activities/_event.html" %}
|
{% include "activities/_event.html" %}
|
||||||
{% empty %}
|
{% empty %}
|
||||||
No events yet.
|
No notirications yet.
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if page_obj.has_next %}
|
||||||
|
<div class="load-more"><a class="button" href=".?page={{ page_obj.next_page_number }}">Next Page</a></div>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue