Fakultas Ilmu Komputer UI

Commit 4515ac27 authored by Muhammad Indra Ramadhan's avatar Muhammad Indra Ramadhan
Browse files

[#87] Material Statistic: Comment Count (User View)

parent 2b1f0814
......@@ -99,6 +99,11 @@ class Materi(models.Model):
def like_count(self):
count = Like.objects.filter(materi=self).count()
return count
@property
def comment_count(self):
count = Comment.objects.filter(materi=self).count()
return count
@property
def is_like(self):
......
......@@ -268,6 +268,7 @@
</div>
{% if materi_data.status == "APPROVE" %}
<div id="komentar" class="container-fluid comments-wrapper p-0">
<h1>Komentar ({{ materi_data.comment_count }})</h1>
{% if is_authenticated %}
<div class="add-comments col col-8 bg-white shadow-sm rounded p-3 mb-3">
<form method="POST">
......
......@@ -439,6 +439,20 @@ class DetailMateriTest(TestCase):
comment_like_counter = LikeComment.objects.filter(comment=comment, session_id=session_id).count()
self.assertEqual(comment_like_counter, 0)
def test_detail_materi_contains_comment_count(self):
url = self.url
self.client.login(**self.contributor_credential)
response = self.client.get(url)
self.assertContains(response, "Komentar (0)")
self.client.post(
url, {"comment": "This is new comment by Contributor"})
self.client.post(
url, {"comment": "This is new comment by Contributor"})
response = self.client.get(url)
self.assertContains(response, "Komentar (2)")
def test_detail_materi_contains_form_comment(self):
self.client.login(**self.contributor_credential)
response = self.client.get(self.url)
......
Supports Markdown
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