mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-25 08:41:00 +00:00
Split Follows page into two types
This overcomes the query problem of pulling a combined list
This commit is contained in:
parent
fb2eea956e
commit
00795f119e
5 changed files with 53 additions and 26 deletions
|
@ -1,4 +1,3 @@
|
||||||
from django.db.models import Q
|
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.generic import ListView
|
from django.views.generic import ListView
|
||||||
|
|
||||||
|
@ -18,22 +17,40 @@ class Follows(ListView):
|
||||||
}
|
}
|
||||||
paginate_by = 50
|
paginate_by = 50
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
self.inbound = self.request.GET.get("inbound")
|
||||||
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return Follow.objects.filter(
|
if self.inbound:
|
||||||
Q(source=self.request.identity) | Q(target=self.request.identity),
|
return Follow.objects.filter(
|
||||||
state__in=FollowStates.group_active(),
|
target=self.request.identity,
|
||||||
).order_by("-created")
|
state__in=FollowStates.group_active(),
|
||||||
|
).order_by("-created")
|
||||||
|
else:
|
||||||
|
return Follow.objects.filter(
|
||||||
|
source=self.request.identity,
|
||||||
|
state__in=FollowStates.group_active(),
|
||||||
|
).order_by("-created")
|
||||||
|
|
||||||
def get_context_data(self):
|
def get_context_data(self):
|
||||||
context = super().get_context_data()
|
context = super().get_context_data()
|
||||||
identities = []
|
# Go work out if any of these people also follow us/are followed
|
||||||
for follow in context["page_obj"].object_list:
|
if self.inbound:
|
||||||
if follow.source == self.request.identity:
|
context["page_obj"].object_list = [
|
||||||
identity = follow.target
|
follow.source for follow in context["page_obj"]
|
||||||
follow_type = "outbound"
|
]
|
||||||
else:
|
identity_ids = [identity.id for identity in context["page_obj"]]
|
||||||
identity = follow.source
|
context["outbound_ids"] = Follow.objects.filter(
|
||||||
follow_type = "inbound"
|
source=self.request.identity, target_id__in=identity_ids
|
||||||
identities.append((identity, follow_type))
|
).values_list("target_id", flat=True)
|
||||||
context["page_obj"].object_list = identities
|
else:
|
||||||
|
context["page_obj"].object_list = [
|
||||||
|
follow.target for follow in context["page_obj"]
|
||||||
|
]
|
||||||
|
identity_ids = [identity.id for identity in context["page_obj"]]
|
||||||
|
context["inbound_ids"] = Follow.objects.filter(
|
||||||
|
target=self.request.identity, source_id__in=identity_ids
|
||||||
|
).values_list("source_id", flat=True)
|
||||||
|
context["inbound"] = self.inbound
|
||||||
return context
|
return context
|
||||||
|
|
|
@ -3,18 +3,28 @@
|
||||||
{% block subtitle %}Follows{% endblock %}
|
{% block subtitle %}Follows{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<div class="view-options">
|
||||||
|
{% if inbound %}
|
||||||
|
<a href=".?outbound=true">Your Follows</a>
|
||||||
|
<a href=".?outbound=true" class="selected">Follows You</a>
|
||||||
|
{% else %}
|
||||||
|
<a href=".?inbound=true" class="selected">Your Follows</a>
|
||||||
|
<a href=".?inbound=true">Follows You</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
<section class="icon-menu">
|
<section class="icon-menu">
|
||||||
{% for identity, follow_type in page_obj %}
|
{% for identity in page_obj %}
|
||||||
<a class="option" href="{{ identity.urls.view }}">
|
<a class="option" href="{{ identity.urls.view }}">
|
||||||
<img src="{{ identity.local_icon_url.relative }}">
|
<img src="{{ identity.local_icon_url.relative }}">
|
||||||
<span class="handle">
|
<span class="handle">
|
||||||
{{ identity.html_name_or_handle }}
|
{{ identity.html_name_or_handle }}
|
||||||
<small>@{{ identity.handle }}</small>
|
<small>@{{ identity.handle }}</small>
|
||||||
</span>
|
</span>
|
||||||
{% if follow_type == "outbound" %}
|
{% if identity.id in outbound_ids %}
|
||||||
<span class="pill">Following</span>
|
<span class="pill">Following</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if follow_type == "inbound" %}
|
{% if identity.id in inbound_ids %}
|
||||||
<span class="pill">Follows You</span>
|
<span class="pill">Follows You</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
|
@ -25,11 +35,11 @@
|
||||||
|
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
{% if page_obj.has_previous %}
|
{% if page_obj.has_previous %}
|
||||||
<div class="load-more"><a class="button" href=".?page={{ page_obj.previous_page_number }}">Previous Page</a></div>
|
<a class="button" href=".?page={{ page_obj.previous_page_number }}">Previous Page</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if page_obj.has_next %}
|
{% if page_obj.has_next %}
|
||||||
<div class="load-more"><a class="button" href=".?page={{ page_obj.next_page_number }}">Next Page</a></div>
|
<a class="button" href=".?page={{ page_obj.next_page_number }}">Next Page</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -24,11 +24,11 @@
|
||||||
|
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
{% if page_obj.has_previous %}
|
{% if page_obj.has_previous %}
|
||||||
<div class="load-more"><a class="button" href=".?page={{ page_obj.previous_page_number }}">Previous Page</a></div>
|
<a class="button" href=".?page={{ page_obj.previous_page_number }}">Previous Page</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if page_obj.has_next %}
|
{% if page_obj.has_next %}
|
||||||
<div class="load-more"><a class="button" href=".?page={{ page_obj.next_page_number }}">Next Page</a></div>
|
<a class="button" href=".?page={{ page_obj.next_page_number }}">Next Page</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -11,11 +11,11 @@
|
||||||
|
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
{% if page_obj.has_previous %}
|
{% if page_obj.has_previous %}
|
||||||
<div class="load-more"><a class="button" href=".?page={{ page_obj.previous_page_number }}">Previous Page</a></div>
|
<a class="button" href=".?page={{ page_obj.previous_page_number }}">Previous Page</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if page_obj.has_next %}
|
{% if page_obj.has_next %}
|
||||||
<div class="load-more"><a class="button" href=".?page={{ page_obj.next_page_number }}">Next Page</a></div>
|
<a class="button" href=".?page={{ page_obj.next_page_number }}">Next Page</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -34,11 +34,11 @@
|
||||||
|
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
{% if page_obj.has_previous %}
|
{% if page_obj.has_previous %}
|
||||||
<div class="load-more"><a class="button" href=".?page={{ page_obj.previous_page_number }}">Previous Page</a></div>
|
<a class="button" href=".?page={{ page_obj.previous_page_number }}">Previous Page</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if page_obj.has_next %}
|
{% if page_obj.has_next %}
|
||||||
<div class="load-more"><a class="button" href=".?page={{ page_obj.next_page_number }}">Next Page</a></div>
|
<a class="button" href=".?page={{ page_obj.next_page_number }}">Next Page</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue