Fakultas Ilmu Komputer UI

Commit 0874eafa authored by Saul Andre's avatar Saul Andre
Browse files

[REFACTOR] Finishing comments page

parent 45399b5d
......@@ -7,3 +7,18 @@
border-radius: 50%;
margin-right: 10px;
}
.comment {
border-bottom: 1px solid #d4d4d4;
}
.comment .user .profile {
display: inline-block;
height: 25px;
width: 25px;
background-color: #bbb;
border-radius: 50%;
margin-right: 10px;
}
.comment .text {
padding-left: 20px;
}
......@@ -73,7 +73,9 @@
>
</li>
<li class="nav-item">
<a class="nav-link" href="#"> <span>Komentar</span></a>
<a class="nav-link" href="{% url 'comments' user.id %}">
<span>Komentar</span></a
>
</li>
</ul>
<!-- End of Sidebar -->
......@@ -157,7 +159,7 @@
<!-- Begin Page Content -->
<div class="container-fluid">
<div
class="row user shadow p-3 mb-5 bg-white rounded bd-highlight"
class="row user shadow p-3 mb-3 bg-white rounded bd-highlight"
>
<div
class="user-profile d-flex flex-row align-items-center flex-grow-1 bd-highligh"
......@@ -188,6 +190,49 @@
<p class="m-0">Komentar</p>
</div>
</div>
<div
class="row comments shadow p-3 mb-3 bg-white rounded d-flex flex-column bd-highlight"
>
<p class="h4 mb-3 bd-highlight">Komentar</p>
<div class="comments">
{% for comment in comments %}
<div
class="comment shadow-sm p-3 mb-1 bg-white rounded bd-highlight"
>
<div
class="d-flex bd-highlight mb-3 align-items-center user"
>
{% if comment.user != Null %}
<img
class="profile"
src="{{ comment.user.profile_picture.url }}"
alt="profile-picture"
/>
{% else %}
<span
style="background-color: #{{comment.profile}}"
class="profile p-1 bd-highligh"
></span>
{% endif %}
<p class="p-1 bd-highligh m-0">
<b>{{comment.user.name}}</b>
</p>
{% if user.is_admin %}
<a
class="ml-auto p-1 bd-highlight close"
href="{% url 'delete-comment' materi_data.id comment.id %}"
>
<span aria-hidden="true"
>&times;</span
>
</a>
{% endif %}
</div>
<p class="text">{{comment.comment}}</p>
</div>
{% endfor %}
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
......
......@@ -59,7 +59,7 @@
<span>Statisik Materi</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<a class="nav-link" href="{% url 'comments' user.id %}">
<span>Komentar</span></a>
</li>
......
......@@ -62,6 +62,10 @@
<span>Statisik Materi</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'comments' user.id %}">
<span>Komentar</span></a>
</li>
</ul>
<!-- End of Sidebar -->
......
......@@ -181,9 +181,13 @@ class ViewCommentsTest(TestCase):
Materi(title="Materi 1", author="Agas", uploader=self.contributor,
publisher="Kelas SC", descriptions="Deskripsi Materi 1",
status="APPROVE", cover=self.cover, content=self.content).save()
Materi(title="Materi 2", author="Matt", uploader=self.mattDamon,
publisher="Kelas SC", descriptions="Deskripsi Materi 2",
status="APPROVE", cover=self.cover, content=self.content).save()
self.materi1 = Materi.objects.first()
self.commentByKontributor = Comment(username='saul', materi=self.materi1, user=self.contributor)
self.commentByMatt = Comment(username='saul', comment="this is Matt Damon", materi=self.materi1, user=self.mattDamon)
self.materi2 = Materi.objects.get(uploader=self.mattDamon)
self.commentByKontributor = Comment.objects.create(username='saul', comment="this is contributor comment", materi=self.materi1, user=self.contributor)
self.commentByMatt = Comment.objects.create(username='saul', comment="this is Matt Damon", materi=self.materi2, user=self.mattDamon)
self.url = '/kontributor/' + str(self.contributor.id) + '/comments/'
def test_comments_url_exist(self):
......@@ -205,14 +209,20 @@ class ViewCommentsTest(TestCase):
def test_comments_page_render_comments(self):
self.client.login(**self.contributor_credential)
response = self.client.get(self.url)
self.assertContains(response, "comments")
self.assertContains(response, "this is contributor comment")
self.assertNotContains(response, 'bukan comment')
def test_comments_page_only_render_specific_user_comments(self):
self.client.login(**self.contributor_credential)
response = self.client.get(self.url)
self.assertContains(response, "comments")
self.assertContains(response, "this is contributor comment")
self.assertNotContains(response, "this is Matt Damon")
def test_comments_page_only_for_specific_contributor(self):
self.client.login(**self.matt_damon_credential)
response = self.client.get(self.url)
self.assertEqual(response.status_code, 403)
self.assertNotEqual(response.status_code, 200)
class TemplateLoaderTest(TestCase):
def test_template_loader_url_exist(self):
......
......@@ -406,7 +406,7 @@ class CommentsView(TemplateView):
template_name = "comments.html"
def dispatch(self, request, *args, **kwargs):
if not request.user.is_contributor:
if not request.user.pk == kwargs["pk_user"] :
raise PermissionDenied(request)
return super(CommentsView, self).dispatch(request, *args, **kwargs)
......@@ -415,11 +415,12 @@ class CommentsView(TemplateView):
user = get_object_or_404(User, pk=kwargs["pk_user"])
users_materi = Materi.objects.filter(uploader=user)
numb_of_comments = 0
qset_comments = Comment.objects.none()
for materi in users_materi:
materi_comments = Comment.objects.filter(materi=materi).count()
numb_of_comments += materi_comments
users_comments = Comment.objects.filter(user=user)
context["comments"] = users_comments
qset_comments |= Comment.objects.filter(materi=materi)
context['comments'] = qset_comments.order_by('-timestamp')
context["numb_of_comments"] = numb_of_comments
context["numb_of_materi"] = users_materi.count()
return context
......
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