Fakultas Ilmu Komputer UI

Commit 84009dcc authored by Ahmad Fauzan Amirul Isnain's avatar Ahmad Fauzan Amirul Isnain
Browse files

[#130] QA: Fix Code Smells Detected by Sonarqube

parent a980e90a
......@@ -18,7 +18,7 @@ BASE_PERIODE = [
]
def genereatePeriodeChoices():
def generate_periode_choices():
periode = BASE_PERIODE
now = timezone.now()
# Month
......
......@@ -3,7 +3,7 @@ from crispy_forms.layout import Layout, Submit, Row, Column, Reset, ButtonHolder
from crispy_forms.bootstrap import InlineCheckboxes
from django import forms
from administration.choices import genereatePeriodeChoices
from administration.choices import generate_periode_choices
from administration.models import VerificationSetting
from app.models import Category
from authentication.models import User
......@@ -88,7 +88,7 @@ class RegistrasiAdminForm(forms.ModelForm):
class PeriodForm(forms.Form):
period = forms.ChoiceField(
choices=genereatePeriodeChoices(), label="Periode", required=False)
choices=generate_periode_choices(), label="Periode", required=False)
start_date = forms.DateField(
widget=DateInput, label="Waktu mulai", required=False)
end_date = forms.DateField(
......@@ -102,14 +102,16 @@ class PeriodForm(forms.Form):
for field_name, field in self.fields.items():
field.widget.attrs['class'] = 'form-control'
period_css_class = 'form-group col-md-4 mb-0'
self.helper = FormHelper()
self.helper.attrs["name"] = "filter-form"
self.helper.form_method = 'get'
self.helper.layout = Layout(
Row(
Column('period', css_class='form-group col-md-4 mb-0'),
Column('start_date', css_class='form-group col-md-4 mb-0'),
Column('end_date', css_class='form-group col-md-4 mb-0'),
Column('period', css_class=period_css_class),
Column('start_date', css_class=period_css_class),
Column('end_date', css_class=period_css_class),
css_class='form-row'
),
InlineCheckboxes('categories'),
......@@ -130,10 +132,9 @@ class PeriodForm(forms.Form):
if start_date is None and end_date is not None:
self.add_error("start_date",
"masukan waktu mulai")
if start_date is not None and end_date is not None:
if start_date > end_date:
self.add_error("end_date",
"waktu selesai sebelum waktu mulai")
if start_date is not None and end_date is not None and start_date > end_date:
self.add_error("end_date",
"waktu selesai sebelum waktu mulai")
class EditAdminStatusForm(forms.ModelForm):
......
......@@ -97,20 +97,6 @@
<!-- Card Header - Dropdown -->
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<h6 class="m-0 font-weight-bold text-primary">Statistik</h6>
<!-- <div class="dropdown no-arrow">
<a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<em class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400"></em>
</a>
<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in"
aria-labelledby="dropdownMenuLink">
<div class="dropdown-header">Dropdown Header:</div>
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div> -->
</div>
<!-- Card Body -->
<div class="card-body" style="overflow:auto!important; display:inline-block!important; height: 750px;">
......@@ -128,7 +114,7 @@
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTableRiwayat" width="100%" cellspacing="0"
<table class="table table-bordered" id="dataTableRiwayat"
aria-describedby="titleTabelRiwayat">
<thead>
<tr>
......
......@@ -17,7 +17,7 @@
</div>
<div class="card-body">
<div class="table-responsive">
<table aria-describedby="table-description" class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<table aria-describedby="table-description" class="table table-bordered" id="dataTable">
<thead>
<tr>
<th scope="col">Nama</th>
......
......@@ -21,7 +21,7 @@
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<table class="table table-bordered" id="dataTable">
<thead>
<tr>
<th scope="col">Judul</th>
......
......@@ -186,7 +186,7 @@
</div>
<div class="card-body">
<div class="table-responsive">
<table aria-describedby="table-description" class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<table aria-describedby="table-description" class="table table-bordered" id="dataTable">
<thead>
<tr>
<th scope="col">Judul Verifikasi</th>
......@@ -235,29 +235,6 @@
<em class="fas fa-angle-up"></em>
</a>
<!-- <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>
<script src="https://code.jquery.com/jquery-3.5.0.min.js"
integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=" crossorigin="anonymous"></script>
<script src="{% static 'js/sb-admin-2.min.js' %}"></script>
<script src="{% static 'vendor/datatables/jquery.dataTables.min.js' %}"></script>
<script src="{% static 'vendor/datatables/dataTables.bootstrap4.min.js' %}"></script>
<script src="{% static 'js/demo/datatables-demo.js' %}"></script> -->
</body>
</html>
\ No newline at end of file
......@@ -61,7 +61,7 @@
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTableRiwayat" width="100%" cellspacing="0" aria-describedby="titleTabelRiwayat">
<table class="table table-bordered" id="dataTableRiwayat" aria-describedby="titleTabelRiwayat">
<thead>
<tr>
<th scope="col">Judul Materi</th>
......
......@@ -19,6 +19,8 @@ from django.core import management
ADMINISTRATION_MANAGEMENT = "/administration/kelola-admin/"
ADMINISTRATION_REPORT = "/administration/laporan-materi/"
ADMINISTRATION_VERIFICATION_SETTING = "/administration/setting/verification/"
ADMINISTRATION_CATEGORY_SETTING = "/administration/setting/category/"
class VerificationView(TemplateView):
......@@ -115,7 +117,7 @@ class VerificationSettingView(TemplateView):
form = VerificationSettingForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect("/administration/setting/verification/")
return HttpResponseRedirect(ADMINISTRATION_VERIFICATION_SETTING)
else:
context = self.get_context_data(**kwargs)
context["form"] = form
......@@ -146,7 +148,7 @@ class CategorySettingView(TemplateView):
form = CategoryForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect("/administration/setting/category/")
return HttpResponseRedirect(ADMINISTRATION_CATEGORY_SETTING)
else:
context = self.get_context_data(**kwargs)
context["form"] = form
......@@ -351,7 +353,7 @@ class EditVerificationView(TemplateView):
request.POST, instance=verification_object)
if form.is_valid():
form.save()
return HttpResponseRedirect("/administration/setting/verification/")
return HttpResponseRedirect(ADMINISTRATION_VERIFICATION_SETTING)
else:
context = self.get_context_data(**kwargs)
context["form"] = form
......@@ -383,7 +385,7 @@ class EditCategoryView(TemplateView):
request.POST, instance=category_object)
if form.is_valid():
form.save()
return HttpResponseRedirect("/administration/setting/category/")
return HttpResponseRedirect(ADMINISTRATION_CATEGORY_SETTING)
else:
context = self.get_context_data(**kwargs)
context["form"] = form
......@@ -483,15 +485,15 @@ 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)
queryObject = get_object_or_404(VerificationSetting,
query_object = get_object_or_404(VerificationSetting,
pk=kwargs["pk_verification"])
queryObject.archived = True
queryObject.description = "Telah dihapus pada " + \
query_object.archived = True
query_object.description = "Telah dihapus pada " + \
str(timezone.now().strftime("%m/%d/%Y, %H:%M:%S")) + " WIB"
queryObject.archived_by = request.user
queryObject.save()
query_object.archived_by = request.user
query_object.save()
messages.success(request, "Point verifikasi berhasil dihapus")
return HttpResponseRedirect("/administration/setting/verification/")
return HttpResponseRedirect(ADMINISTRATION_VERIFICATION_SETTING)
def delete_category(request, *args, **kwargs):
......@@ -499,16 +501,16 @@ def delete_category(request, *args, **kwargs):
raise PermissionDenied(request)
category_name = get_object_or_404(Category,
pk=kwargs["pk_category"]).name
queryObject = get_object_or_404(Category,
query_object = get_object_or_404(Category,
pk=kwargs["pk_category"])
queryObject.archived = True
queryObject.description = "Telah dihapus pada " + \
query_object.archived = True
query_object.description = "Telah dihapus pada " + \
str(timezone.now().strftime("%m/%d/%Y, %H:%M:%S")) + " WIB"
queryObject.archived_by = request.user
queryObject.save()
query_object.archived_by = request.user
query_object.save()
messages.success(request, "Kategori " +
category_name + " berhasil dihapus")
return HttpResponseRedirect("/administration/setting/category/")
return HttpResponseRedirect(ADMINISTRATION_CATEGORY_SETTING)
def generatedummy(request):
if request.user.is_authenticated is False or request.user.is_admin is False:
......
......@@ -10,7 +10,6 @@ def year_choices():
class UploadMateriForm(forms.ModelForm):
categories = forms.ModelMultipleChoiceField(queryset=Category.objects.all(),widget=forms.CheckboxSelectMultiple(attrs={'style' : 'column-count:2'}),required=True)
#categories.widget.attrs["style"] = "column-count:2"
release_year = forms.TypedChoiceField(coerce=int, choices=year_choices, initial=datetime.date.today().year)
yt_video_id = forms.CharField(label="Youtube Video Id", \
help_text="This is not required.<br>\
......
......@@ -24,7 +24,7 @@ class Command(BaseCommand):
counter = 0
category_name = f"Kategori dummy {counter}"
dummy_category = []
for i in range(num_of_category):
for _ in range(num_of_category):
while (Category.objects.filter(name=category_name).exists()):
counter += 1
category_name = f"Kategori dummy {counter}"
......@@ -38,7 +38,7 @@ class Command(BaseCommand):
counter = 0
criterion_name = f"Kriteria dummy {counter}"
dummy_criteria = []
for i in range(num_of_criteria):
for _ in range(num_of_criteria):
while (VerificationSetting.objects.filter(title=criterion_name).exists()):
counter += 1
criterion_name = f"Kriteria dummy {counter}"
......@@ -67,8 +67,7 @@ class Command(BaseCommand):
counter = 0
dummy_user = []
email = f"admin-dummy-{counter}@email.com"
end_date = timezone.now()
for i in range(num_of_user):
for _ in range(num_of_user):
while (User.objects.filter(email=email).exists()):
counter += 1
email = f"admin-dummy-{counter}@email.com"
......@@ -140,8 +139,6 @@ class Command(BaseCommand):
verif_report = VerificationReport(
report=report_field, materi=materi, user=admin, status=materi.get_status_display(), timestamp=timestamp)
verif_report.save()
else:
pass
return materi
......
......@@ -42,53 +42,45 @@
Registrasi Kontributor
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<!-- <input class="input100" type="text" name="nama"> -->
{{ form.name }}
<span class="focus-input100"></span>
<span class="label-input100">Nama</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Password is required">
<!-- <input class="input100" type="text" name="pekerjaan"> -->
{{ form.instansi }}
<span class="focus-input100"></span>
<span class="label-input100">Instansi/Pekerjaan</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<!-- <input class="input100" type="text" name="nama"> -->
{{ form.nik.errors }}
{{ form.nik }}
<span class="focus-input100"></span>
<span class="label-input100">NIK</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<!-- <input class="input100" type="text" name="nama"> -->
{{ form.alamat }}
<span class="focus-input100"></span>
<span class="label-input100">Alamat</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<!-- <input class="input100" type="text" name="nama"> -->
{{ form.email.errors }}
{{ form.email }}
<span class="focus-input100"></span>
<span class="label-input100">Email</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<!-- <input class="input100" type="text" name="nama"> -->
{{ form.nomor_telpon.errors}}
{{ form.nomor_telpon }}
<span class="focus-input100"></span>
<span class="label-input100">Nomor Telepon</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<!-- <input class="input100" type="text" name="nama"> -->
{{ form.password.errors }}
{{ form.password }}
<span class="focus-input100"></span>
<span class="label-input100">Kata Sandi</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<!-- <input class="input100" type="text" name="nama"> -->
{{ form.password2 }}
<span class="focus-input100"></span>
<span class="label-input100">Ketik Ulang Kata Sandi</span>
......
......@@ -42,7 +42,6 @@
Registrasi Umum
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<!-- <input class="input100" type="text" name="nama"> -->
{{ form.name }}
<span class="focus-input100"></span>
<span class="label-input100">Nama</span>
......@@ -54,41 +53,35 @@
<span class="label-input100">Instansi/Pekerjaan</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<!-- <input class="input100" type="text" name="nama"> -->
{{ form.nik.errors }}
{{ form.nik }}
<span class="focus-input100"></span>
<span class="label-input100">NIK</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<!-- <input class="input100" type="text" name="nama"> -->
{{ form.alamat }}
<span class="focus-input100"></span>
<span class="label-input100">Alamat</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<!-- <input class="input100" type="text" name="nama"> -->
{{ form.email.errors }}
{{ form.email }}
<span class="focus-input100"></span>
<span class="label-input100">Email</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<!-- <input class="input100" type="text" name="nama"> -->
{{ form.nomor_telpon.errors}}
{{ form.nomor_telpon }}
<span class="focus-input100"></span>
<span class="label-input100">Nomor Telepon</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<!-- <input class="input100" type="text" name="nama"> -->
{{ form.password.errors }}
{{ form.password }}
<span class="focus-input100"></span>
<span class="label-input100">Kata Sandi</span>
</div>
<div class="wrap-input100 validate-input" data-validate="Valid email is required: ex@abc.xyz">
<!-- <input class="input100" type="text" name="nama"> -->
{{ form.password2 }}
<span class="focus-input100"></span>
<span class="label-input100">Ketik Ulang Kata Sandi</span>
......
......@@ -29,11 +29,11 @@ class RegisterPageTest(TestCase):
def test_status_using_index_func(self):
# Positive tests
found = resolve("/registrasi/")
self.assertEqual(found.func.__name__, views.index.__name__)
self.assertEqual(found.func.__name__, views.Index.__name__)
# Negative tests
found = resolve("/admin/")
self.assertNotEqual(found.func, views.index)
self.assertNotEqual(found.func, views.Index)
def test_register_title(self):
response = Client().get("/registrasi/")
......@@ -628,7 +628,7 @@ class RegisterPublicTest(TestCase):
# Negative tests
found = resolve("/admin/")
self.assertNotEqual(found.func, views.index)
self.assertNotEqual(found.func, views.Index)
def test_register_title(self):
response = Client().get(self.reg_path)
......
......@@ -5,7 +5,7 @@ from . import views
app_name = "register"
urlpatterns = [
path("", views.index.as_view()),
path("", views.Index.as_view()),
path("umum/", views.RegistrasiUmum.as_view()),
path("admin/", views.RegistrasiAdmin.as_view()),
path("verify-email/<str:token>", views.verify_email, name='verify-email'),
......
......@@ -9,12 +9,14 @@ from django.db import models
from django.http import HttpResponseRedirect
from django.views.generic import TemplateView
from django.core.exceptions import PermissionDenied
from django.core.exceptions import ValidationError
from register.forms import UserForm
from register.services import RegistrationService
class index(TemplateView):
class Index(TemplateView):
template_name = "index.html"
def get_context_data(self, **kwargs):
......@@ -134,7 +136,7 @@ def verify_email(request, token):
return render(request, template_name, {
'message': f'Link verifikasi telah expire'
})
except:
except (User.DoesNotExist, ValidationError):
return render(request, template_name, {
'message': f'Email gagal diverifikasi'
})
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