summaryrefslogtreecommitdiffstats
path: root/activities/views/follows.py
diff options
context:
space:
mode:
Diffstat (limited to 'activities/views/follows.py')
-rw-r--r--activities/views/follows.py46
1 files changed, 26 insertions, 20 deletions
diff --git a/activities/views/follows.py b/activities/views/follows.py
index 44d8adc..6b0881a 100644
--- a/activities/views/follows.py
+++ b/activities/views/follows.py
@@ -1,33 +1,39 @@
+from django.db.models import Q
from django.utils.decorators import method_decorator
-from django.views.generic import TemplateView
+from django.views.generic import ListView
from users.decorators import identity_required
-from users.models import FollowStates
+from users.models import Follow, FollowStates
@method_decorator(identity_required, name="dispatch")
-class FollowsPage(TemplateView):
+class Follows(ListView):
"""
Shows followers/follows.
"""
template_name = "activities/follows.html"
+ extra_context = {
+ "section": "follows",
+ }
+ paginate_by = 50
- def get_context_data(self):
- # Gather all identities with a following relationship with us
- identities = {}
- for outbound_follow in self.request.identity.outbound_follows.filter(
- state__in=FollowStates.group_active()
- ):
- identities.setdefault(outbound_follow.target, {})[
- "outbound"
- ] = outbound_follow
- for inbound_follow in self.request.identity.inbound_follows.filter(
- state__in=FollowStates.group_active()
- ):
- identities.setdefault(inbound_follow.source, {})["inbound"] = inbound_follow
+ def get_queryset(self):
+ return Follow.objects.filter(
+ Q(source=self.request.identity) | Q(target=self.request.identity),
+ state__in=FollowStates.group_active(),
+ ).order_by("-created")
- return {
- "section": "follows",
- "identities": sorted(identities.items(), key=lambda i: i[0].username),
- }
+ def get_context_data(self):
+ context = super().get_context_data()
+ identities = []
+ for follow in context["page_obj"].object_list:
+ if follow.source == self.request.identity:
+ identity = follow.target
+ follow_type = "outbound"
+ else:
+ identity = follow.source
+ follow_type = "inbound"
+ identities.append((identity, follow_type))
+ context["page_obj"].object_list = identities
+ return context