Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
DIGIPUS
Commits
8e7e67a9
Commit
8e7e67a9
authored
Nov 01, 2020
by
Selvy Fitriani
Browse files
Merge branch '1706039446/110' into 'master'
[
#110
] Guest Book For Non Registered User See merge request
!112
parents
defcd506
60a1898e
Pipeline
#60185
passed with stages
in 26 minutes and 38 seconds
Changes
10
Pipelines
1
Expand all
Show whitespace changes
Inline
Side-by-side
app/forms.py
View file @
8e7e67a9
from
django
import
forms
from
app.models
import
Materi
,
Category
,
RatingContributor
from
app.models
import
Materi
,
Category
,
RatingContributor
,
GuestBook
from
authentication.models
import
User
import
datetime
def
year_choices
():
return
[(
r
,
r
)
for
r
in
range
(
2000
,
datetime
.
date
.
today
().
year
+
1
)]
return
[(
r
,
r
)
for
r
in
range
(
2000
,
datetime
.
date
.
today
().
year
+
1
)]
class
UploadMateriForm
(
forms
.
ModelForm
):
categories
=
forms
.
ModelMultipleChoiceField
(
queryset
=
Category
.
objects
.
all
(),
widget
=
forms
.
CheckboxSelectMultiple
(
attrs
=
{
'style'
:
'column-count:2'
}),
required
=
True
)
release_year
=
forms
.
TypedChoiceField
(
coerce
=
int
,
choices
=
year_choices
,
initial
=
datetime
.
date
.
today
().
year
)
yt_video_id
=
forms
.
CharField
(
label
=
"Youtube Video Id"
,
\
categories
=
forms
.
ModelMultipleChoiceField
(
queryset
=
Category
.
objects
.
all
(
),
widget
=
forms
.
CheckboxSelectMultiple
(
attrs
=
{
'style'
:
'column-count:2'
}),
required
=
True
)
release_year
=
forms
.
TypedChoiceField
(
coerce
=
int
,
choices
=
year_choices
,
initial
=
datetime
.
date
.
today
().
year
)
yt_video_id
=
forms
.
CharField
(
label
=
"Youtube Video Id"
,
help_text
=
"This is not required.<br>
\
Please insert only Youtube link videos! Take a note for the video id!<br>
\
Example : https://www.youtube.com/watch?v=DkJ-50GLi2I <br> has video id DkJ-50GLi2I"
,
required
=
False
)
...
...
@@ -29,14 +33,13 @@ class UploadMateriForm(forms.ModelForm):
field
.
widget
.
attrs
[
"class"
]
=
"form-control"
field
.
widget
.
attrs
[
"placeholder"
]
=
field
.
initial
field
.
initial
=
""
self
.
fields
[
'categories'
].
widget
.
attrs
.
update
({
'class'
:
"native"
})
self
.
fields
[
'categories'
].
widget
.
attrs
.
update
({
'class'
:
"native"
})
class
SuntingProfilForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
User
fields
=
[
"email"
,
"name"
,
"instansi"
,
"nik"
,
"alamat"
,
"nomor_telpon"
,
fields
=
[
"email"
,
"name"
,
"instansi"
,
"nik"
,
"alamat"
,
"nomor_telpon"
,
"profile_picture"
,
"linkedin"
,
"facebook"
,
"twitter"
,
"instagram"
,
"biography"
,
"is_subscribing_to_material_comments"
]
...
...
@@ -51,7 +54,6 @@ class SuntingProfilForm(forms.ModelForm):
key
=
list
(
self
.
errors
)[
0
]
self
.
fields
[
key
].
widget
.
attrs
[
"autofocus"
]
=
""
self
.
fields
[
"email"
].
widget
.
attrs
[
"readonly"
]
=
True
...
...
@@ -61,14 +63,43 @@ class RatingContributorForm(forms.ModelForm):
fields
=
[
'score'
,
'user'
,
'contributor'
]
SCORE_CHOICE
=
(
(
''
,
'Select score'
),
(
'1'
,
'1'
),
# First one is the value of select option and second is the displayed value in option
# First one is the value of select option and second is the displayed value in option
(
'1'
,
'1'
),
(
'2'
,
'2'
),
(
'3'
,
'3'
),
(
'4'
,
'4'
),
(
'5'
,
'5'
),
)
widgets
=
{
'score'
:
forms
.
Select
(
choices
=
SCORE_CHOICE
,
attrs
=
{
'class'
:
'form-control'
,
'id'
:
'form-rating'
},),
'score'
:
forms
.
Select
(
choices
=
SCORE_CHOICE
,
attrs
=
{
'class'
:
'form-control'
,
'id'
:
'form-rating'
},),
'user'
:
forms
.
HiddenInput
(),
'contributor'
:
forms
.
HiddenInput
()
}
class
GuestBookForm
(
forms
.
models
.
ModelForm
):
class
Meta
:
model
=
GuestBook
fields
=
[
'name'
,
'job'
,
'gender'
]
gender_choices
=
(
(
'Male'
,
'Male'
),
(
'Female'
,
'Female'
)
)
widgets
=
{
'name'
:
forms
.
fields
.
TextInput
(
attrs
=
{
'placeholder'
:
'Input your name'
,
'class'
:
'form-control input-lg'
}),
'job'
:
forms
.
fields
.
TextInput
(
attrs
=
{
'placeholder'
:
'Input your job'
,
'class'
:
'form-control input-lg'
}),
'gender'
:
forms
.
fields
.
Select
(
choices
=
gender_choices
,
attrs
=
{
'class'
:
'form-control input-lg'
})
}
error_messages
=
{
'name'
:
{
'required'
:
'Name is required'
},
'job'
:
{
'required'
:
'Job is required'
},
'gender'
:
{
'required'
:
'Gender is required'
}
}
app/migrations/0029_guestbook.py
0 → 100644
View file @
8e7e67a9
# Generated by Django 3.1 on 2020-10-31 18:19
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'app'
,
'0028_adminnotification'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'GuestBook'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'name'
,
models
.
TextField
(
default
=
''
)),
(
'job'
,
models
.
TextField
(
default
=
''
)),
(
'gender'
,
models
.
CharField
(
default
=
'Male'
,
max_length
=
6
)),
],
),
]
app/migrations/00
29
_merge_20201101_021
7
.py
→
app/migrations/00
30
_merge_20201101_0
6
21.py
View file @
8e7e67a9
# Generated by Django 3.1 on 2020-10-31
19:17
# Generated by Django 3.1 on 2020-10-31
23:21
from
django.db
import
migrations
...
...
@@ -6,8 +6,8 @@ from django.db import migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'app'
,
'0029_guestbook'
),
(
'app'
,
'0028_notifikasikontributor'
),
(
'app'
,
'0028_adminnotification'
),
]
operations
=
[
...
...
app/models.py
View file @
8e7e67a9
...
...
@@ -26,9 +26,11 @@ def get_random_color():
color
=
"%06x"
%
random
.
randint
(
0
,
0xFFFFFF
)
return
color
def
current_year
():
return
datetime
.
date
.
today
().
year
class
Category
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
20
)
description
=
models
.
TextField
(
blank
=
False
,
default
=
""
)
...
...
@@ -75,6 +77,7 @@ class SoftDeletionQuerySet(models.query.QuerySet):
def
delete
(
self
):
return
super
(
SoftDeletionQuerySet
,
self
).
update
(
deleted_at
=
timezone
.
now
())
class
SoftDeleteModel
(
models
.
Model
):
deleted_at
=
models
.
DateTimeField
(
blank
=
True
,
null
=
True
)
...
...
@@ -87,6 +90,7 @@ class SoftDeleteModel(models.Model):
self
.
deleted_at
=
timezone
.
now
()
self
.
save
()
class
Materi
(
SoftDeleteModel
):
cover
=
models
.
ImageField
()
content
=
models
.
FileField
()
...
...
@@ -97,7 +101,8 @@ class Materi(SoftDeleteModel):
release_year
=
models
.
IntegerField
(
default
=
current_year
)
pages
=
models
.
IntegerField
(
default
=
0
)
descriptions
=
models
.
TextField
(
default
=
"Deskripsi"
)
status
=
models
.
CharField
(
max_length
=
30
,
choices
=
VERIFICATION_STATUS
,
default
=
VERIFICATION_STATUS
[
0
][
0
])
status
=
models
.
CharField
(
max_length
=
30
,
choices
=
VERIFICATION_STATUS
,
default
=
VERIFICATION_STATUS
[
0
][
0
])
categories
=
models
.
ManyToManyField
(
Category
)
date_created
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
date_modified
=
models
.
DateTimeField
(
auto_now
=
True
)
...
...
@@ -117,7 +122,8 @@ class Materi(SoftDeleteModel):
def
save
(
self
,
*
args
,
**
kwargs
):
super
().
save
(
*
args
,
**
kwargs
)
search_index
=
{
field
:
weight
for
(
field
,
weight
)
in
Materi
.
SEARCH_INDEX
}
search_index
=
{
field
:
weight
for
(
field
,
weight
)
in
Materi
.
SEARCH_INDEX
}
if
"update_fields"
in
kwargs
:
is_search_index_updated
=
bool
(
set
(
search_index
.
keys
())
&
set
(
kwargs
[
"update_fields"
])
...
...
@@ -127,9 +133,11 @@ class Materi(SoftDeleteModel):
self
.
_search_vector
=
None
for
field
,
weight
in
search_index
.
items
():
if
self
.
_search_vector
is
None
:
self
.
_search_vector
=
search
.
SearchVector
(
field
,
weight
=
weight
)
self
.
_search_vector
=
search
.
SearchVector
(
field
,
weight
=
weight
)
else
:
self
.
_search_vector
+=
search
.
SearchVector
(
field
,
weight
=
weight
)
self
.
_search_vector
+=
search
.
SearchVector
(
field
,
weight
=
weight
)
self
.
save
(
update_fields
=
[
"_search_vector"
])
...
...
@@ -197,7 +205,8 @@ class Comment(models.Model):
profile
=
models
.
CharField
(
max_length
=
100
,
default
=
get_random_color
)
comment
=
models
.
CharField
(
max_length
=
240
,
default
=
"comments"
)
materi
=
models
.
ForeignKey
(
Materi
,
models
.
SET_NULL
,
null
=
True
)
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
SET_NULL
,
blank
=
True
,
null
=
True
)
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
SET_NULL
,
blank
=
True
,
null
=
True
)
timestamp
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
def
__str__
(
self
):
...
...
@@ -213,12 +222,14 @@ class Comment(models.Model):
count
=
DislikeComment
.
objects
.
filter
(
comment
=
self
).
count
()
return
count
class
Review
(
models
.
Model
):
username
=
models
.
CharField
(
max_length
=
100
)
profile
=
models
.
CharField
(
max_length
=
100
,
default
=
get_random_color
)
review
=
models
.
TextField
(
default
=
"review"
)
materi
=
models
.
ForeignKey
(
Materi
,
models
.
SET_NULL
,
null
=
True
)
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
SET_NULL
,
blank
=
True
,
null
=
True
)
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
SET_NULL
,
blank
=
True
,
null
=
True
)
timestamp
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
def
__str__
(
self
):
...
...
@@ -247,6 +258,7 @@ class ReqMaterial(models.Model):
title
=
models
.
CharField
(
max_length
=
100
)
timestamp
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
class
SubmitVisitor
(
models
.
Model
):
user_id
=
models
.
CharField
(
max_length
=
50
)
email
=
models
.
CharField
(
max_length
=
50
)
...
...
@@ -255,13 +267,16 @@ class SubmitVisitor(models.Model):
class
ViewStatistics
(
models
.
Model
):
materi
=
models
.
ForeignKey
(
Materi
,
models
.
SET_NULL
,
null
=
True
,
related_name
=
"baca"
)
materi
=
models
.
ForeignKey
(
Materi
,
models
.
SET_NULL
,
null
=
True
,
related_name
=
"baca"
)
timestamp
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
class
DownloadStatistics
(
models
.
Model
):
materi
=
models
.
ForeignKey
(
Materi
,
models
.
SET_NULL
,
null
=
True
,
related_name
=
"unduh"
)
downloader
=
models
.
ForeignKey
(
User
,
models
.
SET_NULL
,
blank
=
True
,
null
=
True
,
related_name
=
"riwayat_unduh"
)
materi
=
models
.
ForeignKey
(
Materi
,
models
.
SET_NULL
,
null
=
True
,
related_name
=
"unduh"
)
downloader
=
models
.
ForeignKey
(
User
,
models
.
SET_NULL
,
blank
=
True
,
null
=
True
,
related_name
=
"riwayat_unduh"
)
timestamp
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
...
...
@@ -302,9 +317,12 @@ class Rating(models.Model):
class
RatingContributor
(
models
.
Model
):
timestamp
=
models
.
DateTimeField
(
auto_now
=
True
)
score
=
models
.
PositiveIntegerField
(
validators
=
[
MinValueValidator
(
1
),
MaxValueValidator
(
5
)])
contributor
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
CASCADE
,
related_name
=
'contributor'
)
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
CASCADE
,
related_name
=
'user'
)
score
=
models
.
PositiveIntegerField
(
validators
=
[
MinValueValidator
(
1
),
MaxValueValidator
(
5
)])
contributor
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
CASCADE
,
related_name
=
'contributor'
)
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
CASCADE
,
related_name
=
'user'
)
def
save
(
self
,
force_insert
=
False
,
force_update
=
False
,
using
=
None
,
update_fields
=
None
):
if
1
<=
self
.
score
<=
5
:
...
...
@@ -317,12 +335,21 @@ class RatingContributor(models.Model):
class
LaporanMateri
(
models
.
Model
):
materi
=
models
.
ForeignKey
(
Materi
,
on_delete
=
models
.
CASCADE
,
max_length
=
120
)
materi
=
models
.
ForeignKey
(
Materi
,
on_delete
=
models
.
CASCADE
,
max_length
=
120
)
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
CASCADE
)
laporan
=
models
.
TextField
(
validators
=
[
MinValueValidator
(
30
),
MaxValueValidator
(
120
)],
default
=
""
)
laporan
=
models
.
TextField
(
validators
=
[
MinValueValidator
(
30
),
MaxValueValidator
(
120
)],
default
=
""
)
timestamp
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
is_rejected
=
models
.
BooleanField
(
default
=
False
)
class
GuestBook
(
models
.
Model
):
name
=
models
.
TextField
(
default
=
''
)
job
=
models
.
TextField
(
default
=
''
)
gender
=
models
.
CharField
(
max_length
=
6
,
default
=
"Male"
)
class
ReadLater
(
models
.
Model
):
materi
=
models
.
ForeignKey
(
Materi
,
on_delete
=
models
.
CASCADE
)
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
CASCADE
)
...
...
@@ -331,13 +358,16 @@ class ReadLater(models.Model):
class
Meta
:
unique_together
=
[
"materi"
,
"user"
]
class
NotifikasiKontributor
(
models
.
Model
):
materi
=
models
.
ForeignKey
(
Materi
,
on_delete
=
models
.
CASCADE
,
max_length
=
120
)
materi
=
models
.
ForeignKey
(
Materi
,
on_delete
=
models
.
CASCADE
,
max_length
=
120
)
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
CASCADE
)
feedback
=
models
.
CharField
(
max_length
=
20
,
default
=
""
)
def
__str__
(
self
):
return
"Status: {}"
.
format
(
self
.
feedback
)
class
AdminNotification
(
models
.
Model
):
materi
=
models
.
ForeignKey
(
Materi
,
on_delete
=
models
.
CASCADE
)
app/static/app/css/guest_book.css
0 → 100644
View file @
8e7e67a9
.form-style-6
{
font
:
95%
Arial
,
Helvetica
,
sans-serif
;
max-width
:
500px
;
margin
:
25px
auto
;
padding
:
16px
;
background
:
#F7F7F7
;
align-content
:
center
;
justify-content
:
center
;
}
.form-style-6
h1
{
background
:
#43D1AF
;
padding
:
20px
0
;
font-size
:
140%
;
font-weight
:
300
;
text-align
:
center
;
color
:
#fff
;
margin
:
-16px
-16px
16px
-16px
;
}
.form-style-6
input
[
type
=
"text"
],
.form-style-6
select
{
-webkit-transition
:
all
0.30s
ease-in-out
;
-moz-transition
:
all
0.30s
ease-in-out
;
-ms-transition
:
all
0.30s
ease-in-out
;
-o-transition
:
all
0.30s
ease-in-out
;
outline
:
none
;
box-sizing
:
border-box
;
-webkit-box-sizing
:
border-box
;
-moz-box-sizing
:
border-box
;
width
:
100%
;
background
:
#fff
;
margin-bottom
:
4%
;
border
:
1px
solid
#ccc
;
color
:
#555
;
font
:
95%
Arial
,
Helvetica
,
sans-serif
;
}
.form-style-6
input
[
type
=
"text"
]
:focus
,
.form-style-6
textarea
:focus
,
.form-style-6
select
:focus
{
box-shadow
:
0
0
5px
#43D1AF
;
padding
:
3%
;
border
:
1px
solid
#43D1AF
;
}
.form-style-6
button
[
type
=
"submit"
]
{
box-sizing
:
border-box
;
-webkit-box-sizing
:
border-box
;
-moz-box-sizing
:
border-box
;
width
:
100%
;
padding
:
3%
;
background
:
#1da1f2
;
border-bottom
:
2px
solid
#1da1f2
;
border-top-style
:
none
;
border-right-style
:
none
;
border-left-style
:
none
;
color
:
#fff
;
}
.form-style-6
input
[
type
=
"submit"
]
:hover
,
.form-style-6
input
[
type
=
"button"
]
:hover
{
background
:
#2EBC99
;
}
\ No newline at end of file
app/templates/guest_book.html
0 → 100644
View file @
8e7e67a9
{% extends 'base.html' %}
{% load static %}
{% block title %}Digipus Home{% endblock %}
{% block header %}
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
Digipus Home
</title>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, inital-scale=1"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'app/css/guest_book.css' %}"
>
{% endblock header %}
</head>
<!-- Page Content -->
{% block content %}
<div
class=
"form-group form-style-6"
id=
"myForm"
>
<form
method=
"POST"
>
<h3
style=
"text-align: center;"
>
Buku Tamu Non Anggota
</h3>
{% csrf_token %}
{{form}}
<button
type=
"submit"
class=
"btn btn-success"
>
Submit
</button>
</form>
</div>
{% endblock %}
</html>
\ No newline at end of file
app/tests.py
View file @
8e7e67a9
This diff is collapsed.
Click to expand it.
app/urls.py
View file @
8e7e67a9
...
...
@@ -5,8 +5,7 @@ from app import views
from
app.views
import
(
DashboardKontributorView
,
ProfilView
,
StatisticsView
,
SuksesLoginAdminView
,
SuksesLoginKontributorView
,
DownloadHistoryView
,
SuntingProfilView
,
UploadMateriHTML
,
UploadMateriView
,
UploadMateriExcelView
,
PostsView
,
ReqMateriView
,
KatalogPerKontributorView
,
MateriFavorite
,
PasswordChangeViews
,
password_success
,
SubmitVisitorView
,
ReadLaterView
,
MostContributor
)
ReqMateriView
,
KatalogPerKontributorView
,
MateriFavorite
,
PasswordChangeViews
,
password_success
,
SubmitVisitorView
,
GuestBookView
,
ReadLaterView
,
MostContributor
)
urlpatterns
=
[
...
...
@@ -18,13 +17,16 @@ urlpatterns = [
path
(
"review/delete/<int:pk_materi>/<int:pk_review>"
,
views
.
delete_review
,
name
=
"delete-review"
),
path
(
"comment/like/"
,
views
.
toggle_like_comment
,
name
=
"comment-like-toggle"
),
path
(
"comment/dislike/"
,
views
.
toggle_dislike_comment
,
name
=
"comment-dislike-toggle"
),
path
(
"comment/dislike/"
,
views
.
toggle_dislike_comment
,
name
=
"comment-dislike-toggle"
),
path
(
"materi/<int:pk>/delete"
,
views
.
delete_materi
,
name
=
"detele-materi"
),
path
(
"materi/<int:pk>/unduh"
,
views
.
download_materi
,
name
=
"download-materi"
),
path
(
"materi/<int:pk>/view"
,
views
.
view_materi
,
name
=
"view-materi"
),
path
(
"dashboard/"
,
DashboardKontributorView
.
as_view
(),
name
=
"dashboard"
),
path
(
"download-history/"
,
DownloadHistoryView
.
as_view
(),
name
=
"download-history"
),
path
(
"revisi/materi/<int:pk>/"
,
views
.
RevisiMateriView
.
as_view
(),
name
=
"revisi"
),
path
(
"download-history/"
,
DownloadHistoryView
.
as_view
(),
name
=
"download-history"
),
path
(
"revisi/materi/<int:pk>/"
,
views
.
RevisiMateriView
.
as_view
(),
name
=
"revisi"
),
path
(
"unggah/"
,
UploadMateriView
.
as_view
(),
name
=
"unggah"
),
path
(
"unggah_excel/"
,
UploadMateriExcelView
.
as_view
(),
name
=
"unggah_excel"
),
path
(
"profil/"
,
ProfilView
.
as_view
(),
name
=
"profil"
),
...
...
@@ -38,9 +40,11 @@ urlpatterns = [
path
(
"profil/<str:email>/"
,
KatalogPerKontributorView
.
as_view
(),
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
(
"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
(
"change-password/"
,
PasswordChangeViews
.
as_view
(
template_name
=
'change-password.html'
)),
path
(
"password_success/"
,
views
.
password_success
,
name
=
"password_success"
),
path
(
"given-rating/"
,
views
.
see_given_rating
,
name
=
"see_given_rating"
),
path
(
"submit-visitor/"
,
SubmitVisitorView
.
as_view
(),
name
=
"submit-visitor"
),
...
...
@@ -48,16 +52,21 @@ urlpatterns = [
path
(
"baca-nanti-toggle/"
,
views
.
toggle_readlater
,
name
=
"toggle-read-later"
),
path
(
"stats/"
,
StatisticsView
.
as_view
(),
name
=
"stats"
),
path
(
"reset_password/"
,
auth_views
.
PasswordResetView
.
as_view
(
template_name
=
"password_reset.html"
),
auth_views
.
PasswordResetView
.
as_view
(
template_name
=
"password_reset.html"
),
name
=
"reset_password"
),
path
(
"reset_password_sent/"
,
auth_views
.
PasswordResetDoneView
.
as_view
(
template_name
=
"password_reset_sent.html"
),
auth_views
.
PasswordResetDoneView
.
as_view
(
template_name
=
"password_reset_sent.html"
),
name
=
"password_reset_done"
),
path
(
"reset/<uidb64>/<token>/"
,
auth_views
.
PasswordResetConfirmView
.
as_view
(
template_name
=
"password_reset_form.html"
),
auth_views
.
PasswordResetConfirmView
.
as_view
(
template_name
=
"password_reset_form.html"
),
name
=
"password_reset_confirm"
),
path
(
"reset_password_complete/"
,
auth_views
.
PasswordResetCompleteView
.
as_view
(
template_name
=
"password_reset_done.html"
),
auth_views
.
PasswordResetCompleteView
.
as_view
(
template_name
=
"password_reset_done.html"
),
name
=
"password_reset_complete"
),
path
(
"most-contributor/"
,
MostContributor
.
as_view
(),
name
=
"most-contributor"
)
path
(
"most-contributor/"
,
MostContributor
.
as_view
(),
name
=
"most-contributor"
),
path
(
"guest-book/"
,
GuestBookView
.
as_view
(),
name
=
"guest-book"
)
]
app/views.py
View file @
8e7e67a9
...
...
@@ -24,7 +24,7 @@ from django.urls import reverse_lazy
from
django.views
import
defaults
from
django.views.generic
import
TemplateView
from
app.forms
import
SuntingProfilForm
,
UploadMateriForm
,
RatingContributorForm
from
app.forms
import
SuntingProfilForm
,
UploadMateriForm
,
RatingContributorForm
,
GuestBookForm
from
app.models
import
(
Category
,
Comment
,
...
...
@@ -34,6 +34,7 @@ from app.models import (
ReqMaterial
,
Rating
,
RatingContributor
,
SubmitVisitor
,
GuestBook
,
ReadLater
,
NotifikasiKontributor
,
AdminNotification
...
...
@@ -51,6 +52,7 @@ UNGGAH_URL = "/unggah/"
UNGGAH_EXCEL_URL
=
"/unggah_excel/"
LOGIN_URL
=
"/login/"
def
permission_denied
(
request
,
exception
,
template_name
=
"error_403.html"
):
return
defaults
.
permission_denied
(
request
,
exception
,
template_name
)
...
...
@@ -66,11 +68,12 @@ class DaftarKatalog(TemplateView):
context
=
self
.
get_context_data
(
**
kwargs
)
context
[
"kategori_list"
]
=
Category
.
objects
.
all
()
lst_materi
=
Materi
.
objects
.
filter
(
status
=
"APPROVE"
).
order_by
(
"date_modified"
)
lst_materi
=
Materi
.
objects
.
filter
(
status
=
"APPROVE"
).
order_by
(
"date_modified"
)
url
=
""
lst_materi
,
url
=
DafterKatalogService
.
apply_options
(
lst_materi
,
request
,
url
)
lst_materi
,
url
=
DafterKatalogService
.
apply_options
(
lst_materi
,
request
,
url
)
context
[
"materi_list"
]
=
lst_materi
paginator
=
Paginator
(
context
[
"materi_list"
],
15
)
...
...
@@ -105,14 +108,16 @@ class KatalogPerKontributorView(TemplateView):
contributor
=
context
[
"contributor"
]
context
[
"form_rating"
]
=
RatingContributorForm
(
initial
=
{
"contributor"
:
contributor
,
"user"
:
request
.
user
"user"
:
request
.
user
})
context
[
"avg_rating"
]
=
User
.
objects
.
filter
(
email
=
kwargs
[
"email"
])
\
.
annotate
(
avg_rating
=
Avg
(
"contributor__score"
))[
0
]
context
[
"count_rating"
]
=
RatingContributor
.
objects
.
filter
(
contributor
=
contributor
).
count
()
context
[
"count_rating"
]
=
RatingContributor
.
objects
.
filter
(
contributor
=
contributor
).
count
()
if
request
.
user
.
is_authenticated
:
has_rated
=
RatingContributor
.
objects
.
filter
(
user
=
request
.
user
,
contributor
=
contributor
).
exists
()
has_rated
=
RatingContributor
.
objects
.
filter
(
user
=
request
.
user
,
contributor
=
contributor
).
exists
()
context
[
"has_rated"
]
=
has_rated
return
self
.
render_to_response
(
context
=
context
)
...
...
@@ -148,6 +153,7 @@ class KatalogPerKontributorView(TemplateView):
return
redirect
(
"katalog-per-kontributor"
,
email
=
kwargs
[
"email"
])
class
DetailMateri
(
TemplateView
):
template_name
=
"app/detail_materi.html"
...
...
@@ -156,17 +162,21 @@ class DetailMateri(TemplateView):
if
not
self
.
request
.
session
or
not
self
.
request
.
session
.
session_key
:
self
.
request
.
session
.
save
()
materi
=
get_object_or_404
(
Materi
,
pk
=
kwargs
[
"pk"
])
DetailMateriService
.
init_context_data
(
context
,
materi
,
self
.
request
.
session
)
DetailMateriService
.
init_context_data
(
context
,
materi
,
self
.
request
.
session
)
published_date
=
DetailMateriService
.
set_published_date
(
materi
)
DetailMateriService
.
init_citation_and_materi_rating
(
context
,
materi
,
published_date
,
self
.
request
)
DetailMateriService
.
init_citation_and_materi_rating
(
context
,
materi
,
published_date
,
self
.
request
)
DetailMateriService
.
init_materi_download_count
(
context
,
materi
)
if
self
.
request
.
user
.
is_authenticated
:
materi_rating
=
Rating
.
objects
.
filter
(
materi
=
materi
,
user
=
self
.
request
.
user
).
first
()
materi_rating
=
Rating
.
objects
.
filter
(
materi
=
materi
,
user
=
self
.
request
.
user
).
first
()
if
materi_rating
is
not
None
:
context
[
'materi_rating_score'
]
=
materi_rating
.
score
materi_read_later
=
ReadLater
.
objects
.
filter
(
materi
=
materi
,
user
=
self
.
request
.
user
).
first
()
materi_read_later
=
ReadLater
.
objects
.
filter
(
materi
=
materi
,
user
=
self
.
request
.
user
).
first
()
if
materi_read_later
is
not
None
:
context
[
'is_in_read_later_list'
]
=
True
else
:
...
...
@@ -176,12 +186,14 @@ class DetailMateri(TemplateView):
return
context
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
context
=
self
.
get_context_data
(
**
kwargs
)
query_set_for_comment
=
Comment
.
objects
.
filter
(
materi
=
context
[
"materi_data"
])
query_set_for_review
=
Review
.
objects
.
filter
(
materi
=
context
[
"materi_data"
])
has_disliked
,
has_liked
=
DetailMateriService
.
find_comment_like_dislike
(
query_set_for_comment
,
self
.
request
.
session
)
query_set_for_comment
=
Comment
.
objects
.
filter
(
materi
=
context
[
"materi_data"
])
query_set_for_review
=
Review
.
objects
.
filter
(
materi
=
context
[
"materi_data"
])
has_disliked
,
has_liked
=
DetailMateriService
.
find_comment_like_dislike
(
query_set_for_comment
,
self
.
request
.
session
)
context
[
"comment_data"
]
=
query_set_for_comment
context
[
"review_data"
]
=
query_set_for_review
context
[
"has_liked_comment"
]
=
has_liked
...
...
@@ -191,28 +203,28 @@ class DetailMateri(TemplateView):
opened_notif
.
delete
()
return
self
.
render_to_response
(
context
=
context
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
comment_text
=
request
.
POST
.
get
(
"comment"
,
None
)
review_text
=
request
.
POST
.
get
(
"review"
,
None
)
report_text
=
request
.
POST
.
get
(
"report"
,
None
)
if
((
comment_text
==
None
or
comment_text
==
""
)
and
\
(
review_text
==
None
or
review_text
==
""
)
and
\
if
((
comment_text
==
None
or
comment_text
==
""
)
and
(
review_text
==
None
or
review_text
==
""
)
and
(
report_text
==
None
or
report_text
==
""
)):
context
=
self
.
get_context_data
(
*
args
,
**
kwargs
)
context
[
"error_message"
]
=
"Anda belum menuliskan komentar"
context
[
"materi_data"
]
=
get_object_or_404
(
Materi
,
pk
=
kwargs
[
"pk"
])