Fakultas Ilmu Komputer UI

Commit eadb8c9b authored by Saul Andre's avatar Saul Andre
Browse files

[REFACTOR]Creating edit and delete function for verification settings

parent 23e2b2aa
......@@ -233,7 +233,7 @@
class="far fa-save"
aria-hidden="true"
></i>
Tambahkan
Simpan
</button>
</div>
</form>
......
......@@ -251,6 +251,15 @@
</h6>
</div>
<div class="card-body">
<div class="alert">
{% if messages %}
{% for message in messages %}
<div class="alert alert-success" role="alert">
{{message}}
</div>
{% endfor %}
{% endif %}
</div>
<div class="table-responsive">
<table
class="table table-bordered"
......@@ -272,10 +281,39 @@
<th class="verif-buttons">
<a
href="/administration/setting/verification/{{ item.id }}/edit"
class="accept-button"
style="background-color:#4e73df"
>Edit</a
>
class="btn-primary btn-sm"
role="button"
>Edit</a
>
<a class="btn-sm btn-danger text-white" role="button" data-toggle="modal" data-target="#hapus-modal-{{item.id}}">
Hapus
</a>
<div class="modal fade" id="hapus-modal-{{item.id}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Hapus Point Verifikasi</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</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>
</div>
<form/>
{% csrf_token %}
<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>
</div>
</form>
</div>
</div>
</div>
</th>
</tr>
{% endfor %}
......@@ -343,6 +381,16 @@
<script src="{% static 'vendor/datatables/dataTables.bootstrap4.min.js' %}"></script>
<!-- Page level custom scripts -->
<script src="{% static 'js/demo/datatables-demo.js' %}"></script>
<script src="{% static 'js/demo/datatables-demo.js' %}"></script>
<script type="text/javascript">
function checkValue(element){
buttonElement = document.getElementById("btn-hapus-" + element.id)
if(element.value != element.name) {
buttonElement.classList.add("disabled");
} else {
buttonElement.classList.remove("disabled");
}
}
</script>
</body>
</html>
......@@ -800,6 +800,7 @@ class RegistrasiAdminTest(TestCase):
class EditVerificationTest(TestCase):
def setUp(self):
self.client = Client()
self.template_name = "edit_verifikasi.html"
self.admin_credential = {
"email": "admin@gov.id",
"password": id_generator()
......@@ -816,12 +817,12 @@ class EditVerificationTest(TestCase):
self.assertEqual(response.status_code, 200)
self.assertNotEqual(response.status_code, 404)
def test_verification_detail_anonymous_access(self):
def test_edit_verifikasi_anonymous_access(self):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 403)
self.assertNotEqual(response.status_code, 200)
def test_verifikasi_materi_using_correct_template(self):
def test_edit_verifikasi_using_correct_template(self):
self.client.login(**self.admin_credential)
found = resolve(self.url)
self.assertEqual(found.func.__name__, views.EditVerificationView.__name__)
......@@ -830,4 +831,44 @@ class EditVerificationTest(TestCase):
self.client.login(**self.admin_credential)
response = self.client.get(self.url)
self.assertContains(response, self.verification.title)
self.assertContains(response, self.verification.description)
\ No newline at end of file
self.assertContains(response, self.verification.description)
def test_post_edit_verifikasi_item_content(self):
self.client.login(**self.admin_credential)
response = self.client.get(self.url)
self.assertContains(response, self.verification.title)
self.assertContains(response, self.verification.description)
def test_delete_verification_data(self):
self.client.login(**self.admin_credential)
deleteObject = models.VerificationSetting.objects.create(title="deletelah", description="delete test")
self.client.get("/administration/delete-verification/" + str(deleteObject.id) + "/")
self.assertEqual(models.VerificationSetting.objects.all().filter(
title="deletelah").count(), 0)
def test_edit_verification(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_title"})["value"]
self.assertEqual(self.verification.title, el)
response = self.client.post(self.url, {
"title": "Kriteria 1", "description": "Deskripsi Kriteria 1"}, follow=True)
bs = BeautifulSoup(response.rendered_content, features="html.parser")
el = bs.find("table", {"id": "dataTable"}).get_text()
self.assertIn('Kriteria 1', el)
self.assertIn('Deskripsi Kriteria 1', el)
def test_edit_verification_missing_attribute(self):
# Login
self.client.login(**self.admin_credential)
response = self.client.post(
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
from django.urls import path
from administration.views import VerificationView, DetailVerificationView, VerificationSettingView, CategorySettingView, KelolaKontributorView, ProfileContributorAdminView, ProfileAdminAdministrationView, KelolaAdminView, RegistrasiAdminView, EditVerificationView, delete_admin, delete_contributor
from administration.views import VerificationView, DetailVerificationView, VerificationSettingView, CategorySettingView, KelolaKontributorView, ProfileContributorAdminView, ProfileAdminAdministrationView, KelolaAdminView, RegistrasiAdminView, EditVerificationView, delete_admin, delete_contributor, delete_verification
app_name = "administration"
......@@ -8,8 +8,9 @@ urlpatterns = [
path("", VerificationView.as_view()),
path("detail-verif/<int:pk>/", DetailVerificationView.as_view()),
path("setting/verification/", VerificationSettingView.as_view()),
path("delete-verification/<int:pk_verification>/", delete_verification),
path("setting/verification/<int:pk>/edit",
EditVerificationView.as_view(), name="edit-verifikasi"),
EditVerificationView.as_view(), name="edit-verification"),
path("setting/category/", CategorySettingView.as_view()),
path("kelola-kontributor/", KelolaKontributorView.as_view()),
path("profil/<int:pk>/", ProfileContributorAdminView.as_view()),
......@@ -18,5 +19,4 @@ urlpatterns = [
path("kelola-admin/tambah/", RegistrasiAdminView.as_view()),
path("hapus-admin/<int:pk>/", delete_admin),
path("hapus-kontributor/<int:pk>/", delete_contributor),
]
......@@ -3,6 +3,7 @@ from django.contrib.auth.hashers import make_password
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.views.generic import TemplateView
from django.contrib import messages
from app.models import Category, Materi
from authentication.models import User
......@@ -281,6 +282,18 @@ class EditVerificationView(TemplateView):
context = self.get_context_data(**kwargs)
return self.render_to_response(context=context)
def post(self, request, *args, **kwargs):
verification_object = self.get_context_data(**kwargs)["item"]
form = VerificationSettingForm(
request.POST, instance=verification_object)
if form.is_valid():
form.save()
return HttpResponseRedirect("/administration/setting/verification/")
else:
context = self.get_context_data(**kwargs)
context["form"] = form
return self.render_to_response(context)
def delete_admin(request, *args, **kwargs):
User.objects.filter(pk=kwargs["pk"]).delete()
......@@ -290,3 +303,10 @@ def delete_admin(request, *args, **kwargs):
def delete_contributor(request, *args, **kwargs):
User.objects.filter(pk=kwargs["pk"]).delete()
return HttpResponseRedirect("/administration/kelola-kontributor/")
def delete_verification(request, *args, **kwargs):
get_object_or_404(VerificationSetting,
pk=kwargs["pk_verification"]).delete()
print("lewat")
return HttpResponseRedirect("/administration/setting/verification/")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment