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
40ea5598
Commit
40ea5598
authored
Oct 16, 2020
by
Mutia Rahmatun Husna
Browse files
[
#39
]Material: Like/Favorite (User View)
parent
9eb16994
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
app/models.py
View file @
40ea5598
...
...
@@ -100,6 +100,12 @@ class Materi(models.Model):
count
=
Like
.
objects
.
filter
(
materi
=
self
).
count
()
return
count
@
property
def
is_like
(
self
):
like
=
False
if
Like
.
objects
.
filter
(
materi
=
self
).
exists
():
like
=
True
class
Comment
(
models
.
Model
):
username
=
models
.
CharField
(
max_length
=
100
)
...
...
app/templates/app/includes/sidebar.html
View file @
40ea5598
...
...
@@ -31,6 +31,11 @@
<span>
Statisik Materi
</span>
</a>
</li>
<li
class=
"nav-item"
>
<a
class=
"nav-link"
href=
"{% url 'favorite' %}"
>
<span>
Favorite Materi
</span>
</a>
</li>
<li
class=
"nav-item"
>
<a
class=
"nav-link"
href=
"{% url 'posts' %}"
>
<span>
Materi Diunggah
</span></a>
...
...
app/templates/user_favorite_materi.html
0 → 100644
View file @
40ea5598
{% extends 'app/base_dashboard.html' %}
{% load static %}
{% block title %}
<title>
Materi Favorite | Digipus
</title>
{% endblock %}
{% block stylesheets %}
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'app/css/user_uploaded_posts.css' %}"
/>
{% endblock %}
{% block content %}
<div
style=
"padding: 1rem 0"
id=
"like"
>
{% if materi %}
{% for _, mat in materi.items %}
<div
id=
"mat-{{ mat.data.id }}"
>
<div
class=
"posts-space-between-container bg-white rounded shadow"
style=
"margin: 0.5rem 2rem; padding: 1rem;"
>
<div
id=
"posts-user-profile"
>
{% if mat.data.cover %}
<img
id=
"posts-img"
src=
"{{ post.data.cover.url }}"
alt=
"profile-picture"
/>
{% else %}
</div
style="background-color:
grey;
width:
100px;
height:
100px;"
>
{% endif %}
<div
id=
"posts-info"
>
<span><a
class=
"ml-auto p-1 link"
style=
"text-align: left; font-size: 2rem;"
href=
"{% url 'detail-materi' post.data.id %}"
>
{{ mat.data.title }}
</a></span>
<span
style=
"font-size: 0.75rem; padding-left: 0.3rem;"
>
{{ mat.data.date_created }}
</span>
</div>
</div>
<div
class=
"posts-vertically-centered ml-auto pr-4"
>
<span
id=
"post-like-count-{{post.data.id}}"
>
{{ mat.data.like_count }}
</span>
<span>
Like
</span>
</div>
<div
class=
"posts-vertically-centered"
>
<span>
{{ mat.comments|length }}
</span>
<span>
Komentar
</span>
</div>
</div>
{% for comment in mat.comments %}
<div
id=
"post-{{ post.data.id }}-comment-{{ comment.id }}"
>
<div
id=
"posts-comment-info"
class=
"bg-white rounded shadow"
>
<img
id=
"posts-profile-picture"
src=
"{{ comment.user.profile_picture.url }}"
alt=
"profile-picture"
width=
"40px"
height=
"40px"
style=
"margin: 18px"
/>
<div
style=
"display: flex; align-items: center;"
>
<div
style=
"display: flex; flex-direction: column;"
>
<span
style=
"font-size: 0.9rem;"
><strong>
{{ comment.user.name }}
</strong>
- {{ comment.timestamp }}
</span>
{{ comment.comment }}
</div>
</div>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
{% else %}
<div
class=
"text-center h5"
>
Anda belum memiliki materi yang disukai
</div>
{% endif %}
</div>
{% endblock %}
app/tests.py
View file @
40ea5598
This diff is collapsed.
Click to expand it.
app/urls.py
View file @
40ea5598
...
...
@@ -5,7 +5,7 @@ from app.views import (DashboardKontributorView, ProfilKontributorView,
SuksesLoginAdminView
,
SuksesLoginKontributorView
,
DownloadHistoryView
,
SuntingProfilView
,
UploadMateriHTML
,
UploadMateriView
,
UploadMateriExcelView
,
ProfilAdminView
,
PostsView
,
SuntingProfilAdminView
,
ReqMateriView
,
KatalogPerKontributorView
,
PasswordChangeViews
,
password_success
)
ReqMateriView
,
KatalogPerKontributorView
,
MateriFavorite
,
PasswordChangeViews
,
password_success
)
from
django.contrib.auth
import
views
as
auth_views
urlpatterns
=
[
path
(
""
,
views
.
DaftarKatalog
.
as_view
(),
name
=
"daftar_katalog"
),
...
...
@@ -37,6 +37,7 @@ urlpatterns = [
name
=
"katalog-per-kontributor"
),
path
(
"materi/rate/"
,
views
.
add_rating_materi
,
name
=
"rate-materi"
),
path
(
"materi/<int:pk>/save-to-gdrive/"
,
views
.
save_to_gdrive
,
name
=
"save-to-gdrive"
),
path
(
"favorite/"
,
MateriFavorite
.
as_view
(),
name
=
"favorite"
),
path
(
"change-password/"
,
PasswordChangeViews
.
as_view
(
template_name
=
'change-password.html'
)),
path
(
"password_success/"
,
views
.
password_success
,
name
=
"password_success"
),
]
app/views.py
View file @
40ea5598
...
...
@@ -701,10 +701,38 @@ def save_to_gdrive(request, pk):
return
HttpResponseRedirect
(
reverse
(
'detail-materi'
,
kwargs
=
{
'pk'
:
pk
}))
class
MateriFavorite
(
TemplateView
):
template_name
=
"user_favorite_materi.html"
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
if
not
request
.
user
.
is_authenticated
:
raise
PermissionDenied
(
request
)
return
super
(
MateriFavorite
,
self
).
dispatch
(
request
,
*
args
,
**
kwargs
)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
context
=
super
().
get_context_data
(
**
kwargs
)
user
=
self
.
request
.
user
materi
=
Materi
.
objects
.
filter
(
like
=
True
)
likes_data
=
{
mat
.
id
:
{
"data"
:
mat
,
"comments"
:
[]
}
for
mat
in
materi
}
comments
=
Comment
.
objects
\
.
filter
(
materi__id__in
=
likes_data
.
keys
())
\
.
order_by
(
"-timestamp"
)
for
comment
in
comments
:
likes_data
[
comment
.
materi
.
id
][
"comments"
].
append
(
comment
)
context
[
"user"
]
=
user
context
[
"likes"
]
=
likes_data
return
self
.
render_to_response
(
context
=
context
)
class
PasswordChangeViews
(
PasswordChangeView
):
from_class
=
PasswordChangeForm
success_url
=
reverse_lazy
(
'password_success'
)
def
password_success
(
request
):
return
render
(
request
,
'password_success.html'
,
{})
\ No newline at end of file
return
render
(
request
,
'password_success.html'
,
{})
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