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
9f170065
Commit
9f170065
authored
Nov 01, 2020
by
Sayid Abyan Rizal Shiddiq
Browse files
[
#60
] Material: Notify Admin for Approval when a Contributor Uploads New Material
parent
4e11f0a2
Changes
8
Hide whitespace changes
Inline
Side-by-side
administration/views.py
View file @
9f170065
...
...
@@ -9,7 +9,7 @@ from django.utils import timezone
from
administration.models
import
VerificationReport
,
VerificationSetting
,
DeletionHistory
from
administration.forms
import
CategoryForm
,
VerificationSettingForm
,
RegistrasiAdminForm
,
PeriodForm
,
EditAdminStatusForm
,
EditKontributorStatusForm
from
administration.services
import
StatisticService
,
DetailVerificationService
,
LaporanMateriService
from
app.models
import
Category
,
Materi
,
ViewStatistics
,
DownloadStatistics
,
Comment
,
Like
,
LaporanMateri
from
app.models
import
Category
,
Materi
,
ViewStatistics
,
DownloadStatistics
,
Comment
,
Like
,
LaporanMateri
,
AdminNotification
from
authentication.models
import
User
from
datetime
import
datetime
...
...
@@ -87,6 +87,8 @@ class DetailVerificationView(TemplateView):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
context
=
self
.
get_context_data
(
**
kwargs
)
if
(
request
.
user
.
is_admin
):
AdminNotification
.
objects
.
filter
(
materi
=
context
[
"materi_data"
]).
delete
()
return
self
.
render_to_response
(
context
=
context
)
...
...
app/admin.py
View file @
9f170065
from
django.contrib
import
admin
from
.models
import
AdminNotification
# Register your models here.
admin
.
site
.
register
(
AdminNotification
)
\ No newline at end of file
app/migrations/0028_adminnotification.py
0 → 100644
View file @
9f170065
# Generated by Django 3.1 on 2020-10-31 14:46
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'app'
,
'0027_readlater'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'AdminNotification'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'materi'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'app.materi'
)),
],
),
]
app/models.py
View file @
9f170065
...
...
@@ -329,4 +329,7 @@ class ReadLater(models.Model):
timestamp
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
class
Meta
:
unique_together
=
[
"materi"
,
"user"
]
\ No newline at end of file
unique_together
=
[
"materi"
,
"user"
]
class
AdminNotification
(
models
.
Model
):
materi
=
models
.
ForeignKey
(
Materi
,
on_delete
=
models
.
CASCADE
)
app/services.py
View file @
9f170065
...
...
@@ -19,7 +19,7 @@ from pydrive.drive import GoogleDrive
from
app.forms
import
SuntingProfilForm
from
app.models
import
(
Category
,
Comment
,
DislikeComment
,
DownloadStatistics
,
Like
,
LikeComment
,
Materi
,
Rating
,
ReadLater
,
ViewStatistics
)
ViewStatistics
,
AdminNotification
)
from
app.utils.fileManagementUtil
import
(
get_random_filename
,
remove_image_exifdata
)
...
...
@@ -353,6 +353,7 @@ class UploadMateriService:
@
staticmethod
def
upload_materi
(
form
,
materi
):
materi
.
save
()
AdminNotification
.
objects
.
create
(
materi
=
materi
)
kateg
=
form
.
cleaned_data
[
"categories"
]
for
i
in
kateg
:
materi
.
categories
.
add
(
i
)
...
...
@@ -401,6 +402,7 @@ class UploadMateriService:
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
default_cover
))
materi
.
save
()
AdminNotification
.
objects
.
create
(
materi
=
materi
)
for
c
in
excel
[
"Categories"
][
i
].
split
(
","
):
materi
.
categories
.
add
(
categories
.
get
(
name
=
c
))
...
...
@@ -426,6 +428,7 @@ class RevisiMateriService:
materi
.
uploader
=
request
.
user
materi
.
status
=
"REVISION"
materi
.
save
()
AdminNotification
.
objects
.
create
(
materi
=
materi
)
kateg
=
form
.
cleaned_data
[
"categories"
]
for
i
in
kateg
:
materi
.
categories
.
add
(
i
)
...
...
app/templates/sukses_admin.html
View file @
9f170065
...
...
@@ -47,6 +47,23 @@
<span>
<a
class=
"btn btn-primary main-content"
href=
"/administration/"
>
Halaman Administrasi
</a>
</span>
<div
class=
"profile-margin"
></div>
{% if notifications%}
<h3>
Materi Baru
</h3>
{% endif %}
<table
class=
"table main-content"
>
<tbody>
{% for i in notifications %}
<tr>
<td>
<a
href=
"/administration/detail-verif/{{i.materi.id}}"
>
Materi {{i.materi.title}} butuh verifikasi
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
...
...
app/tests.py
View file @
9f170065
...
...
@@ -45,7 +45,7 @@ from app.views import UploadMateriHTML, add_rating_materi
from
.models
import
(
Category
,
Comment
,
DislikeComment
,
DownloadStatistics
,
Like
,
LikeComment
,
Materi
,
Rating
,
RatingContributor
,
ReadLater
,
ReqMaterial
,
Review
,
ViewStatistics
)
ReadLater
,
ReqMaterial
,
Review
,
ViewStatistics
,
AdminNotification
)
from
.services
import
DetailMateriService
from
.views
import
(
DaftarKatalog
,
DashboardKontributorView
,
DetailMateri
,
KatalogPerKontributorView
,
MateriFavorite
,
...
...
@@ -3947,7 +3947,6 @@ class MateriStatsTest(TestCase):
jobj
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
len
(
jobj
[
'labels'
]),
6
)
class
UploadMateriTest
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
Client
()
...
...
@@ -3985,4 +3984,52 @@ class UploadMateriTest(TestCase):
self
.
client
.
post
(
"/unggah/"
,
data
=
data
)
self
.
assertEqual
(
Materi
.
objects
.
count
(),
1
)
\ No newline at end of file
self
.
assertEqual
(
Materi
.
objects
.
count
(),
1
)
class
AdminNotificationTest
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
Client
()
self
.
contributor_credential
=
{
"email"
:
"kontributor@gov.id"
,
"password"
:
id_generator
()
}
self
.
admin_credential
=
{
"email"
:
"admin@gov.id"
,
"password"
:
id_generator
()
}
self
.
public_credential
=
{
"email"
:
"public@gov.id"
,
"password"
:
id_generator
()
}
self
.
kontributor
=
User
.
objects
.
create_contributor
(
**
self
.
contributor_credential
)
self
.
admin
=
User
.
objects
.
create_admin
(
**
self
.
admin_credential
)
self
.
public
=
User
.
objects
.
create_user
(
**
self
.
public_credential
)
self
.
setUpImage
()
self
.
content
=
SimpleUploadedFile
(
"ExampleFile221.pdf"
,
b
"Test file"
)
self
.
category
=
Category
.
objects
.
create
(
id
=
"1"
,
name
=
"medis"
,
description
=
"kategori medis"
)
@
override_settings
(
MEDIA_ROOT
=
tempfile
.
gettempdir
())
def
setUpImage
(
self
):
self
.
cover
=
InMemoryUploadedFile
(
BytesIO
(
base64
.
b64decode
(
TEST_IMAGE
)),
field_name
=
'tempfile'
,
name
=
'tempfile.png'
,
content_type
=
'image/png'
,
size
=
len
(
TEST_IMAGE
),
charset
=
'utf-8'
,
)
def
test_notification_admin
(
self
):
self
.
client
.
login
(
**
self
.
contributor_credential
)
self
.
client
.
post
(
"/unggah/"
,
data
=
{
"title"
:
"Materi 1"
,
"author"
:
"Agas"
,
"publisher"
:
"Kelas SC"
,
"release_year"
:
"2000"
,
"descriptions"
:
"Deskripsi Materi 1"
,
'categories'
:
"1"
,
"cover"
:
self
.
cover
,
"content"
:
self
.
content
,
"yt_video_id"
:
"jNwz4L9MGVY"
}
)
materi
=
Materi
.
objects
.
get
(
title
=
"Materi 1"
)
self
.
assertTrue
(
AdminNotification
.
objects
.
get
(
materi
=
materi
.
id
))
app/views.py
View file @
9f170065
...
...
@@ -34,7 +34,8 @@ from app.models import (
ReqMaterial
,
Rating
,
RatingContributor
,
SubmitVisitor
,
ReadLater
ReadLater
,
AdminNotification
)
from
authentication.models
import
User
from
.services
import
DafterKatalogService
,
DetailMateriService
,
LikeDislikeService
,
MateriFieldValidationHelperService
,
\
...
...
@@ -593,6 +594,10 @@ class SuksesLoginKontributorView(TemplateView):
class
SuksesLoginAdminView
(
TemplateView
):
template_name
=
"sukses_admin.html"
def
getAdminNotification
(
self
):
notifications
=
AdminNotification
.
objects
.
all
()
return
notifications
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
if
not
request
.
user
.
is_admin
:
raise
PermissionDenied
(
request
)
...
...
@@ -608,8 +613,10 @@ class SuksesLoginAdminView(TemplateView):
current_user
=
self
.
request
.
user
context
[
"user"
]
=
current_user
return
self
.
render_to_response
(
context
)
notifications
=
self
.
getAdminNotification
()
context
[
"notifications"
]
=
notifications
return
self
.
render_to_response
(
context
)
class
PostsView
(
TemplateView
):
...
...
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