Commit b2effb77 authored by Jason Robinson's avatar Jason Robinson

Add followers page and link from profile

parent 450fb863
Pipeline #1343 passed with stage
in 5 minutes and 53 seconds
......@@ -25,6 +25,8 @@ Added
* It's now possible to disable incoming `relay system <https://git.feneas.org/jaywink/social-relay>`_ integration by setting the environment variable ``SOCIALHOME_RELAY_SCOPE`` to ``none``. (`#94 <https://git.feneas.org/socialhome/socialhome/issues/94>`_)
* User profile now has a link to a new followers contacts page. This is limited to the logged in user only.
Changed
.......
......
......@@ -51,7 +51,7 @@
<div class="mt-1">
<b-button
variant="secondary"
href="#"
:href="urls.contactsFollowers"
:title="translations.followers"
:aria-label="translations.followers"
>
......@@ -159,6 +159,7 @@ export default Vue.component("profile-stamped-element", {
urls() {
return {
contactsFollowed: Urls["users:contacts-followed"](),
contactsFollowers: Urls["users:contacts-followers"](),
organizeProfileUrl: Urls["users:profile-organize"](),
pictureUpdate: Urls["users:picture-update"](),
pinnedContent: Urls["users:profile-detail"]({uuid: this.profile.uuid}),
......
This diff is collapsed.
......@@ -4,7 +4,7 @@ from django_tables2.utils import Accessor
from socialhome.users.models import Profile
class FollowedTable(Table):
class ContactTable(Table):
picture = TemplateColumn(template_name="users/_picture_column.html", orderable=False)
handle = LinkColumn(
"users:profile-detail", args=[Accessor("uuid")], text=lambda record: record.handle if record.handle else "",
......
{% extends "base.html" %}
{% load i18n %}
{% load render_table from django_tables2 %}
{% block title %}{% trans "Contacts - followers" %}{% endblock %}
{% block content %}
<h1>{% trans "Contacts - followers" %}</h1>
<br>
{% render_table followers_table %}
{% endblock %}
......@@ -12,7 +12,7 @@ from socialhome.streams.enums import StreamType
from socialhome.tests.utils import SocialhomeTestCase
from socialhome.users.models import User, Profile
from socialhome.users.serializers import ProfileSerializer
from socialhome.users.tables import FollowedTable
from socialhome.users.tables import ContactTable
from socialhome.users.tests.factories import (
UserFactory, AdminUserFactory, ProfileFactory, PublicUserFactory, PublicProfileFactory)
from socialhome.users.views import (
......@@ -489,7 +489,33 @@ class TestContactsFollowedView(SocialhomeTestCase):
def test_contains_table_object(self):
with self.login(self.user):
self.get("users:contacts-followed")
self.assertTrue(isinstance(self.context["followed_table"], FollowedTable))
self.assertTrue(isinstance(self.context["followed_table"], ContactTable))
self.assertEqual(len(self.context["followed_table"].data), 1)
self.assertContext("profile", self.user.profile)
class TestContactsFollowersView(SocialhomeTestCase):
@classmethod
def setUpTestData(cls):
super().setUpTestData()
cls.user = UserFactory()
cls.profile = ProfileFactory()
cls.profile.following.add(cls.user.profile)
def test_login_required(self):
# Not logged in, redirects to login
self.get("users:contacts-followers")
self.response_302()
# Logged in
with self.login(self.user):
self.get("users:contacts-followers")
self.response_200()
def test_contains_table_object(self):
with self.login(self.user):
self.get("users:contacts-followers")
self.assertTrue(isinstance(self.context["followers_table"], ContactTable))
self.assertEqual(len(self.context["followers_table"].data), 1)
self.assertContext("profile", self.user.profile)
......
......@@ -37,6 +37,16 @@ urlpatterns = [
view=views.ProfileUpdateView.as_view(),
name="profile-update"
),
url(
regex=r"^p/~followed/$",
view=views.ContactsFollowedView.as_view(),
name="contacts-followed"
),
url(
regex=r"^p/~followers/$",
view=views.ContactsFollowersView.as_view(),
name="contacts-followers"
),
url(
regex=r"^p/(?P<uuid>[^/]+)/all/$",
view=views.ProfileAllContentView.as_view(),
......@@ -48,10 +58,5 @@ urlpatterns = [
view=csrf_exempt(views.ProfileDetailView.as_view()),
name="profile-detail"
),
url(
regex=r"^contacts/$",
view=views.ContactsFollowedView.as_view(),
name="contacts-followed"
),
path('delete-account/', views.DeleteAccountView.as_view(), name="delete-account"),
]
......@@ -13,7 +13,7 @@ from socialhome.streams.views import BaseStreamView
from socialhome.users.forms import ProfileForm, UserPictureForm
from socialhome.users.models import User, Profile
from socialhome.users.serializers import ProfileSerializer
from socialhome.users.tables import FollowedTable
from socialhome.users.tables import ContactTable
from socialhome.utils import get_full_url
......@@ -202,7 +202,22 @@ class ContactsFollowedView(LoginRequiredMixin, DetailView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
table = FollowedTable(self.object.following.all(), order_by=self.request.GET.get("sort"))
table = ContactTable(self.object.following.all(), order_by=self.request.GET.get("sort"))
table.paginate(page=self.request.GET.get("page", 1), per_page=25)
context["followed_table"] = table
return context
class ContactsFollowersView(LoginRequiredMixin, DetailView):
model = Profile
template_name = "users/contacts_followers.html"
def get_object(self, queryset=None):
return self.request.user.profile
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
table = ContactTable(self.object.followers.all(), order_by=self.request.GET.get("sort"))
table.paginate(page=self.request.GET.get("page", 1), per_page=25)
context["followers_table"] = table
return context
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment