From 6ce05296b01b1bd177e93b5ea3745fba5a5ff8f2 Mon Sep 17 00:00:00 2001 From: Tyler Kennedy Date: Sun, 4 Dec 2022 11:41:41 -0500 Subject: Make follows a top-level activity. (#94) --- activities/views/follows.py | 33 +++++++++++++++++++++++++++++++++ takahe/urls.py | 15 ++++++++------- templates/activities/_menu.html | 3 +++ templates/activities/follows.html | 25 +++++++++++++++++++++++++ templates/settings/_menu.html | 3 --- templates/settings/follows.html | 25 ------------------------- users/views/follows.py | 33 --------------------------------- 7 files changed, 69 insertions(+), 68 deletions(-) create mode 100644 activities/views/follows.py create mode 100644 templates/activities/follows.html delete mode 100644 templates/settings/follows.html delete mode 100644 users/views/follows.py diff --git a/activities/views/follows.py b/activities/views/follows.py new file mode 100644 index 0000000..44d8adc --- /dev/null +++ b/activities/views/follows.py @@ -0,0 +1,33 @@ +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" + + 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), + } diff --git a/takahe/urls.py b/takahe/urls.py index 9aa67a2..0e995c4 100644 --- a/takahe/urls.py +++ b/takahe/urls.py @@ -3,10 +3,10 @@ from django.contrib import admin as djadmin from django.urls import path, re_path from django.views.static import serve -from activities.views import compose, explore, posts, search, timelines +from activities.views import compose, explore, follows, posts, search, timelines from core import views as core from stator import views as stator -from users.views import activitypub, admin, auth, follows, identity, settings +from users.views import activitypub, admin, auth, identity, settings urlpatterns = [ path("", core.homepage), @@ -19,6 +19,12 @@ urlpatterns = [ path("tags//", timelines.Tag.as_view(), name="tag"), path("explore/", explore.Explore.as_view(), name="explore"), path("explore/tags/", explore.ExploreTag.as_view(), name="explore-tag"), + path( + "follows/", + follows.FollowsPage.as_view(), + name="follows", + ), + # Settings views path( "settings/", settings.SettingsRoot.as_view(), @@ -34,11 +40,6 @@ urlpatterns = [ settings.ProfilePage.as_view(), name="settings_profile", ), - path( - "settings/follows/", - follows.FollowsPage.as_view(), - name="settings_follows", - ), path( "settings/interface/", settings.InterfacePage.as_view(), diff --git a/templates/activities/_menu.html b/templates/activities/_menu.html index a912090..4676831 100644 --- a/templates/activities/_menu.html +++ b/templates/activities/_menu.html @@ -18,6 +18,9 @@ Federated + + Follows +

Compose diff --git a/templates/activities/follows.html b/templates/activities/follows.html new file mode 100644 index 0000000..6116dd6 --- /dev/null +++ b/templates/activities/follows.html @@ -0,0 +1,25 @@ +{% extends "base.html" %} + +{% block subtitle %}Follows{% endblock %} + +{% block content %} +
+ {% for identity, details in identities %} + + + + {{ identity.name_or_handle }} + @{{ identity.handle }} + + {% if details.outbound %} + Following + {% endif %} + {% if details.inbound %} + Follows You + {% endif %} + + {% empty %} +

You have no follows.

+ {% endfor %} +
+{% endblock %} diff --git a/templates/settings/_menu.html b/templates/settings/_menu.html index 8aede68..55c0100 100644 --- a/templates/settings/_menu.html +++ b/templates/settings/_menu.html @@ -6,9 +6,6 @@ Interface - - Follows -

Account

Login & Security diff --git a/templates/settings/follows.html b/templates/settings/follows.html deleted file mode 100644 index 5f43d05..0000000 --- a/templates/settings/follows.html +++ /dev/null @@ -1,25 +0,0 @@ -{% extends "settings/base.html" %} - -{% block subtitle %}Follows{% endblock %} - -{% block content %} -
- {% for identity, details in identities %} - - - - {{ identity.name_or_handle }} - @{{ identity.handle }} - - {% if details.outbound %} - Following - {% endif %} - {% if details.inbound %} - Follows You - {% endif %} - - {% empty %} -

You have no follows.

- {% endfor %} -
-{% endblock %} diff --git a/users/views/follows.py b/users/views/follows.py deleted file mode 100644 index 9030efe..0000000 --- a/users/views/follows.py +++ /dev/null @@ -1,33 +0,0 @@ -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 = "settings/follows.html" - - 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), - } -- cgit v1.2.3