Fakultas Ilmu Komputer UI

Commit 3c22be34 authored by Samuel Dimas Partogi's avatar Samuel Dimas Partogi
Browse files

Merge branch 'PBI-Edit_Verifikasi' into 'staging'

Pbi edit verifikasi

See merge request ppl-fasilkom-ui/2020/ppl-c/diskominfo-depok-digipus/marjinal-digipus!56
parents fb620c4d eadb8c9b
......@@ -26,16 +26,21 @@ class VerificationSettingForm(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"
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
if field_name == "description":
field.widget.attrs["rows"] = "3"
class RegistrasiAdminForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput)
password2 = forms.CharField(widget=forms.PasswordInput)
class Meta:
model = User
fields = ["name", "instansi", "nik", "alamat", "email", "nomor_telpon"]
def __init__(self, *args, **kwargs):
super(RegistrasiAdminForm, self).__init__(*args, **kwargs)
for field_name, field in self.fields.items():
......@@ -53,7 +58,7 @@ class RegistrasiAdminForm(forms.ModelForm):
if password != password2:
raise forms.ValidationError("Password tidak sama")
return password
def clean_email(self):
email = self.cleaned_data.get("email")
if not User.objects.filter(email=email).exists():
......
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="description" content="" />
<meta name="author" content="" />
<title>Dasbor - {{ page_title }}</title>
<!-- Custom fonts for this template -->
<link
href="https://fonts.googleapis.com/css2?family=Poppins&display=swap"
rel="stylesheet"
/>
<!-- Custom styles for this template -->
<link
rel="icon"
type="image/png"
href="{% static 'images/icons/logo.ico' %}"
/>
<link href="{% static 'css/sb-admin-2.min.css' %}" rel="stylesheet" />
<link rel="stylesheet" href="{% static 'css/button.css' %}" />
<!-- Custom styles for this page -->
<link
href="{% static 'vendor/datatables/dataTables.bootstrap4.min.css' %}"
rel="stylesheet"
/>
</head>
<body id="page-top" style="font-family: 'Poppins', sans-serif;">
<!-- Page Wrapper -->
<div id="wrapper">
<!-- Sidebar -->
<ul
class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion"
id="accordionSidebar"
>
<!-- Sidebar - Brand -->
<a
class="sidebar-brand d-flex align-items-center justify-content-center"
href="verif.html"
>
<div class="sidebar-brand-icon rotate-n-15"></div>
<div class="sidebar-brand-text mx-3">Digipus</div>
</a>
<!-- Divider -->
<hr class="sidebar-divider my-0" />
<!-- Nav Item - Dashboard -->
<li class="nav-item">
<a class="nav-link" href="/administration/">
<span>Verifikasi Materi</span></a
>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span>Statistik Materi</span></a
>
</li>
<!-- Divider -->
<hr class="sidebar-divider my-0" />
<li class="nav-item">
<a
class="nav-link"
href="/administration/setting/verification/"
>
<span>Pengaturan Verifikasi</span></a
>
</li>
<li class="nav-item">
<a
class="nav-link"
href="/administration/setting/category/"
>
<span>Pengaturan Kategori</span></a
>
</li>
<!-- Divider -->
<hr class="sidebar-divider my-0" />
<li class="nav-item">
<a
class="nav-link"
href="/administration/kelola-kontributor/"
>
<span>Kelola Kontributor</span></a
>
</li>
<li class="nav-item">
<a class="nav-link" href="/administration/kelola-admin/">
<span>Kelola Admin</span></a
>
</li>
<!-- Divider -->
<hr class="sidebar-divider my-0" />
</ul>
<!-- End of Sidebar -->
<!-- Content Wrapper -->
<div id="content-wrapper" class="d-flex flex-column">
<!-- Main Content -->
<div id="content">
<!-- Topbar -->
<nav
class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow"
>
<!-- Sidebar Toggle (Topbar) -->
<button
id="sidebarToggleTop"
class="btn btn-link d-md-none rounded-circle mr-3"
>
<i class="fa fa-bars" aria-hidden="true"></i>
</button>
<div class="sidebar-brand-text mx-3">
Diskominfo Kota Depok
</div>
<!-- Topbar Navbar -->
<ul class="navbar-nav ml-auto">
<!-- Nav Item - Search Dropdown (Visible Only XS) -->
<li class="nav-item">
<a class="nav-link" href="/dashboard/">
<span
class="mr-2 d-none d-lg-inline text-gray-600 small"
>Administrasi</span
>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/profil-admin/">
<span
class="mr-2 d-none d-lg-inline text-gray-600 small"
>Profil</span
>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/logout/">
<span
class="mr-2 d-none d-lg-inline text-gray-600 small"
>Logout</span
>
</a>
</li>
<div class="topbar-divider d-none d-sm-block"></div>
<!-- Nav Item - User Information -->
<li class="nav-item dropdown no-arrow">
<a
class="nav-link dropdown-toggle"
href="#"
id="userDropdown"
role="button"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
<span
class="mr-2 d-none d-lg-inline text-gray-600 small"
>Admin</span
>
{% if not user.default_profile_picture %}
<img
class="img-profile rounded-circle"
src="https://i.ibb.co/9wgPzyZ/default-image.png"
alt="User profile picture"
/>
{% else %}
<img
class="img-profile rounded-circle"
src="{{ user.profile_picture.url }}"
alt="User profile picture"
/>
{% endif %}
</a>
</li>
</ul>
</nav>
<!-- End of Topbar -->
<!-- Begin Page Content -->
<div class="container-fluid">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">
{{ page_title }} Baru
</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 }}
</div>
<div
class="description d-flex align-items-baseline"
>
{{ form.description }}
</div>
<div class="">
<button
class="primary_btn save"
style="border-radius:20px;"
type="submit"
>
<i
class="far fa-save"
aria-hidden="true"
></i>
Simpan
</button>
</div>
</form>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
<!-- End of Main Content -->
<!-- Footer -->
<footer class="sticky-footer bg-white">
<div class="container my-auto">
<div class="copyright text-center my-auto">
<span
>Copyright &copy; Diskominfo Kota Depok
2020</span
>
</div>
</div>
</footer>
<!-- End of Footer -->
</div>
<!-- End of Content Wrapper -->
</div>
<!-- End of Page Wrapper -->
<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
<i class="fas fa-angle-up" aria-hidden="true"></i>
</a>
<!-- Bootstrap core JavaScript-->
<script
src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"
></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"
></script>
<!-- Core plugin JavaScript-->
<script
src="https://code.jquery.com/jquery-3.5.0.min.js"
integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ="
crossorigin="anonymous"
></script>
<!-- Custom scripts for all pages-->
<script src="{% static 'js/sb-admin-2.min.js' %}"></script>
<!-- Page level plugins -->
<script src="{% static 'vendor/datatables/jquery.dataTables.min.js' %}"></script>
<script src="{% static 'vendor/datatables/dataTables.bootstrap4.min.js' %}"></script>
<!-- Page level custom scripts -->
<script src="{% static 'js/demo/datatables-demo.js' %}"></script>
</body>
</html>
This diff is collapsed.
......@@ -795,4 +795,80 @@ class RegistrasiAdminTest(TestCase):
self.assertContains(response, 'Dasbor - Kelola Admin')
self.assertNotContains(response, 'Fake Title')
\ No newline at end of file
self.assertNotContains(response, 'Fake Title')
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()
}
self.admin = get_user_model().objects.create_user(
**self.admin_credential, name="Admin", is_admin=True)
models.VerificationSetting(title='test', description="desc test").save()
self.verification = models.VerificationSetting.objects.first()
self.url = "/administration/setting/verification/" + str(self.verification.id) +"/edit"
def test_edit_verification_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_verifikasi_anonymous_access(self):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 403)
self.assertNotEqual(response.status_code, 200)
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__)
def test_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_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, 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,6 +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-verification"),
path("setting/category/", CategorySettingView.as_view()),
path("kelola-kontributor/", KelolaKontributorView.as_view()),
path("profil/<int:pk>/", ProfileContributorAdminView.as_view()),
......@@ -16,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
......@@ -174,6 +175,7 @@ class KelolaKontributorView(TemplateView):
context = self.get_context_data(**kwargs)
return self.render_to_response(context)
class KelolaAdminView(TemplateView):
template_name = "kelola_admin.html"
......@@ -192,6 +194,7 @@ class KelolaAdminView(TemplateView):
context = self.get_context_data(**kwargs)
return self.render_to_response(context)
class ProfileContributorAdminView(TemplateView):
template_name = "detail_kontri_admin.html"
......@@ -209,6 +212,7 @@ class ProfileContributorAdminView(TemplateView):
context["user"] = get_object_or_404(User, pk=kwargs["pk"])
return self.render_to_response(context=context)
class ProfileAdminAdministrationView(TemplateView):
template_name = "detail_admin.html"
......@@ -226,6 +230,7 @@ class ProfileAdminAdministrationView(TemplateView):
context["user"] = get_object_or_404(User, pk=kwargs["pk"])
return self.render_to_response(context=context)
class RegistrasiAdminView(TemplateView):
template_name = "registrasi_admin.html"
......@@ -238,11 +243,11 @@ class RegistrasiAdminView(TemplateView):
context = super(RegistrasiAdminView, self).get_context_data(**kwargs)
context["form"] = RegistrasiAdminForm
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):
data = request.POST.copy()
form = RegistrasiAdminForm(request.POST)
......@@ -257,10 +262,51 @@ class RegistrasiAdminView(TemplateView):
context["form"] = form
return self.render_to_response(context)
class EditVerificationView(TemplateView):
template_name = "edit_verifikasi.html"
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated or not request.user.is_admin:
raise PermissionDenied(request)
return super(EditVerificationView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(EditVerificationView, self).get_context_data(**kwargs)
context["page_title"] = "Edit Verifikasi"
context["item"] = VerificationSetting.objects.get(id=kwargs["pk"])
context["form"] = VerificationSettingForm(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):
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()
return HttpResponseRedirect("/administration/kelola-admin/")
def delete_contributor(request, *args, **kwargs):
User.objects.filter(pk=kwargs["pk"]).delete()
return HttpResponseRedirect("/administration/kelola-kontributor/")
\ No newline at end of file
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