diff --git a/project/accounts/templates/accounts/user_civis.html b/project/accounts/templates/accounts/user_civis.html
new file mode 100644
index 00000000..d1a616b1
--- /dev/null
+++ b/project/accounts/templates/accounts/user_civis.html
@@ -0,0 +1,28 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block content %}
+ {% for civi in civis %}
+
+ {% empty %}
+
+ {% endfor %}
+
+
+{% endblock content %}
diff --git a/project/accounts/tests/test_views.py b/project/accounts/tests/test_views.py
index bfd2f542..aafb1391 100644
--- a/project/accounts/tests/test_views.py
+++ b/project/accounts/tests/test_views.py
@@ -4,6 +4,7 @@
from django.contrib.auth import views as auth_views
from django.test import TestCase
from django.urls import resolve, reverse
+from threads.models import Civi, Thread
class BaseTestCase(TestCase):
@@ -215,3 +216,39 @@ def test_get_user_profile(self):
self.assertEqual(response.status_code, 200)
self.assertContains(response, self.user.username)
self.assertTemplateUsed(response, "account.html")
+
+
+class UserProfileCivis(BaseTestCase):
+ """A class to test user profiles following view"""
+
+ def setUp(self) -> None:
+ super(UserProfileCivis, self).setUp()
+
+ self.user2 = get_user_model().objects.create_user(
+ username="newuser2", email="test2@test2.com", password="password123"
+ )
+
+ thread = Thread(
+ author=self.user2, title="test thread", summary="this is a test thread"
+ )
+ thread.save()
+ civi = Civi(author=self.user, thread=thread, title="test civi title")
+ civi.save()
+
+ def test_get_my_civis(self):
+ """Whether user_profile function works as expected"""
+
+ self.client.login(username="newuser", password="password123")
+ response = self.client.get(reverse("user-civis", args=["newuser"]))
+ self.assertEqual(response.status_code, 200)
+ self.assertContains(response, "test civi title")
+ self.assertTemplateUsed(response, "user_civis.html")
+
+ def test_get_other_civis(self):
+ """Whether user_profile function works as expected"""
+
+ self.client.login(username="newuser2", password="password123")
+ response = self.client.get(reverse("user-civis", args=["newuser"]))
+ self.assertEqual(response.status_code, 200)
+ self.assertContains(response, "test civi title")
+ self.assertTemplateUsed(response, "user_civis.html")
diff --git a/project/accounts/urls.py b/project/accounts/urls.py
index a008713b..b1daeb95 100644
--- a/project/accounts/urls.py
+++ b/project/accounts/urls.py
@@ -10,6 +10,7 @@
SettingsView,
ProfileFollowing,
UserProfileView,
+ UserCivis,
expunge_user,
)
from django.contrib.auth import views as auth_views
@@ -43,6 +44,11 @@
ProfileFollowing.as_view(),
name="profile-following",
),
+ path(
+ "profile//civis/",
+ UserCivis.as_view(),
+ name="user-civis",
+ ),
path(
"accounts/password_reset/",
PasswordResetView.as_view(),
diff --git a/project/accounts/views.py b/project/accounts/views.py
index a49d77b6..de4f5354 100644
--- a/project/accounts/views.py
+++ b/project/accounts/views.py
@@ -206,6 +206,24 @@ def get(self, request, username=None):
)
+class UserCivis(LoginRequiredMixin, View):
+ """
+ A view that shows list of civis
+ that profile with given username created
+ """
+
+ def get(self, request, username=None):
+ profile = get_object_or_404(Profile, user__username=username)
+ user = profile.user
+ civis = user.civis.all()
+
+ return TemplateResponse(
+ request,
+ "user_civis.html",
+ {"profile": profile, "civis": civis},
+ )
+
+
@login_required
def expunge_user(request):
"""