Fakultas Ilmu Komputer UI

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

[REFACTOR]Update Category and verifications models for archived data after deletion

parent 81477841
......@@ -24,6 +24,7 @@ class CategoryForm(forms.ModelForm):
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"
field.widget.attrs["rows"] = "3"
else:
field.widget.attrs["placeholder"] = "Nama Kategori"
......@@ -80,9 +81,12 @@ class RegistrasiAdminForm(forms.ModelForm):
class PeriodForm(forms.Form):
period = forms.ChoiceField(choices=genereatePeriodeChoices(), label="Periode", required=False)
start_date = forms.DateField(widget=DateInput, label="Waktu mulai", required=False)
end_date = forms.DateField(widget=DateInput, label="Waktu selesai", required=False)
period = forms.ChoiceField(
choices=genereatePeriodeChoices(), label="Periode", required=False)
start_date = forms.DateField(
widget=DateInput, label="Waktu mulai", required=False)
end_date = forms.DateField(
widget=DateInput, label="Waktu selesai", required=False)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
......@@ -95,4 +99,3 @@ class PeriodForm(forms.Form):
self.helper.add_input(Submit('submit', 'Filter'))
# def get_date(self):
......@@ -344,6 +344,42 @@
</div>
</div>
</div>
<!-- DataTales Example -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6
class="m-0 font-weight-bold text-primary"
id="titleTabel"
>
{{ page_title }} Terhapus
</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table
class="table table-bordered"
id="dataTable"
aria-describedby="titleTabel"
>
<thead>
<tr>
<th scope="col">Item</th>
<th scope="col">Deskripsi</th>
</tr>
</thead>
<tbody>
{% for item in items_archived %}
<tr>
<th>{{item.title}} {{item.name}}</th>
<th>{{item.description}}</th>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
......
......@@ -843,8 +843,8 @@ class EditVerificationTest(TestCase):
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)
self.assertEqual(models.VerificationSetting.objects.get(
title="deletelah").archived, True)
def test_delete_verification_data_by_anonymous(self):
self.client.logout()
......@@ -925,8 +925,8 @@ class EditCategoryTest(TestCase):
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)
self.assertEqual(Category.objects.get(
name="deletelah").archived, True)
def test_delete_category_data_by_anonymous(self):
self.client.logout()
......
......@@ -10,6 +10,7 @@ from administration.models import VerificationReport, VerificationSetting
from administration.forms import CategoryForm, VerificationSettingForm, RegistrasiAdminForm, PeriodForm
from app.models import Category, Materi
from authentication.models import User
from datetime import datetime
# Create your views here.
......@@ -108,6 +109,8 @@ class VerificationSettingView(TemplateView):
self).get_context_data(**kwargs)
context["items"] = VerificationSetting.objects.filter(
archived=False)
context["items_archived"] = VerificationSetting.objects.filter(
archived=True)
context["page_title"] = "Point Verifikasi Materi"
return context
......@@ -137,7 +140,8 @@ class CategorySettingView(TemplateView):
def get_context_data(self, **kwargs):
context = super(CategorySettingView, self).get_context_data(**kwargs)
context["items"] = Category.objects.all()
context["items"] = Category.objects.filter(archived=False)
context["items_archived"] = Category.objects.filter(archived=True)
context["page_title"] = "Kategori Materi"
return context
......@@ -372,8 +376,13 @@ def delete_contributor(request, *args, **kwargs):
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()
queryObject = get_object_or_404(VerificationSetting,
pk=kwargs["pk_verification"])
queryObject.archived = True
queryObject.description = "Telah dihapus oleh " + \
request.user.name + " pada tanggal " + \
str(datetime.now().strftime("%m/%d/%Y, %H:%M:%S")) + "WIB"
queryObject.save()
messages.success(request, "Point verifikasi berhasil dihapus")
return HttpResponseRedirect("/administration/setting/verification/")
......@@ -383,8 +392,13 @@ def delete_category(request, *args, **kwargs):
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 " +
queryObject = get_object_or_404(Category,
pk=kwargs["pk_category"])
queryObject.archived = True
queryObject.description = "Telah dihapus oleh " + \
request.user.name + " pada tanggal " + \
str(datetime.now().strftime("%m/%d/%Y, %H:%M:%S")) + "WIB"
queryObject.save()
messages.success(request, "Kategori " +
category_name + " berhasil dihapus")
return HttpResponseRedirect("/administration/setting/category/")
# Generated by Django 3.0.3 on 2020-06-03 06:48
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0009_auto_20200518_2245'),
]
operations = [
migrations.AddField(
model_name='category',
name='archived',
field=models.BooleanField(default=False),
),
]
# Generated by Django 3.0.3 on 2020-06-03 06:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0010_category_archived'),
]
operations = [
migrations.AlterField(
model_name='category',
name='description',
field=models.TextField(default=''),
),
]
......@@ -22,7 +22,8 @@ def getRandomColor():
class Category(models.Model):
name = models.CharField(max_length=20)
description = models.CharField(max_length=20)
description = models.TextField(blank=False, default="")
archived = models.BooleanField(default=False, blank=False)
def __str__(self):
return self.name
......
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