Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
DIGIPUS
Commits
0874eafa
Commit
0874eafa
authored
May 20, 2020
by
Saul Andre
Browse files
[REFACTOR] Finishing comments page
parent
45399b5d
Changes
6
Hide whitespace changes
Inline
Side-by-side
app/static/app/css/comments.css
View file @
0874eafa
...
...
@@ -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
;
}
app/templates/comments.html
View file @
0874eafa
...
...
@@ -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"
>
×
</span
>
</a>
{% endif %}
</div>
<p
class=
"text"
>
{{comment.comment}}
</p>
</div>
{% endfor %}
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
...
...
app/templates/dashboard.html
View file @
0874eafa
...
...
@@ -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>
...
...
app/templates/unggah.html
View file @
0874eafa
...
...
@@ -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 -->
...
...
app/tests.py
View file @
0874eafa
...
...
@@ -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
,
"comment
s
"
)
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
,
"comment
s
"
)
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
):
...
...
app/views.py
View file @
0874eafa
...
...
@@ -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
=
us
er
)
context
[
"
comments
"
]
=
u
se
rs
_comments
qset
_comments
|
=
Comment
.
objects
.
filter
(
materi
=
mat
er
i
)
context
[
'
comments
'
]
=
q
se
t
_comments
.
order_by
(
'-timestamp'
)
context
[
"numb_of_comments"
]
=
numb_of_comments
context
[
"numb_of_materi"
]
=
users_materi
.
count
()
return
context
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment