Fakultas Ilmu Komputer UI

Commit 796f79b9 authored by Saul Andre's avatar Saul Andre
Browse files

Merge branch 'staging' of...

Merge branch 'staging' of https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/2020/ppl-c/diskominfo-depok-digipus/marjinal-digipus into PBI-Edit_Verifikasi
parents 3aff6414 cef3365b
# Generated by Django 3.0.3 on 2020-06-03 12:57
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('administration', '0004_auto_20200517_1713'),
]
operations = [
migrations.CreateModel(
name='DeletionHistory',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('deleted_user_name', models.CharField(max_length=150)),
('deleted_user_role', models.CharField(max_length=150)),
('timestamp', models.DateTimeField(default=django.utils.timezone.now)),
('deletor_admin', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
),
]
......@@ -20,3 +20,9 @@ class VerificationReport(models.Model):
timestamp = models.DateTimeField(default=timezone.now)
status = models.CharField(
max_length=30, choices=VERIFICATION_STATUS, default=VERIFICATION_STATUS[0][0])
class DeletionHistory(models.Model):
deleted_user_name = models.CharField(max_length=150)
deleted_user_role = models.CharField(max_length=150)
timestamp = models.DateTimeField(default=timezone.now)
deletor_admin = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
\ No newline at end of file
......@@ -186,6 +186,40 @@
<a class="btn btn-primary btn-admin" href="/administration/kelola-admin/">Kembali ke Kelola Admin</a>
</div>
</div>
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary" id="titleTabelPending">Daftar Pengguna yang Pernah Dihapus</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTablePending" aria-describedby="titleTabelPending">
<thead>
<tr>
<th scope="col">Nama</th>
<th scope="col">Peran</th>
<th scope="col">Waktu Penghapusan</th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="col">Nama</th>
<th scope="col">Peran</th>
<th scope="col">Waktu Penghapusan</th>
</tr>
</tfoot>
<tbody>
{% for history in deletion_history %}
<tr>
<td>{{ history.deleted_user_name }}</td>
<td>{{ history.deleted_user_role }}</td>
<td>{{ history.timestamp }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
......
......@@ -184,9 +184,9 @@
<td>{{ user.instansi }}</td>
<td class="verif-buttons">
<span>
<a href="/administration/profil/{{ current.id }}/" class="accept-button button-decoration">Detail</a>
<button type="button" class="reject-button button-decoration" data-toggle="modal" data-target="#confirmModal{{ current.id }}">Hapus</button>
<div class="modal fade" id="confirmModal{{ current.id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<a href="/administration/profil/{{ user.id }}/" class="accept-button button-decoration">Detail</a>
<button type="button" class="reject-button button-decoration" data-toggle="modal" data-target="#confirmModal{{ user.id }}">Hapus</button>
<div class="modal fade" id="confirmModal{{ user.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">
......@@ -200,7 +200,7 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
<a href="/administration/hapus-kontributor/{{current.id}}/" type="button" class="btn btn-danger">Hapus</a>
<a href="/administration/hapus-kontributor/{{user.id}}/" type="button" class="btn btn-danger">Hapus</a>
</div>
</div>
</div>
......
......@@ -6,7 +6,7 @@ from django.http import HttpResponseRedirect, JsonResponse
from django.shortcuts import get_object_or_404, render
from django.views.generic import TemplateView, View
from django.contrib import messages
from administration.models import VerificationReport, VerificationSetting
from administration.models import VerificationReport, VerificationSetting, DeletionHistory
from administration.forms import CategoryForm, VerificationSettingForm, RegistrasiAdminForm, PeriodForm
from app.models import Category, Materi
from authentication.models import User
......@@ -50,7 +50,10 @@ class DetailVerificationView(TemplateView):
context["materi_data"] = materi
context["kriteria_list"] = VerificationSetting.objects.filter(
archived=False)
riwayat = True if materi.status != "PENDING" else False
if materi.status == "PENDING" or materi.status == "REVISION":
riwayat = False
else:
riwayat = True
context["riwayat"] = riwayat
context["verification_report"] = materi.verificationreport_set.first()
return context
......@@ -198,7 +201,6 @@ class KelolaAdminView(TemplateView):
context = self.get_context_data(**kwargs)
return self.render_to_response(context)
class ProfileContributorAdminView(TemplateView):
template_name = "detail_kontri_admin.html"
......@@ -216,7 +218,6 @@ class ProfileContributorAdminView(TemplateView):
context["user"] = get_object_or_404(User, pk=kwargs["pk"])
return self.render_to_response(context=context)
class StatisticsView(TemplateView):
template_name = "administration/data_statistik.html"
......@@ -260,6 +261,7 @@ class ProfileAdminAdministrationView(TemplateView):
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
context["user"] = get_object_or_404(User, pk=kwargs["pk"])
context["deletion_history"] = DeletionHistory.objects.filter(deletor_admin=get_object_or_404(User, pk=kwargs["pk"]))
return self.render_to_response(context=context)
......@@ -362,6 +364,14 @@ class EditCategoryView(TemplateView):
def delete_admin(request, *args, **kwargs):
if not request.user.is_authenticated or not request.user.is_admin:
raise PermissionDenied(request)
user_to_be_deleted = User.objects.get(pk=kwargs["pk"])
DeletionHistory.objects.create(
deleted_user_name=user_to_be_deleted.name,
deleted_user_role="Admin",
deletor_admin=request.user
)
User.objects.filter(pk=kwargs["pk"]).delete()
return HttpResponseRedirect("/administration/kelola-admin/")
......@@ -369,6 +379,14 @@ def delete_admin(request, *args, **kwargs):
def delete_contributor(request, *args, **kwargs):
if not request.user.is_authenticated or not request.user.is_admin:
raise PermissionDenied(request)
user_to_be_deleted = User.objects.get(pk=kwargs["pk"])
DeletionHistory.objects.create(
deleted_user_name=user_to_be_deleted.name,
deleted_user_role="Kontributor",
deletor_admin=request.user
)
User.objects.filter(pk=kwargs["pk"]).delete()
return HttpResponseRedirect("/administration/kelola-kontributor/")
......
......@@ -6,3 +6,26 @@
body {
padding-top: 56px;
}
.center {
text-align: center;
}
.pagination {
display: inline-block;
}
.pagination a {
color: black;
float: left;
padding: 8px 16px;
text-decoration: none;
transition: background-color .3s;
border: 1px solid #ddd;
margin: 0 4px;
}
.pagination a.active {
background-color: #4CAF50;
color: white;
border: 1px solid #4CAF50;
}
\ No newline at end of file
body{
color: #615CFD;
}
.center {
text-align: center;
}
.pagination {
display: inline-block;
}
.pagination a {
color: black;
float: left;
padding: 8px 16px;
text-decoration: none;
transition: background-color .3s;
border: 1px solid #ddd;
margin: 0 4px;
}
.pagination a.active {
background-color: #4CAF50;
color: white;
border: 1px solid #4CAF50;
}
.header {
display: flex;
......@@ -111,4 +134,5 @@ body{
.card-body .btn:hover{
color: #ffffff;
background-color: #615CFD;
}
\ No newline at end of file
}
\ No newline at end of file
......@@ -48,7 +48,7 @@
{% for item in report %}
<p class="black-text">Alasan materi ditolak:</p>
<p class="black-text">{{ item.report.feedback }}</p>
<p class="black-text">Untuk merevisi materi, sila tekan tombol perbarui di halaman riwayat unggah.</p>
<p class="black-text">Untuk merevisi materi, sila tekan tombol revisi di halaman riwayat unggah.</p>
{% endfor %}
</div>
<div class="modal-footer">
......
......@@ -138,10 +138,36 @@
</div>
{% endfor %}
</div>
<div class="center">
<div class="pagination">
<span class="step-links">
<span class="current">
Page {{ materi_list.number }} of {{ materi_list.paginator.num_pages }}
</span>
<br>
</br>
{% if materi_list.has_previous %}
<a href="?page=1" >&laquo; first</a>
<a href="?page={{ materi_list.previous_page_number }}">previous</a>
{% endif %}
{% if materi_list.has_next %}
<a href="?page={{ materi_list.next_page_number }}">next</a>
<a href="?page={{ materi_list.paginator.num_pages }}">last &raquo;</a>
{% endif %}
</span>
</div>
</div>
</div>
</div>
</div>
<!-- /.container -->
</body>
......
......@@ -121,7 +121,7 @@
<div class="col-20">
<h1 class="mt-2">Sunting Profil</h1>
<hr class="mt-0 mb-4">
<form id="add_form" method="POST" action="{% url 'sunting' %}" novalidate enctype="multipart/form-data">
<form id="add_form" method="POST" action="{% url 'sunting-admin' %}" novalidate enctype="multipart/form-data">
{% csrf_token %}
{% for field in form %}
<div class="col-md-6">
......
......@@ -154,7 +154,9 @@
<div class="col-md-6">
<div class="fieldWrapper">
{{ field.label_tag }} {{ field }}
<p> </p>
{{ field.errors }}
<p> </p>
{% if field.help_text %}
<p class="help">{{ field.help_text|safe }}</p>
{% endif %}
......@@ -163,10 +165,7 @@
{% endfor %}
<div class="row marl text-center m-3">
<a href="{% url 'unggah' %}" class="secondary_btn clear" style="border-radius:20px;color:white;"
id="create_user_cancel"><i class="fa fa-undo" aria-hidden="true">
</i>
Batal</a>
<button type="submit" class="btn btn-success"
style="background-color: #615CFD; border-color: #615CFD;">Simpan</button>
......
......@@ -5,7 +5,7 @@ from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.contrib import messages
from django.core import serializers
from django.core.exceptions import PermissionDenied
from django.core.exceptions import PermissionDenied, ValidationError
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Q
from django.http import (Http404, HttpResponse, HttpResponseRedirect,
......@@ -66,6 +66,11 @@ class DaftarKatalog(TemplateView):
elif(getSort == "pengunggah"):
context["materi_list"] = list.order_by('uploader')
paginator = Paginator(context["materi_list"], 15)
page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number)
context["materi_list"] = page_obj
return self.render_to_response(context=context)
......@@ -166,6 +171,7 @@ def download_materi(request, pk):
else:
raise Http404("File tidak dapat ditemukan.")
def view_materi(request, pk):
materi = get_object_or_404(Materi, pk=pk)
path = materi.content.path
......@@ -184,6 +190,7 @@ def view_materi(request, pk):
else:
raise Http404("File tidak dapat ditemukan.")
class UploadMateriView(TemplateView):
template_name = "unggah.html"
context = {}
......@@ -199,11 +206,18 @@ class UploadMateriView(TemplateView):
if form.is_valid():
materi = form.save(commit=False)
materi.uploader = request.user
konten = form.cleaned_data['content']
try:
self.validate_file_extension(konten)
except ValidationError:
messages.error(request, "Materi gagal diunggah, format file tidak sesuai")
return HttpResponseRedirect("/unggah/")
materi.save()
kateg = form.cleaned_data['categories']
for i in kateg:
materi.categories.add(i)
messages.success(request, "Materi berhasil diunggah, periksa riwayat unggah anda")
messages.success(
request, "Materi berhasil diunggah, periksa riwayat unggah anda")
return HttpResponseRedirect("/unggah/")
else:
context = self.get_context_data(**kwargs)
......@@ -217,11 +231,18 @@ class UploadMateriView(TemplateView):
context = self.get_context_data(**kwargs)
context["form"] = UploadMateriForm
return self.render_to_response(context)
def validate_file_extension(self, value):
ext = os.path.splitext(value.name)[1] # [0] returns path+filename
valid_extensions = ['.pdf', '.doc', '.docx', '.jpg', '.png', '.xlsx', '.xls', '.mp4', '.mp3']
if not ext.lower() in valid_extensions:
raise ValidationError('Unsupported file extension.')
class UploadMateriHTML(TemplateView):
template_name = "unggah.html"
context = {}
def get_template_names(self):
if self.request.path == "/unggah/":
template_name = "unggah.html"
......@@ -324,6 +345,7 @@ class SuntingProfilView(TemplateView):
context["form"] = form
return self.render_to_response(context)
class SuntingProfilAdminView(TemplateView):
template_name = "sunting_admin.html"
......@@ -333,7 +355,8 @@ class SuntingProfilAdminView(TemplateView):
return super(SuntingProfilAdminView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(SuntingProfilAdminView, self).get_context_data(**kwargs)
context = super(SuntingProfilAdminView,
self).get_context_data(**kwargs)
return context
def get(self, request, *args, **kwargs):
......@@ -404,11 +427,12 @@ class SuksesLoginAdminView(TemplateView):
return self.render_to_response(context)
class CommentsView(TemplateView):
template_name = "comments.html"
def dispatch(self, request, *args, **kwargs):
if not request.user.pk == kwargs["pk_user"] :
if not request.user.pk == kwargs["pk_user"]:
raise PermissionDenied(request)
return super(CommentsView, self).dispatch(request, *args, **kwargs)
......@@ -416,7 +440,7 @@ class CommentsView(TemplateView):
context = super(CommentsView, self).get_context_data(**kwargs)
user = get_object_or_404(User, pk=kwargs["pk_user"])
users_materi = Materi.objects.filter(uploader=user)
numb_of_comments = 0
numb_of_comments = 0
qset_comments = Comment.objects.none()
for materi in users_materi:
materi_comments = Comment.objects.filter(materi=materi).count()
......
......@@ -83,6 +83,7 @@
.btn-admin {
margin-top: 20px;
margin-bottom: 20px;
}
.page-height {
......
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