Skip to content

Commit 9685d57

Browse files
authored
Merge pull request #1477 from audreyelim/develop
add civis tab to user profile
2 parents 5e6bcd6 + 73d3c3c commit 9685d57

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{% extends "base.html" %}
2+
{% load i18n %}
3+
4+
{% block content %}
5+
{% for civi in civis %}
6+
<div class="civi-card white" data-id="">
7+
<div class="civi-header-account white">
8+
<div class="civi-title-outer">
9+
<div class="civi-type gray-text">{{ civi.c_type }}</div>
10+
<div class="civi-title">{{ civi.title }}</div>
11+
</div>
12+
</div>
13+
<div class="civi-body">
14+
<div class="civi-body-inner">{{ civi.body }}</div>
15+
</div>
16+
</div>
17+
{% empty %}
18+
<div class="section no-state">
19+
<div class="container">
20+
<div class="section">
21+
<div class="center title-lato text">No activity</div>
22+
</div>
23+
</div>
24+
</div>
25+
{% endfor %}
26+
27+
28+
{% endblock content %}

project/accounts/tests/test_views.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.contrib.auth import views as auth_views
55
from django.test import TestCase
66
from django.urls import resolve, reverse
7+
from threads.models import Civi, Thread
78

89

910
class BaseTestCase(TestCase):
@@ -215,3 +216,39 @@ def test_get_user_profile(self):
215216
self.assertEqual(response.status_code, 200)
216217
self.assertContains(response, self.user.username)
217218
self.assertTemplateUsed(response, "account.html")
219+
220+
221+
class UserProfileCivis(BaseTestCase):
222+
"""A class to test user profiles following view"""
223+
224+
def setUp(self) -> None:
225+
super(UserProfileCivis, self).setUp()
226+
227+
self.user2 = get_user_model().objects.create_user(
228+
username="newuser2", email="test2@test2.com", password="password123"
229+
)
230+
231+
thread = Thread(
232+
author=self.user2, title="test thread", summary="this is a test thread"
233+
)
234+
thread.save()
235+
civi = Civi(author=self.user, thread=thread, title="test civi title")
236+
civi.save()
237+
238+
def test_get_my_civis(self):
239+
"""Whether user_profile function works as expected"""
240+
241+
self.client.login(username="newuser", password="password123")
242+
response = self.client.get(reverse("user-civis", args=["newuser"]))
243+
self.assertEqual(response.status_code, 200)
244+
self.assertContains(response, "test civi title")
245+
self.assertTemplateUsed(response, "user_civis.html")
246+
247+
def test_get_other_civis(self):
248+
"""Whether user_profile function works as expected"""
249+
250+
self.client.login(username="newuser2", password="password123")
251+
response = self.client.get(reverse("user-civis", args=["newuser"]))
252+
self.assertEqual(response.status_code, 200)
253+
self.assertContains(response, "test civi title")
254+
self.assertTemplateUsed(response, "user_civis.html")

project/accounts/urls.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
SettingsView,
1111
ProfileFollowing,
1212
UserProfileView,
13+
UserCivis,
1314
expunge_user,
1415
)
1516
from django.contrib.auth import views as auth_views
@@ -43,6 +44,11 @@
4344
ProfileFollowing.as_view(),
4445
name="profile-following",
4546
),
47+
path(
48+
"profile/<str:username>/civis/",
49+
UserCivis.as_view(),
50+
name="user-civis",
51+
),
4652
path(
4753
"accounts/password_reset/",
4854
PasswordResetView.as_view(),

project/accounts/views.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,24 @@ def get(self, request, username=None):
206206
)
207207

208208

209+
class UserCivis(LoginRequiredMixin, View):
210+
"""
211+
A view that shows list of civis
212+
that profile with given username created
213+
"""
214+
215+
def get(self, request, username=None):
216+
profile = get_object_or_404(Profile, user__username=username)
217+
user = profile.user
218+
civis = user.civis.all()
219+
220+
return TemplateResponse(
221+
request,
222+
"user_civis.html",
223+
{"profile": profile, "civis": civis},
224+
)
225+
226+
209227
@login_required
210228
def expunge_user(request):
211229
"""

0 commit comments

Comments
 (0)