Fakultas Ilmu Komputer UI

Commit d7f02f1f authored by Yumna Pratista Tastaftian's avatar Yumna Pratista Tastaftian
Browse files

1606836976 65

parent 00836819
# -*- coding: utf-8 -*-
# Generated by Django 1.11.17 on 2019-10-12 12:21
# Generated by Django 1.11.17 on 2019-10-12 14:46
from __future__ import unicode_literals
import core.lib.validators
......@@ -65,6 +65,7 @@ class Migration(migrations.Migration):
('updated', models.DateTimeField(auto_now=True)),
('npm', models.IntegerField(unique=True, validators=[core.lib.validators.validate_npm])),
('resume', models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_student_resume_file_path, validators=[core.lib.validators.validate_document_file_extension])),
('sertifikat', models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_student_sertifikat_file_path, validators=[core.lib.validators.validate_document_file_extension])),
('phone_number', models.CharField(blank=True, db_index=True, max_length=100, null=True, validators=[django.core.validators.RegexValidator('^0\\d{1,11}$')])),
('gender', models.CharField(blank=True, max_length=30, null=True)),
('birth_place', models.CharField(blank=True, max_length=30, null=True)),
......
......@@ -55,6 +55,11 @@ def get_display_name(user, full_name=False):
return name.strip()
def get_student_sertifikat_file_path(instance, filename):
extension = filename.split('.')[-1].lower()
filename = "%s.%s" % (uuid.uuid4(), extension)
return os.path.join("student-sertifikat/", filename)
class Student(models.Model):
"""
......@@ -65,6 +70,7 @@ class Student(models.Model):
user = models.OneToOneField(User)
npm = models.IntegerField(validators=[validate_npm], unique=True)
resume = models.FileField(upload_to=get_student_resume_file_path, null=True, blank=True, validators=[validate_document_file_extension])
sertifikat = models.FileField(upload_to=get_student_sertifikat_file_path, null=True, blank=True, validators=[validate_document_file_extension])
phone_number = models.CharField(max_length=100, blank=True, db_index=True, null=True, validators=[RegexValidator(r'^0\d{1,11}$')])
gender = models.CharField(max_length=30, blank=True, null=True)
bookmarked_vacancies = models.ManyToManyField('core.Vacancy', related_name="bookmarked_vacancies", blank=True)
......
......@@ -122,6 +122,11 @@ class RegisterTests(APITestCase):
class ProfileUpdateTests(APITestCase):
def _create_test_file_pdf(self,path):
file = open(path, 'rb')
return {'pdf_sertifikat':file}
@requests_mock.Mocker()
def test_student_profile_update(self, m):
m.get('https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={"username": 'dummy.mahasiswa', "role": 'mahasiswa', "identity_number": '1234567890'}, status_code=200)
......@@ -246,6 +251,16 @@ class ProfileUpdateTests(APITestCase):
self.assertEqual(response.data.get('intro'), 'Saya tertarik dengan dunia front-end development')
url = '/api/students/' + str(student_id) + "/profile/"
data = self._create_test_file_pdf('./assets/img/UI.png')
response = self.client.patch(url, data, format='multipart')
self.assertEqual(response.status_code, status.HTTP_415_UNSUPPORTED_MEDIA_TYPE)
url = '/api/students/' + str(student_id) + "/profile/"
data = self._create_test_file_pdf('./assets/pdf/pdf_coba.PDF')
response = self.client.patch(url, data, format='multipart')
self.assertEqual(response.status_code, status.HTTP_200_OK)
response = self.client.patch(url, {'expected_salary': '4000000'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('expected_salary'), '4000000')
......
......@@ -63,6 +63,14 @@ class StudentViewSet(viewsets.ModelViewSet):
---
"""
user = self.get_object()
if 'pdf_sertifikat' in request.data.keys():
if request.data['pdf_sertifikat'].content_type == 'application/pdf':
user.sertifikat = request.data['pdf_sertifikat']
user.save()
return Response({}, status=status.HTTP_200_OK)
else:
return Response({}, status=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE)
if 'pdf_file' in request.data.keys():
if request.data['pdf_file'].content_type == 'application/pdf':
user.ui_ux_portofolio = request.data['pdf_file']
......@@ -70,6 +78,11 @@ class StudentViewSet(viewsets.ModelViewSet):
return Response({}, status=status.HTTP_200_OK)
else:
return Response({}, status=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE)
serializer = self.serializer_class(user, data=request.data, partial=True)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_202_ACCEPTED)
else:
serializer = self.serializer_class(user, data=request.data, partial=True)
if serializer.is_valid():
......
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