Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions project/accounts/templates/accounts/user_civis.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends "base.html" %}
{% load i18n %}

{% block content %}
{% for civi in civis %}
<div class="civi-card white" data-id="">
<div class="civi-header-account white">
<div class="civi-title-outer">
<div class="civi-type gray-text">{{ civi.c_type }}</div>
<div class="civi-title">{{ civi.title }}</div>
</div>
</div>
<div class="civi-body">
<div class="civi-body-inner">{{ civi.body }}</div>
</div>
</div>
{% empty %}
<div class="section no-state">
<div class="container">
<div class="section">
<div class="center title-lato text">No activity</div>
</div>
</div>
</div>
{% endfor %}


{% endblock content %}
37 changes: 37 additions & 0 deletions project/accounts/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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="[email protected]", 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")
6 changes: 6 additions & 0 deletions project/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
SettingsView,
ProfileFollowing,
UserProfileView,
UserCivis,
expunge_user,
)
from django.contrib.auth import views as auth_views
Expand Down Expand Up @@ -43,6 +44,11 @@
ProfileFollowing.as_view(),
name="profile-following",
),
path(
"profile/<str:username>/civis/",
UserCivis.as_view(),
name="user-civis",
),
path(
"accounts/password_reset/",
PasswordResetView.as_view(),
Expand Down
18 changes: 18 additions & 0 deletions project/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down