This repository has been archived on 2023-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
takahe/activities/views/follows.py

34 lines
1.1 KiB
Python
Raw Normal View History

2022-11-18 04:04:01 +01:00
from django.utils.decorators import method_decorator
from django.views.generic import TemplateView
from users.decorators import identity_required
from users.models import FollowStates
@method_decorator(identity_required, name="dispatch")
class FollowsPage(TemplateView):
"""
Shows followers/follows.
"""
template_name = "activities/follows.html"
2022-11-18 04:04:01 +01:00
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
return {
"section": "follows",
"identities": sorted(identities.items(), key=lambda i: i[0].username),
}