Fix profile page post listing
This commit is contained in:
parent
05ed5989e3
commit
47de2c4424
@ -56,9 +56,13 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% for post in posts %}
|
{% for post in page_obj %}
|
||||||
{% include "activities/_post.html" %}
|
{% include "activities/_post.html" %}
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<span class="empty">No posts yet.</a>
|
<span class="empty">No posts yet.</a>
|
||||||
{% 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 %}
|
||||||
|
@ -6,8 +6,9 @@ from django.core import validators
|
|||||||
from django.http import Http404, JsonResponse
|
from django.http import Http404, JsonResponse
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.generic import FormView, TemplateView, View
|
from django.views.generic import FormView, ListView, TemplateView, View
|
||||||
|
|
||||||
|
from activities.models import Post
|
||||||
from core.ld import canonicalise
|
from core.ld import canonicalise
|
||||||
from core.models import Config
|
from core.models import Config
|
||||||
from users.decorators import identity_required
|
from users.decorators import identity_required
|
||||||
@ -15,22 +16,28 @@ from users.models import Domain, Follow, FollowStates, Identity, IdentityStates
|
|||||||
from users.shortcuts import by_handle_or_404
|
from users.shortcuts import by_handle_or_404
|
||||||
|
|
||||||
|
|
||||||
class ViewIdentity(TemplateView):
|
class ViewIdentity(ListView):
|
||||||
"""
|
"""
|
||||||
Shows identity profile pages, and also acts as the Actor endpoint when
|
Shows identity profile pages, and also acts as the Actor endpoint when
|
||||||
approached with the right Accept header.
|
approached with the right Accept header.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
template_name = "identity/view.html"
|
template_name = "identity/view.html"
|
||||||
|
paginate_by = 5
|
||||||
|
|
||||||
def get(self, request, handle):
|
def get(self, request, handle):
|
||||||
# Make sure we understand this handle
|
# Make sure we understand this handle
|
||||||
identity = by_handle_or_404(
|
self.identity = by_handle_or_404(
|
||||||
self.request,
|
self.request,
|
||||||
handle,
|
handle,
|
||||||
local=False,
|
local=False,
|
||||||
fetch=True,
|
fetch=True,
|
||||||
)
|
)
|
||||||
|
if (
|
||||||
|
not self.identity.local
|
||||||
|
and self.identity.data_age > Config.system.identity_max_age
|
||||||
|
):
|
||||||
|
self.identity.transition_perform(IdentityStates.outdated)
|
||||||
# If they're coming in looking for JSON, they want the actor
|
# If they're coming in looking for JSON, they want the actor
|
||||||
accept = request.META.get("HTTP_ACCEPT", "text/html").lower()
|
accept = request.META.get("HTTP_ACCEPT", "text/html").lower()
|
||||||
if (
|
if (
|
||||||
@ -39,10 +46,10 @@ class ViewIdentity(TemplateView):
|
|||||||
or "application/activity" in accept
|
or "application/activity" in accept
|
||||||
):
|
):
|
||||||
# Return actor info
|
# Return actor info
|
||||||
return self.serve_actor(identity)
|
return self.serve_actor(self.identity)
|
||||||
else:
|
else:
|
||||||
# Show normal page
|
# Show normal page
|
||||||
return super().get(request, identity=identity)
|
return super().get(request, identity=self.identity)
|
||||||
|
|
||||||
def serve_actor(self, identity):
|
def serve_actor(self, identity):
|
||||||
# If this not a local actor, redirect to their canonical URI
|
# If this not a local actor, redirect to their canonical URI
|
||||||
@ -50,28 +57,29 @@ class ViewIdentity(TemplateView):
|
|||||||
return redirect(identity.actor_uri)
|
return redirect(identity.actor_uri)
|
||||||
return JsonResponse(canonicalise(identity.to_ap(), include_security=True))
|
return JsonResponse(canonicalise(identity.to_ap(), include_security=True))
|
||||||
|
|
||||||
def get_context_data(self, identity):
|
def get_queryset(self):
|
||||||
posts = identity.posts.all()[:100]
|
return (
|
||||||
if identity.data_age > Config.system.identity_max_age:
|
self.identity.posts.filter(
|
||||||
identity.transition_perform(IdentityStates.outdated)
|
visibility__in=[Post.Visibilities.public, Post.Visibilities.unlisted],
|
||||||
follow = None
|
)
|
||||||
reverse_follow = None
|
.select_related("author")
|
||||||
|
.prefetch_related("attachments")
|
||||||
|
.order_by("-created")
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_context_data(self):
|
||||||
|
context = super().get_context_data()
|
||||||
|
context["identity"] = self.identity
|
||||||
|
context["follow"] = None
|
||||||
|
context["reverse_follow"] = None
|
||||||
if self.request.identity:
|
if self.request.identity:
|
||||||
follow = Follow.maybe_get(self.request.identity, identity)
|
follow = Follow.maybe_get(self.request.identity, self.identity)
|
||||||
if follow and follow.state not in FollowStates.group_active():
|
if follow and follow.state in FollowStates.group_active():
|
||||||
follow = None
|
context["follow"] = follow
|
||||||
reverse_follow = Follow.maybe_get(identity, self.request.identity)
|
reverse_follow = Follow.maybe_get(self.identity, self.request.identity)
|
||||||
if (
|
if reverse_follow and reverse_follow.state in FollowStates.group_active():
|
||||||
reverse_follow
|
context["reverse_follow"] = reverse_follow
|
||||||
and reverse_follow.state not in FollowStates.group_active()
|
return context
|
||||||
):
|
|
||||||
reverse_follow = None
|
|
||||||
return {
|
|
||||||
"identity": identity,
|
|
||||||
"posts": posts,
|
|
||||||
"follow": follow,
|
|
||||||
"reverse_follow": reverse_follow,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(identity_required, name="dispatch")
|
@method_decorator(identity_required, name="dispatch")
|
||||||
|
Reference in New Issue
Block a user