2022-12-16 16:06:29 -08:00
|
|
|
from django.db.models import Q
|
2022-11-17 19:04:01 -08:00
|
|
|
from django.utils.decorators import method_decorator
|
2022-12-16 16:06:29 -08:00
|
|
|
from django.views.generic import ListView
|
2022-11-17 19:04:01 -08:00
|
|
|
|
|
|
|
from users.decorators import identity_required
|
2022-12-16 16:06:29 -08:00
|
|
|
from users.models import Follow, FollowStates
|
2022-11-17 19:04:01 -08:00
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(identity_required, name="dispatch")
|
2022-12-16 16:06:29 -08:00
|
|
|
class Follows(ListView):
|
2022-11-17 19:04:01 -08:00
|
|
|
"""
|
|
|
|
Shows followers/follows.
|
|
|
|
"""
|
|
|
|
|
2022-12-04 08:41:41 -08:00
|
|
|
template_name = "activities/follows.html"
|
2022-12-16 16:06:29 -08:00
|
|
|
extra_context = {
|
|
|
|
"section": "follows",
|
|
|
|
}
|
|
|
|
paginate_by = 50
|
2022-11-17 19:04:01 -08:00
|
|
|
|
2022-12-16 16:06:29 -08:00
|
|
|
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")
|
2022-11-17 19:04:01 -08:00
|
|
|
|
2022-12-16 16:06:29 -08:00
|
|
|
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
|