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
79a25474
Commit
79a25474
authored
Jun 02, 2020
by
Saul Andre
Committed by
igor lestin sianipar
Jun 02, 2020
Browse files
Pbi edit kategori
parent
fc30f474
Changes
7
Hide whitespace changes
Inline
Side-by-side
administration/forms.py
View file @
79a25474
...
...
@@ -21,7 +21,11 @@ class CategoryForm(forms.ModelForm):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
CategoryForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
for
field_name
,
field
in
self
.
fields
.
items
():
field
.
widget
.
attrs
[
"class"
]
=
"widget-control"
field
.
widget
.
attrs
[
"class"
]
=
"form-control mb-2 p-1 col col-md-8 col-lg-6 rounded-lg rounded-sm"
if
field_name
==
"description"
:
field
.
widget
.
attrs
[
"placeholder"
]
=
"Deskripsi"
else
:
field
.
widget
.
attrs
[
"placeholder"
]
=
"Nama Kategori"
class
VerificationSettingForm
(
forms
.
ModelForm
):
...
...
@@ -32,10 +36,12 @@ class VerificationSettingForm(forms.ModelForm):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
VerificationSettingForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
for
field_name
,
field
in
self
.
fields
.
items
():
field
.
widget
.
attrs
[
"class"
]
=
"widget-control mb-2 col col-md-8 col-lg-6 rounded-lg rounded-sm"
field
.
widget
.
attrs
[
"placeholder"
]
=
field_name
field
.
widget
.
attrs
[
"class"
]
=
"form-control mb-2 p-1 col col-md-8 col-lg-6 rounded-lg rounded-sm"
if
field_name
==
"description"
:
field
.
widget
.
attrs
[
"rows"
]
=
"3"
field
.
widget
.
attrs
[
"placeholder"
]
=
"Deskripsi"
else
:
field
.
widget
.
attrs
[
"placeholder"
]
=
"Judul Verifikasi"
class
RegistrasiAdminForm
(
forms
.
ModelForm
):
...
...
administration/templates/edit_
verifikasi
.html
→
administration/templates/edit_
settings
.html
View file @
79a25474
...
...
@@ -12,7 +12,7 @@
<meta
name=
"description"
content=
""
/>
<meta
name=
"author"
content=
""
/>
<title>
Dasbor - {{ page_title }}
</title>
<title>
Dasbor -
Edit
{{ page_title }}
</title>
<!-- Custom fonts for this template -->
<link
...
...
@@ -204,19 +204,16 @@
<div
class=
"card shadow mb-4"
>
<div
class=
"card-header py-3"
>
<h6
class=
"m-0 font-weight-bold text-primary"
>
{{ page_title }}
Baru
Edit
{{ page_title }}
</h6>
</div>
<div
class=
"card-body"
>
<form
method=
"POST"
>
{% csrf_token %}
<p
class=
"h5 mb-3 border-bottom"
>
Edit Point Verifikasi
</p>
<div
class=
"judul d-flex align-items-baseline"
>
{{ form.title }}
{{ form.title }}
{{ form.name }}
</div>
<div
class=
"description d-flex align-items-baseline"
...
...
@@ -225,8 +222,7 @@
</div>
<div
class=
""
>
<button
class=
"primary_btn save"
style=
"border-radius:20px;"
class=
"btn-sm btn-primary rounded p-12"
type=
"submit"
>
<i
...
...
administration/templates/settings.html
View file @
79a25474
...
...
@@ -12,7 +12,7 @@
<meta
name=
"description"
content=
""
/>
<meta
name=
"author"
content=
""
/>
<title>
Dasbor - {{ page_title }}
</title>
<title>
Dasbor -
Pengaturan
{{ page_title }}
</title>
<!-- Custom fonts for this template -->
<link
...
...
@@ -204,7 +204,7 @@
<div
class=
"card shadow mb-4"
>
<div
class=
"card-header py-3"
>
<h6
class=
"m-0 font-weight-bold text-primary"
>
{{ page_title }}
Baru
Tambah
{{ page_title }}
</h6>
</div>
<div
class=
"card-body"
>
...
...
@@ -217,6 +217,7 @@
class=
"judul d-flex align-items-baseline"
>
{{ form.title }}
{{ form.name }}
</div>
<div
class=
"description d-flex align-items-baseline"
...
...
@@ -225,8 +226,7 @@
</div>
<div
class=
""
>
<button
class=
"primary_btn save"
style=
"border-radius:20px;"
class=
"btn-sm btn-primary rounded p-12"
type=
"submit"
>
<i
...
...
@@ -247,11 +247,11 @@
class=
"m-0 font-weight-bold text-primary"
id=
"titleTabel"
>
{{ page_title }}
List
{{ page_title }}
</h6>
</div>
<div
class=
"card-body"
>
<div
class=
"alert"
>
<div
class=
"alert
m-0 p-0 text-center
"
>
{% if messages %}
{% for message in messages %}
<div
class=
"alert alert-success"
role=
"alert"
>
...
...
@@ -276,15 +276,24 @@
<tbody>
{% for item in items %}
<tr>
<th>
{{item.title}}
</th>
<th>
{{item.title}}
{{item.name}}
</th>
<th>
{{item.description}}
</th>
<th
class=
"verif-buttons"
>
{% if item.name is None %}
<a
href=
"/administration/setting/verification/{{ item.id }}/edit"
class=
"btn-primary btn-sm"
role=
"button"
>
Edit
</a
>
>
{% else %}
<a
href=
"/administration/setting/category/{{ item.id }}/edit"
class=
"btn-primary btn-sm"
role=
"button"
>
Edit
</a
>
{% endif %}
<a
class=
"btn-sm btn-danger text-white"
role=
"button"
data-toggle=
"modal"
data-target=
"#hapus-modal-{{item.id}}"
>
Hapus
</a>
...
...
@@ -292,24 +301,37 @@
<div
class=
"modal-dialog"
role=
"document"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<h5
class=
"modal-title"
id=
"exampleModalLabel"
>
Hapus
Point Verifikasi
</h5>
<h5
class=
"modal-title"
id=
"exampleModalLabel"
>
Hapus
{{ page_title }}
</h5>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
>
<span
aria-hidden=
"true"
>
×
</span>
</button>
</div>
<div
class=
"modal-body"
>
<p>
Anda akan menghapus point verifikasi {{ item.title }}. Data tersebut akan hilang, dan tidak dapat dikembalikan. Untuk melanjutkan ketik:
</p>
<p
class=
"bg-danger text-white p-1"
>
{{ item.title }}
</p>
<p>
Anda akan menghapus
<span
style=
"text-transform: lowercase"
>
{{page_title}}
</span>
<span
class=
"bg-danger pr-1 pl-1 text-white"
style=
"text-transform: lowercase"
>
{{ item.title }}{{item.name}}
</span>
. Data tersebut akan hilang, dan tidak dapat dikembalikan. Untuk melanjutkan ketik:
</p>
<p
class=
"bg-danger text-white p-1"
>
{{ item.title }} {{item.name}}
</p>
</div>
<form/>
{% csrf_token %}
{% if item.name is None %}
<div
class=
"form-group pl-3 pr-3"
>
<input
name=
"{{ item.title }}"
class=
"form-control"
id=
"{{ item.id }}"
required
pattern=
"{{item.title}}"
oninput=
"checkValue(this)"
>
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-primary"
data-dismiss=
"modal"
>
Batal
</button>
<a
type=
"submit"
id=
"btn-hapus-{{item.id}}"
href=
"/administration/delete-verification/{{ item.id }}"
class=
"btn btn-danger btn-hapus-{{item.id}} disabled"
>
Hapus
</a>
<input
name=
"{{ item.title }}"
class=
"form-control"
id=
"{{ item.id }}"
required
pattern=
"{{item.title}}"
oninput=
"checkValue(this)"
>
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-primary"
data-dismiss=
"modal"
>
Batal
</button>
<a
type=
"submit"
id=
"btn-hapus-{{item.id}}"
href=
"/administration/delete-verification/{{ item.id }}"
class=
"btn btn-danger btn-hapus-{{item.id}} disabled"
>
Hapus
</a>
</div>
{% else %}
<div
class=
"form-group pl-3 pr-3"
>
<input
name=
"{{ item.name }}"
class=
"form-control"
id=
"{{ item.id }}"
required
pattern=
"{{item.name}}"
oninput=
"checkValue(this)"
>
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-primary"
data-dismiss=
"modal"
>
Batal
</button>
<a
type=
"submit"
id=
"btn-hapus-{{item.id}}"
href=
"/administration/delete-category/{{ item.id }}"
class=
"btn btn-danger btn-hapus-{{item.id}} disabled"
>
Hapus
</a>
</div>
{% endif %}
</form>
</div>
</div>
...
...
administration/tests.py
View file @
79a25474
...
...
@@ -800,7 +800,7 @@ class RegistrasiAdminTest(TestCase):
class
EditVerificationTest
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
Client
()
self
.
template_name
=
"edit_
verifikasi
.html"
self
.
template_name
=
"edit_
settings
.html"
self
.
admin_credential
=
{
"email"
:
"admin@gov.id"
,
"password"
:
id_generator
()
...
...
@@ -845,6 +845,12 @@ class EditVerificationTest(TestCase):
self
.
client
.
get
(
"/administration/delete-verification/"
+
str
(
deleteObject
.
id
)
+
"/"
)
self
.
assertEqual
(
models
.
VerificationSetting
.
objects
.
all
().
filter
(
title
=
"deletelah"
).
count
(),
0
)
def
test_delete_verification_data_by_anonymous
(
self
):
self
.
client
.
logout
()
deleteObject
=
models
.
VerificationSetting
.
objects
.
create
(
title
=
"deletelah"
,
description
=
"delete test"
)
response
=
self
.
client
.
get
(
"/administration/delete-verification/"
+
str
(
deleteObject
.
id
)
+
"/"
)
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_edit_verification
(
self
):
self
.
client
.
login
(
**
self
.
admin_credential
)
...
...
@@ -871,4 +877,87 @@ class EditVerificationTest(TestCase):
self
.
url
,
{
"description"
:
"Deskripsi Kriteria 1"
},
follow
=
True
)
self
.
assertTemplateUsed
(
response
,
self
.
template_name
)
self
.
assertContains
(
response
,
"Edit Point Verifikasi"
)
\ No newline at end of file
self
.
assertContains
(
response
,
"Edit Verifikasi Materi"
)
class
EditCategoryTest
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
Client
()
self
.
template_name
=
"edit_settings.html"
self
.
admin_credential
=
{
"email"
:
"admin@gov.id"
,
"password"
:
id_generator
()
}
self
.
admin
=
get_user_model
().
objects
.
create_user
(
**
self
.
admin_credential
,
name
=
"Admin"
,
is_admin
=
True
)
Category
(
name
=
'test'
,
description
=
"desc test"
).
save
()
self
.
category
=
Category
.
objects
.
first
()
self
.
url
=
"/administration/setting/category/"
+
str
(
self
.
category
.
id
)
+
"/edit"
def
test_edit_category_admin_access
(
self
):
self
.
client
.
login
(
**
self
.
admin_credential
)
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertNotEqual
(
response
.
status_code
,
404
)
def
test_edit_category_anonymous_access
(
self
):
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertNotEqual
(
response
.
status_code
,
200
)
def
test_edit_category_using_correct_template
(
self
):
self
.
client
.
login
(
**
self
.
admin_credential
)
found
=
resolve
(
self
.
url
)
self
.
assertEqual
(
found
.
func
.
__name__
,
views
.
EditCategoryView
.
__name__
)
def
test_edit_category_item_content
(
self
):
self
.
client
.
login
(
**
self
.
admin_credential
)
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertContains
(
response
,
self
.
category
.
name
)
self
.
assertContains
(
response
,
self
.
category
.
description
)
def
test_post_edit_category_item_content
(
self
):
self
.
client
.
login
(
**
self
.
admin_credential
)
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertContains
(
response
,
self
.
category
.
name
)
self
.
assertContains
(
response
,
self
.
category
.
description
)
def
test_delete_category_data
(
self
):
self
.
client
.
login
(
**
self
.
admin_credential
)
deleteObject
=
Category
.
objects
.
create
(
name
=
"deletelah"
,
description
=
"delete test"
)
self
.
client
.
get
(
"/administration/delete-category/"
+
str
(
deleteObject
.
id
)
+
"/"
)
self
.
assertEqual
(
Category
.
objects
.
all
().
filter
(
name
=
"deletelah"
).
count
(),
0
)
def
test_delete_category_data_by_anonymous
(
self
):
self
.
client
.
logout
()
deleteObject
=
Category
.
objects
.
create
(
name
=
"deletelah"
,
description
=
"delete test"
)
response
=
self
.
client
.
get
(
"/administration/delete-category/"
+
str
(
deleteObject
.
id
)
+
"/"
)
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_edit_category
(
self
):
self
.
client
.
login
(
**
self
.
admin_credential
)
response
=
self
.
client
.
get
(
self
.
url
)
bs
=
BeautifulSoup
(
response
.
rendered_content
,
features
=
"html.parser"
)
el
=
bs
.
find
(
"input"
,
{
"id"
:
"id_name"
})[
"value"
]
self
.
assertEqual
(
self
.
category
.
name
,
el
)
response
=
self
.
client
.
post
(
self
.
url
,
{
"name"
:
"Kategori 1"
,
"description"
:
"Deskripsi Kategori 1"
},
follow
=
True
)
bs
=
BeautifulSoup
(
response
.
rendered_content
,
features
=
"html.parser"
)
el
=
bs
.
find
(
"table"
,
{
"id"
:
"dataTable"
}).
get_text
()
self
.
assertIn
(
'Kategori 1'
,
el
)
self
.
assertIn
(
'Deskripsi Kategori 1'
,
el
)
def
test_edit_category_missing_attribute
(
self
):
# Login
self
.
client
.
login
(
**
self
.
admin_credential
)
response
=
self
.
client
.
post
(
self
.
url
,
{
"description"
:
"Deskripsi Kategori 1"
},
follow
=
True
)
self
.
assertTemplateUsed
(
response
,
self
.
template_name
)
self
.
assertContains
(
response
,
"Edit Kategori Materi"
)
administration/urls.py
View file @
79a25474
from
django.urls
import
path
from
administration.views
import
VerificationView
,
DetailVerificationView
,
VerificationSettingView
,
CategorySettingView
,
KelolaKontributorView
,
ProfileContributorAdminView
,
ProfileAdminAdministrationView
,
KelolaAdminView
,
RegistrasiAdminView
,
EditVerificationView
,
delete_admin
,
delete_contributor
,
delete_verification
,
StatisticsView
,
StatisticApiView
from
administration.views
import
(
VerificationView
,
DetailVerificationView
,
VerificationSettingView
,
CategorySettingView
,
KelolaKontributorView
,
ProfileContributorAdminView
,
ProfileAdminAdministrationView
,
KelolaAdminView
,
RegistrasiAdminView
,
EditVerificationView
,
EditCategoryView
,
StatisticsView
,
StatisticApiView
,
delete_admin
,
delete_contributor
,
delete_verification
,
delete_category
)
app_name
=
"administration"
...
...
@@ -12,6 +16,9 @@ urlpatterns = [
path
(
"setting/verification/<int:pk>/edit"
,
EditVerificationView
.
as_view
(),
name
=
"edit-verification"
),
path
(
"setting/category/"
,
CategorySettingView
.
as_view
()),
path
(
"setting/category/<int:pk>/edit"
,
EditCategoryView
.
as_view
(),
name
=
"edit-category"
),
path
(
"delete-category/<int:pk_category>/"
,
delete_category
),
path
(
"kelola-kontributor/"
,
KelolaKontributorView
.
as_view
()),
path
(
"profil/<int:pk>/"
,
ProfileContributorAdminView
.
as_view
()),
path
(
"statistics/"
,
StatisticsView
.
as_view
(),
name
=
"halaman-statistik"
),
...
...
administration/views.py
View file @
79a25474
...
...
@@ -108,7 +108,7 @@ class VerificationSettingView(TemplateView):
self
).
get_context_data
(
**
kwargs
)
context
[
"items"
]
=
VerificationSetting
.
objects
.
filter
(
archived
=
False
)
context
[
"page_title"
]
=
"
Pengaturan
Point Verifikasi Materi"
context
[
"page_title"
]
=
"Point Verifikasi Materi"
return
context
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -138,7 +138,7 @@ class CategorySettingView(TemplateView):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
CategorySettingView
,
self
).
get_context_data
(
**
kwargs
)
context
[
"items"
]
=
Category
.
objects
.
all
()
context
[
"page_title"
]
=
"
Pengaturan
Kategori Materi"
context
[
"page_title"
]
=
"Kategori Materi"
return
context
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -292,7 +292,7 @@ class RegistrasiAdminView(TemplateView):
class
EditVerificationView
(
TemplateView
):
template_name
=
"edit_
verifikasi
.html"
template_name
=
"edit_
settings
.html"
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
if
not
request
.
user
.
is_authenticated
or
not
request
.
user
.
is_admin
:
...
...
@@ -301,7 +301,7 @@ class EditVerificationView(TemplateView):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
EditVerificationView
,
self
).
get_context_data
(
**
kwargs
)
context
[
"page_title"
]
=
"
Edit
Verifikasi"
context
[
"page_title"
]
=
"Verifikasi
Materi
"
context
[
"item"
]
=
VerificationSetting
.
objects
.
get
(
id
=
kwargs
[
"pk"
])
context
[
"form"
]
=
VerificationSettingForm
(
instance
=
context
[
"item"
])
return
context
...
...
@@ -323,18 +323,68 @@ class EditVerificationView(TemplateView):
return
self
.
render_to_response
(
context
)
class
EditCategoryView
(
TemplateView
):
template_name
=
"edit_settings.html"
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
if
not
request
.
user
.
is_authenticated
or
not
request
.
user
.
is_admin
:
raise
PermissionDenied
(
request
)
return
super
(
EditCategoryView
,
self
).
dispatch
(
request
,
*
args
,
**
kwargs
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
EditCategoryView
,
self
).
get_context_data
(
**
kwargs
)
context
[
"page_title"
]
=
"Kategori Materi"
context
[
"item"
]
=
Category
.
objects
.
get
(
id
=
kwargs
[
"pk"
])
context
[
"form"
]
=
CategoryForm
(
instance
=
context
[
"item"
])
return
context
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
context
=
self
.
get_context_data
(
**
kwargs
)
return
self
.
render_to_response
(
context
=
context
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
category_object
=
self
.
get_context_data
(
**
kwargs
)[
"item"
]
form
=
CategoryForm
(
request
.
POST
,
instance
=
category_object
)
if
form
.
is_valid
():
form
.
save
()
return
HttpResponseRedirect
(
"/administration/setting/category/"
)
else
:
context
=
self
.
get_context_data
(
**
kwargs
)
context
[
"form"
]
=
form
return
self
.
render_to_response
(
context
)
def
delete_admin
(
request
,
*
args
,
**
kwargs
):
if
not
request
.
user
.
is_authenticated
or
not
request
.
user
.
is_admin
:
raise
PermissionDenied
(
request
)
User
.
objects
.
filter
(
pk
=
kwargs
[
"pk"
]).
delete
()
return
HttpResponseRedirect
(
"/administration/kelola-admin/"
)
def
delete_contributor
(
request
,
*
args
,
**
kwargs
):
if
not
request
.
user
.
is_authenticated
or
not
request
.
user
.
is_admin
:
raise
PermissionDenied
(
request
)
User
.
objects
.
filter
(
pk
=
kwargs
[
"pk"
]).
delete
()
return
HttpResponseRedirect
(
"/administration/kelola-kontributor/"
)
def
delete_verification
(
request
,
*
args
,
**
kwargs
):
if
not
request
.
user
.
is_authenticated
or
not
request
.
user
.
is_admin
:
raise
PermissionDenied
(
request
)
get_object_or_404
(
VerificationSetting
,
pk
=
kwargs
[
"pk_verification"
]).
delete
()
print
(
"lewat
"
)
messages
.
success
(
request
,
"Point verifikasi berhasil dihapus
"
)
return
HttpResponseRedirect
(
"/administration/setting/verification/"
)
def
delete_category
(
request
,
*
args
,
**
kwargs
):
if
not
request
.
user
.
is_authenticated
or
not
request
.
user
.
is_admin
:
raise
PermissionDenied
(
request
)
category_name
=
get_object_or_404
(
Category
,
pk
=
kwargs
[
"pk_category"
]).
name
get_object_or_404
(
Category
,
pk
=
kwargs
[
"pk_category"
]).
delete
()
messages
.
success
(
request
,
"Kategoryi "
+
category_name
+
" berhasil dihapus"
)
return
HttpResponseRedirect
(
"/administration/setting/category/"
)
app/models.py
View file @
79a25474
...
...
@@ -29,7 +29,6 @@ class Category(models.Model):
class
Materi
(
models
.
Model
):
# TODO: file fields, cover ubah jadi image fields, uploader jadi one to one kontributor
cover
=
models
.
ImageField
()
content
=
models
.
FileField
()
title
=
models
.
CharField
(
max_length
=
50
,
default
=
'title'
)
...
...
@@ -69,7 +68,7 @@ class Comment(models.Model):
materi
=
models
.
ForeignKey
(
Materi
,
models
.
SET_NULL
,
null
=
True
)
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
SET_NULL
,
blank
=
True
,
null
=
True
)
timestamp
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
timestamp
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
def
__str__
(
self
):
return
self
.
username
...
...
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