Fakultas Ilmu Komputer UI

Commit a1e22c70 authored by Aldo Bima Syahputra's avatar Aldo Bima Syahputra
Browse files

1606833463 217 - Membuat validasi input skor toefl pada halaman edit profile

parent 11c594c2
......@@ -27,6 +27,10 @@ def validate_student_gpa(value):
if value < 0 or value > 4:
raise ValidationError(u"GPA harus merupakan angka antara 0-4")
def validate_toefl_score(value):
if value < 0 or value >677:
raise ValidationError(u"skor toefl harus merupakan angka antara 0-677")
def validate_npm(value):
"""
......
# Generated by Django 2.2.8 on 2019-12-05 04:16
# Generated by Django 2.2.8 on 2019-12-06 12:07
import core.lib.validators
import core.models.accounts
......@@ -32,11 +32,12 @@ class Migration(migrations.Migration):
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('description', models.TextField()),
('founded', models.DateField(blank=True, null=True)),
('status', models.IntegerField(default=0, validators=[django.core.validators.MaxValueValidator(2), django.core.validators.MinValueValidator(0)])),
('logo', models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_company_logo_file_path, validators=[core.lib.validators.validate_image_file_extension])),
('address', models.CharField(blank=True, max_length=1000, null=True)),
('category', models.CharField(default='Belum ada kategori perusahaan', max_length=140)),
('size', models.CharField(blank=True, default=0, max_length=10, null=True)),
('size', models.IntegerField(default=1, validators=[django.core.validators.MinValueValidator(1)])),
('website', models.CharField(default='Belum ada link website', max_length=100)),
('linkedin_url', models.URLField(blank=True, null=True)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
......@@ -150,7 +151,7 @@ class Migration(migrations.Migration):
('expected_salary', models.CharField(blank=True, max_length=10, null=True, validators=[django.core.validators.RegexValidator('^\\d{0,10}$')])),
('job_seeking_status', models.CharField(blank=True, max_length=30, null=True)),
('student_gpa', models.FloatField(blank=True, db_column='student_gpa', default=1.0, null=True, validators=[core.lib.validators.validate_student_gpa])),
('student_toefl', models.IntegerField(blank=True, db_column='toefl', default=0, null=True)),
('student_toefl', models.IntegerField(blank=True, db_column='toefl', default=0, null=True, validators=[core.lib.validators.validate_toefl_score])),
('student_toefl_file', models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_student_toefl_file_path, validators=[django.core.validators.FileExtensionValidator(['pdf'])])),
('volunteer', models.CharField(blank=True, max_length=100, null=True)),
('awards', models.CharField(blank=True, max_length=100, null=True)),
......@@ -161,6 +162,7 @@ class Migration(migrations.Migration):
('interests', models.CharField(blank=True, max_length=100, null=True)),
('dependants', models.IntegerField(blank=True, db_column='dependants', default=0, null=True)),
('related_course', models.CharField(blank=True, max_length=200, null=True)),
('ielts', models.FloatField(blank=True, db_column='ielts', default=1.0, null=True)),
('applied_vacancies', models.ManyToManyField(blank=True, related_name='applied_vacancies', through='core.Application', to='core.Vacancy')),
('bookmarked_vacancies', models.ManyToManyField(blank=True, related_name='bookmarked_vacancies', to='core.Vacancy')),
('recommendations', models.ManyToManyField(blank=True, related_name='recommendations', to='core.Recommendation')),
......
# Generated by Django 2.2.8 on 2019-12-06 03:44
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='student',
name='ielts',
field=models.FloatField(blank=True, db_column='ielts', default=1.0, null=True),
),
]
# Generated by Django 2.2.8 on 2019-12-06 08:01
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0002_student_ielts'),
]
operations = [
migrations.AddField(
model_name='company',
name='founded',
field=models.DateTimeField(blank=True, null=True),
),
]
# Generated by Django 2.2.8 on 2019-12-06 08:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0003_company_founded'),
]
operations = [
migrations.AlterField(
model_name='company',
name='founded',
field=models.DateField(blank=True, null=True),
),
]
# Generated by Django 2.2.8 on 2019-12-06 09:34
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0004_auto_20191206_1510'),
]
operations = [
migrations.AlterField(
model_name='company',
name='size',
field=models.IntegerField(default=1, validators=[django.core.validators.MinValueValidator(1)]),
),
]
......@@ -7,7 +7,7 @@ from django.core.validators import MinValueValidator, MaxValueValidator, RegexVa
from django.db import models
from core.lib.validators import validate_document_file_extension, validate_image_file_extension, validate_npm, \
validate_student_gpa
validate_student_gpa, validate_toefl_score
def get_student_resume_file_path(instance, filename):
......@@ -116,7 +116,7 @@ class Student(models.Model):
job_seeking_status = models.CharField(max_length=30, blank=True, null=True)
student_gpa = models.FloatField(db_column='student_gpa', default=1.0, blank=True, null=True,
validators=[validate_student_gpa])
student_toefl = models.IntegerField(db_column='toefl', default=0, blank=True, null=True)
student_toefl = models.IntegerField(db_column='toefl', default=0, blank=True, null=True, validators=[validate_toefl_score])
student_toefl_file = models.FileField(upload_to=get_student_toefl_file_path, null=True, blank=True,
validators=[FileExtensionValidator(['pdf'])])
volunteer = models.CharField(max_length=100, blank=True, null=True)
......@@ -129,7 +129,7 @@ class Student(models.Model):
dependants = models.IntegerField(db_column='dependants', default=0, blank=True, null=True)
related_course = models.CharField(max_length=200, blank=True, null=True)
ielts = models.FloatField(db_column='ielts', default=1.0, blank=True, null=True)
@property
def name(self):
return get_display_name(self.user)
......
......@@ -337,6 +337,22 @@ class ProfileUpdateTests(APITestCase):
response = self.client.patch(url, {'student_gpa': '8'}, format='multipart', encoding='utf-8')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
url = '/api/students/' + str(student_id) + "/profile/"
response = self.client.patch(url, {'student_toefl': '0'}, format='multipart', encoding='utf-8')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
url = '/api/students/' + str(student_id) + "/profile/"
response = self.client.patch(url, {'student_toefl': '677'}, format='multipart', encoding='utf-8')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
url = '/api/students/' + str(student_id) + "/profile/"
response = self.client.patch(url, {'student_toefl': '-1'}, format='multipart', encoding='utf-8')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
url = '/api/students/' + str(student_id) + "/profile/"
response = self.client.patch(url, {'student_toefl': '678'}, format='multipart', encoding='utf-8')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
response = self.client.patch(url, {'interests': 'Machine Learning'}, format='multipart', encoding='utf-8')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('interests'), 'Machine Learning')
......
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