Fakultas Ilmu Komputer UI

Commit f819a62f authored by Muhammad Indra Ramadhan's avatar Muhammad Indra Ramadhan
Browse files

Merge branch '1706028695-87' into 'master'

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

Closes #87

See merge request !55
parents 2b1f0814 4515ac27
Pipeline #59456 passed with stages
in 14 minutes and 15 seconds
...@@ -99,6 +99,11 @@ class Materi(models.Model): ...@@ -99,6 +99,11 @@ class Materi(models.Model):
def like_count(self): def like_count(self):
count = Like.objects.filter(materi=self).count() count = Like.objects.filter(materi=self).count()
return count return count
@property
def comment_count(self):
count = Comment.objects.filter(materi=self).count()
return count
@property @property
def is_like(self): def is_like(self):
......
...@@ -268,6 +268,7 @@ ...@@ -268,6 +268,7 @@
</div> </div>
{% if materi_data.status == "APPROVE" %} {% if materi_data.status == "APPROVE" %}
<div id="komentar" class="container-fluid comments-wrapper p-0"> <div id="komentar" class="container-fluid comments-wrapper p-0">
<h1>Komentar ({{ materi_data.comment_count }})</h1>
{% if is_authenticated %} {% if is_authenticated %}
<div class="add-comments col col-8 bg-white shadow-sm rounded p-3 mb-3"> <div class="add-comments col col-8 bg-white shadow-sm rounded p-3 mb-3">
<form method="POST"> <form method="POST">
......
...@@ -439,6 +439,20 @@ class DetailMateriTest(TestCase): ...@@ -439,6 +439,20 @@ class DetailMateriTest(TestCase):
comment_like_counter = LikeComment.objects.filter(comment=comment, session_id=session_id).count() comment_like_counter = LikeComment.objects.filter(comment=comment, session_id=session_id).count()
self.assertEqual(comment_like_counter, 0) 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): def test_detail_materi_contains_form_comment(self):
self.client.login(**self.contributor_credential) self.client.login(**self.contributor_credential)
response = self.client.get(self.url) 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