summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Godwin2022-12-16 17:24:56 -0700
committerAndrew Godwin2022-12-16 17:24:56 -0700
commit00795f119eeb4b8eb1330b7959ca5ef93accc64b (patch)
tree4eceb5408f1135d30cdce18d69e5a783015812c4
parentfb2eea956ef7416eb755ebecf58db7f9a57215c4 (diff)
downloadtakahe-00795f119eeb4b8eb1330b7959ca5ef93accc64b.tar.gz
takahe-00795f119eeb4b8eb1330b7959ca5ef93accc64b.tar.bz2
takahe-00795f119eeb4b8eb1330b7959ca5ef93accc64b.zip
Split Follows page into two types
This overcomes the query problem of pulling a combined list
-rw-r--r--activities/views/follows.py47
-rw-r--r--templates/activities/follows.html20
-rw-r--r--templates/activities/home.html4
-rw-r--r--templates/activities/local.html4
-rw-r--r--templates/activities/notifications.html4
5 files changed, 53 insertions, 26 deletions
diff --git a/activities/views/follows.py b/activities/views/follows.py
index 6b0881a..f5f5909 100644
--- a/activities/views/follows.py
+++ b/activities/views/follows.py
@@ -1,4 +1,3 @@
-from django.db.models import Q
from django.utils.decorators import method_decorator
from django.views.generic import ListView
@@ -18,22 +17,40 @@ class Follows(ListView):
}
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):
- return Follow.objects.filter(
- Q(source=self.request.identity) | Q(target=self.request.identity),
- state__in=FollowStates.group_active(),
- ).order_by("-created")
+ if self.inbound:
+ return Follow.objects.filter(
+ target=self.request.identity,
+ 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):
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
+ # Go work out if any of these people also follow us/are followed
+ if self.inbound:
+ context["page_obj"].object_list = [
+ follow.source for follow in context["page_obj"]
+ ]
+ identity_ids = [identity.id for identity in context["page_obj"]]
+ context["outbound_ids"] = Follow.objects.filter(
+ source=self.request.identity, target_id__in=identity_ids
+ ).values_list("target_id", flat=True)
+ 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
diff --git a/templates/activities/follows.html b/templates/activities/follows.html
index e2c0ece..bc2db7d 100644
--- a/templates/activities/follows.html
+++ b/templates/activities/follows.html
@@ -3,18 +3,28 @@
{% block subtitle %}Follows{% endblock %}
{% 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">
- {% for identity, follow_type in page_obj %}
+ {% for identity in page_obj %}
<a class="option" href="{{ identity.urls.view }}">
<img src="{{ identity.local_icon_url.relative }}">
<span class="handle">
{{ identity.html_name_or_handle }}
<small>@{{ identity.handle }}</small>
</span>
- {% if follow_type == "outbound" %}
+ {% if identity.id in outbound_ids %}
<span class="pill">Following</span>
{% endif %}
- {% if follow_type == "inbound" %}
+ {% if identity.id in inbound_ids %}
<span class="pill">Follows You</span>
{% endif %}
</a>
@@ -25,11 +35,11 @@
<div class="pagination">
{% 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 %}
{% 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 %}
</div>
{% endblock %}
diff --git a/templates/activities/home.html b/templates/activities/home.html
index 06fa88c..8d9d39c 100644
--- a/templates/activities/home.html
+++ b/templates/activities/home.html
@@ -24,11 +24,11 @@
<div class="pagination">
{% 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 %}
{% 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 %}
</div>
{% endblock %}
diff --git a/templates/activities/local.html b/templates/activities/local.html
index c3d180b..55f9090 100644
--- a/templates/activities/local.html
+++ b/templates/activities/local.html
@@ -11,11 +11,11 @@
<div class="pagination">
{% 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 %}
{% 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 %}
</div>
{% endblock %}
diff --git a/templates/activities/notifications.html b/templates/activities/notifications.html
index 89ca4d8..8b7bc13 100644
--- a/templates/activities/notifications.html
+++ b/templates/activities/notifications.html
@@ -34,11 +34,11 @@
<div class="pagination">
{% 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 %}
{% 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 %}
</div>
{% endblock %}