Fakultas Ilmu Komputer UI

Commit c6fa52af authored by Samuel Dimas's avatar Samuel Dimas
Browse files

[CHORES] Merging conflicts

parents d4619c36 2a1a04ec
{% extends 'app/detail_materi.html' %}
{% block title %}
Pratinjau Materi
{% endblock title %}
{% block verification %}
<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"></i>
</button>
<div class="sidebar-brand-text mx-3">Pratinjau Materi</div>
<!-- Topbar Navbar -->
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<button data-toggle="modal" data-target="#myModal" id="checklistButton" class="btn"
style="background-color:#4e73df;color: azure;">
Tampilkan Kriteria
</button>
</li>
</ul>
</nav>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-xl">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Kriteria Verifikasi</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
{% if error %}
<h4>Terjadi Kesalahan, coba lagi.</h4>
{% endif %}
{% for kriteria in kriteria_list %}
<div class="row m-2">
<div class="col-8">
{{kriteria.title}}
</div>
<div class="col-2">
<div class="custom-control custom-radio custom-control-inline">
<input id="kriteria{{ forloop.counter }}Ya" type="radio"
name="kriteria{{ forloop.counter }}" class="custom-control-input kriteria-ok" value=1>
<label class="custom-control-label" for="kriteria{{ forloop.counter }}Ya">Ya</label>
</div>
</div>
<div class="col-2">
<div class="custom-control custom-radio custom-control-inline">
<input checked id="kriteria{{ forloop.counter }}Tidak" type="radio"
name="kriteria{{ forloop.counter }}" class="custom-control-input" value=0>
<label class="custom-control-label" for="kriteria{{ forloop.counter }}Tidak">Tidak</label>
</div>
</div>
</div>
{% endfor %}
<span><small>Kontributor tidak dapat melihat point-point verifikasi, jika materi ditolak tuliskan alasan
penolakan tersebut di kolom tanggapan.</small></span>
<hr>
<form method="POST" id="submitForm">
{% csrf_token %}
<label for="feedbackMateri">Tanggapan terhadap materi untuk Kontributor :</label>
<textarea name="feedback" id="feedbackMateri" class="form-control" rows="6"></textarea>
</form>
</div>
<div class="modal-footer">
<button disabled class="accept-button btn" type="submit" name="action" value="approve" form="submitForm"
style="background-color: #28a745;border-radius: .25rem;color: azure;"
id="approveButton">Terima</button>
<button disabled class="reject-button btn" type="submit" name="action" value="disapprove"
form="submitForm" style="background-color: #dc3545;border-radius: .25rem;color: azure;"
id="disapproveButton">Tolak</button>
<button type="button" class="btn" data-dismiss="modal">Tutup</button>
</div>
</div>
</div>
</div>
{% endblock verification %}
{% block extra_scripts %}
<script>
function cekRadio() {
res = true
x = document.getElementsByClassName("kriteria-ok")
for (index = 0; index < x.length; index++) {
if (x[index].checked == false) {
res = false;
break;
}
}
return res;
}
function cekFeedback() {
if (!$.trim($("#feedbackMateri").val())) {
return false;
} else {
return true;
}
}
$(document).ready(function () {
var approveButton = document.getElementById("approveButton")
var disapproveButton = document.getElementById("disapproveButton")
$(":input").change(function () {
console.log("Running test")
var statusRadio = cekRadio();
var statusFeedback = cekFeedback();
if (statusFeedback) {
disapproveButton.disabled = false;
if (statusRadio) {
approveButton.disabled = false;
} else {
approveButton.disabled = true;
}
} else {
disapproveButton.disabled = true;
approveButton.disabled = true;
}
});
});
</script>
{% endblock extra_scripts %}
\ No newline at end of file
......@@ -168,6 +168,22 @@
<th>Status</th>
</tr>
</tfoot>
<tbody>
{% for materi in materi_list %}
<tr>
<td>{{ materi.title }}</td>
<td>{{ materi.uploader.name }}</td>
<td>{{ materi.status.label }}</td>
{% if materi.status == "PENDING" %}
<td class="verif-buttons">
<a href="/administration/detail-verif/{{materi.id}}/" class="accept-button"
style="background-color:#4e73df">Detail</a>
<a href="/administration/api/approve/{{materi.id}}/" class="accept-button">Terima</a>
<a href="/administration/api/disapprove/{{materi.id}}/" class="reject-button">Tolak</a></td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
......
......@@ -3,129 +3,117 @@ from django.test import Client, TestCase
from django.urls import resolve
from administration import models, views
from app.models import Materi
from app.models import Materi, Category
class VerifikasiMateriTest(TestCase):
def setUp(self):
self.client = Client()
# def test_verifikasi_materi_url_exist(self):
# response = self.client.get('/administration/')
# self.assertEqual(response.status_code, 200)
# def test_verifikasi_materi_using_correct_template(self):
# found = resolve('/administration/')
# self.assertEqual(found.func.__name__, views.verification.__name__)
# found2 = resolve('/admin/')
# self.assertNotEqual(found2.func.__name__, views.verification.__name__)
# def test_verifikasi_materi_title(self):
# response = self.client.get('/administration/')
# self.assertContains(response, 'Dasbor - Verifikasi Materi')
# self.assertNotContains(response, 'Fake Title')
# def test_verifikasi_materi_content(self):
# response = self.client.get('/administration/')
# self.assertContains(response, 'Judul Materi')
# self.assertContains(response, 'Nama Kontributor')
# self.assertContains(response, 'Status')
# self.assertNotContains(response, 'Halaman Katalog')
self.url = "/administration/setting/verification/"
self.model = models.VerificationSetting
self.admin = get_user_model().objects.create_user(
password="admin123", email="admin@admin.com", is_admin=True)
self.contributor = get_user_model().objects.create_user(
password="kontributor123", email="kontributor@kontributor.com", is_contributor=True
)
self.materi = Materi(title="LK 3", author="Agas", uploader=self.contributor,
publisher="Kelas SC", descriptions="COntoh pengerjaan LK 3", status="PENDING").save()
def test_verifikasi_materi_url_exist(self):
response = self.client.get('/administration/detail')
# Login
self.client.login(email="admin@admin.com",
password="admin123")
response = self.client.get('/administration/')
self.assertEqual(response.status_code, 200)
def test_verifikasi_materi_using_correct_template(self):
found = resolve('/administration/detail')
self.assertEqual(found.func.__name__, views.detail.__name__)
found2 = resolve('/admin/')
self.assertNotEqual(found2.func.__name__, views.verification.__name__)
# Login
self.client.login(email="admin@admin.com",
password="admin123")
found = resolve('/administration/')
self.assertEqual(found.func.__name__, views.VerificationView.__name__)
def test_verifikasi_materi_title(self):
response = self.client.get('/administration/detail')
# Login
self.client.login(email="admin@admin.com",
password="admin123")
response = self.client.get('/administration/')
self.assertContains(response, 'Dasbor - Verifikasi Materi')
self.assertNotContains(response, 'Fake Title')
def test_verifikasi_materi_content(self):
response = self.client.get('/administration/detail')
# Login
self.client.login(email="admin@admin.com",
password="admin123")
response = self.client.get('/administration/')
self.assertContains(response, 'Judul Verifikasi')
self.assertContains(response, 'Deskripsi')
self.assertContains(response, 'Tombol')
self.assertContains(response, 'LK 3')
self.assertContains(response, self.contributor.name)
self.assertNotContains(response, 'Halaman Katalog')
class DetailVerifikasiMateriTest(TestCase):
def setUp(self):
self.client = Client()
self.view = views.DetailVerificationView
self.template_name = "detai_verif.html"
self.model = models.VerificationSetting
self.admin = get_user_model().objects.create_user(
password="admin123", email="admin@admin.com", is_admin=True)
self.contributor = get_user_model().objects.create_user(
password="kontributor123", email="kontributor@kontributor.com", is_contributor=True
)
self.materi = Materi(id = 1, title="LK 3", author="Agas", uploader=self.contributor,
publisher="Kelas SC", descriptions="COntoh pengerjaan LK 3", status="PENDING").save()
self.url = f"/administration/detail-verif/1/"
def test_dashboard_kontributor_view(self):
found = resolve(self.url)
self.assertEqual(found.func.__name__, self.view.as_view().__name__)
def test_dashboard_kontributor_template(self):
# Login
self.client.login(email="admin@admin.com",
password="admin123")
# Test
response = self.client.get(self.url)
self.assertTemplateUsed(response, self.template_name)
# Logout
self.client.logout()
def test_dashboard_kontributor_url(self):
# Login
self.client.login(email="admin@admin.com",
password="admin123")
# Test
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
# Logout
self.client.logout()
class SettingVerifikasiTest(TestCase):
def setUp(self):
self.client = Client()
self.url = "/administration/setting/verification/"
self.model = models.VerificationSetting
self.admin = get_user_model().objects.create_user(password="admin123", email="admin@admin.com", is_admin=True)
self.admin = get_user_model().objects.create_user(
password="admin123", email="admin@admin.com", is_admin=True)
self.contributor = get_user_model().objects.create_user(
password="kontributor123", email="kontributor@kontributor.com", is_contributor=True
)
# def test_setting_verifikasi_url_exist(self):
# # Test not authenticated
# response = self.client.get(self.url)
# self.assertEqual(response.status_code, 403)
# # Test Contributor
# self.client.login(email = 'kontributor@kontributor.com', password = 'kontributor123')
# response = self.client.get(self.url)
# self.assertEqual(response.status_code, 403)
# self.client.logout()
# # Test Admin
# self.client.login(email = 'admin@admin.com', password = 'admin123')
# response = self.client.get(self.url)
# self.assertEqual(response.status_code, 200)
# def test_setting_verifikasi_template(self):
# self.client.login(email = 'admin@admin.com', password = 'admin123')
# response = self.client.get(self.url)
# self.assertTemplateUsed(response, 'setting_verifikasi.html')
# def test_setting_verifikasi_func(self):
# found = resolve(self.url)
# self.assertEqual(found.func.__name__, views.VerificationSettingView.as_view().__name__)
# def test_setting_verifikasi_model(self):
# self.assertEqual(self.model.objects.all().count(), 0)
# s1 = self.model(title = "Point 1",description= "Deskripsi Point 1")
# s1.save()
# self.assertEqual(self.model.objects.all().count(), 1)
# def test_setting_verifikasi_table(self):
# # Login
# self.client.login(email = 'admin@admin.com', password = 'admin123')
# # View table
# response = self.client.get(self.url)
# self.assertNotIn(response.content, b'Point 1')
# # Add new setting
# data = {
# "tittle":"Point 1",
# "description":"Deskripsi Point 1"
# }
# response = self.client.post(self.url, data)
# self.assertIn(response.content, b'Point 1')
# self.assertEqual(response.status_code, 200)
# # Add new setting, missing value
# data = {
# "description":"Deskripsi Point 2"
# }
# response = self.client.post(self.url, data)
# self.assertNotIn(response.content, b'Deskripsi Point 2')
# self.assertEqual(response.status_code, 200)
class SettingKategoriTest(TestCase):
def setUp(self):
self.client = Client()
self.url = "/administration/setting/category/"
self.model = Category
self.admin = get_user_model().objects.create_user(
password="admin123", email="admin@admin.com", is_admin=True)
self.contributor = get_user_model().objects.create_user(
password="kontributor123", email="kontributor@kontributor.com", is_contributor=True
)
......@@ -5,9 +5,8 @@ from . import views
app_name = "administration"
urlpatterns = [
path("", views.verification),
path("api/approve/<int:pk>", views.verification),
path("api/disapprove/<int:pk>", views.verification),
path("", views.VerificationView.as_view()),
path("detail-verif/<int:pk>/", views.DetailVerificationView.as_view()),
path("setting/verification/", views.VerificationSettingView.as_view()),
path("setting/category/", views.CategorySettingView.as_view()),
path("detail", views.detail)
......
......@@ -10,39 +10,70 @@ from .models import VerificationSetting
# Create your views here.
def verification(request):
materi_list = Materi.objects.all()
context = {'materi_list': materi_list}
return render(request, "verif.html", context)
class VerificationView(TemplateView):
template_name = "verif.html"
def detail(request):
return render(request, "detail.html")
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated or not request.user.is_admin:
raise PermissionDenied(request)
return super(VerificationView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(VerificationView, self).get_context_data(**kwargs)
context["materi_list"] = Materi.objects.filter(status='PENDING')
return context
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
return self.render_to_response(context)
class DetailVerificationView(TemplateView):
template_name = "detail_verif.html"
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated or not request.user.is_admin:
raise PermissionDenied(request)
return super(DetailVerificationView, self).dispatch(request, *args, **kwargs)
def approve(request, pk):
if request.user.is_authenticated == False or request.user.is_admin != True:
raise PermissionDenied(request)
materi = get_object_or_404(Materi, pk=pk)
materi.status = ("APPROVE", "Diterima")
materi.save()
return render(request, "verif.html")
def get_context_data(self, **kwargs):
context = super(DetailVerificationView,
self).get_context_data(**kwargs)
context["materi_data"] = get_object_or_404(Materi, pk=kwargs["pk"])
context["kriteria_list"] = VerificationSetting.objects.filter(
archived=False)
return context
def post(self, request, *args, **kwargs):
materi = get_object_or_404(Materi, pk=kwargs["pk"])
feedback = request.POST.get("feedback")
if request.POST.get("action") == "approve":
materi.status = "APPROVE"
materi.feedback = feedback
materi.save()
elif request.POST.get("action") == "disapprove":
materi.status = "DISAPPROVE"
materi.feedback = feedback
materi.save()
else:
context = self.get_context_data(**kwargs)
context["error"] = True
return self.render_to_response(context=context)
return HttpResponseRedirect("/administration/")
def disapprove(request, pk):
if request.user.is_authenticated == False or request.user.is_admin != True:
raise PermissionDenied(request)
materi = get_object_or_404(Materi, pk=pk)
materi.status = ("DISAPROVE", "Ditolat")
materi.save()
return render(request, "verif.html")
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
return self.render_to_response(context=context)
class VerificationSettingView(TemplateView):
template_name = "setting_verifikasi.html"
def get_context_data(self, **kwargs):
context = super(VerificationSettingView, self).get_context_data(**kwargs)
context["verification_settings"] = VerificationSetting.objects.filter(archived=False)
context = super(VerificationSettingView,
self).get_context_data(**kwargs)
context["verification_settings"] = VerificationSetting.objects.filter(
archived=False)
return context
def get(self, request, *args, **kwargs):
......
......@@ -50,7 +50,8 @@ class Materi(models.Model):
uploader = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
publisher = models.CharField(max_length=30, default="publiser")
descriptions = models.TextField(default="descriptions")
status = models.CharField(max_length=30, choices=VERIFICATION_STATUS, default=VERIFICATION_STATUS[0])
status = models.CharField(max_length=30, choices=VERIFICATION_STATUS, default=VERIFICATION_STATUS[0][0])
categories = models.ManyToManyField(Category)
comments = models.ManyToManyField(Comment)
feedback = models.TextField(blank=True, default="")
\ No newline at end of file
<!doctype html>
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dashboard Kontributor</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" type="image/png" href="../static/unggah_materi/images/logo.ico" />
<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 Kontributor</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 href="{% static 'css/sb-admin-2.min.css' %}" rel="stylesheet">
<link rel="stylesheet" href="{% static 'css/button.css' %}">
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet">
<!-- Custom styles for this page -->
<link href="{% static 'vendor/datatables/dataTables.bootstrap4.min.css' %}" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="../static/unggah_materi/css/style.css">
</head>
<body style="background-color: #f2f2f2;">
<div class="wrapper d-flex align-items-stretch">
<nav id="sidebar" style="background-color: #6675df;" >
<div class="p-4 pt-5" >
<a href="#" class="img logo rounded-circle mb-5" style="background-image: url(../static/unggah_materi/images/dummy.png);"></a>
<ul class="list-unstyled components mb-5">
<li>
<a href="/dashboard/">Dashboard</a>
</li>
<li>
<a href="/profile/">Profile</a>
</li>
<li>
<a href="/unggah/">Unggah materi</a>
</li>
</ul>
</div>
<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="{% url 'daftar_katalog' %}">
<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="{% url 'dashboard' %}">
<span>Beranda</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'unggah' %}">
<span>Unggah Materi</span></a>
</li>
</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"></i>
</button>
<div class="sidebar-brand-text mx-3">Diskominfo Kota Depok</div>
<!-- Topbar Navbar -->
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="/unggah/">
<span class="mr-2 d-none d-lg-inline text-gray-600 small">Unggah</span>
</a>
</li>
<li <