Fakultas Ilmu Komputer UI

Commit 08286292 authored by ALIF AHSANIL SATRIA's avatar ALIF AHSANIL SATRIA
Browse files

Merge branch '1606882540-59' into 'master'

1606882540-59

See merge request !33
parents ea535f52 6e6f0135
Pipeline #22193 passed with stages
in 50 minutes and 37 seconds
# -*- coding: utf-8 -*-
# Generated by Django 1.11.17 on 2019-10-06 10:14
from __future__ import unicode_literals
import core.lib.validators
import core.models.accounts
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0017_merge_20191006_0134'),
]
operations = [
migrations.AddField(
model_name='student',
name='ui_ux_portofolio',
field=models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_student_ui_ux_portofolio_file_path, validators=[core.lib.validators.validate_document_file_extension]),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.17 on 2019-10-07 19:56
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('core', '0018_student_ui_ux_portofolio'),
('core', '0025_merge_20191008_0048'),
('core', '0025_merge_20191007_2124'),
]
operations = [
]
......@@ -25,6 +25,11 @@ def get_company_logo_file_path(instance, filename):
filename = "%s.%s" % (uuid.uuid4(), extension)
return os.path.join("company-logo/", filename)
def get_student_ui_ux_portofolio_file_path(instance, filename):
extension = filename.split('.')[-1].lower()
filename = "%s.%s" % (uuid.uuid4(), extension)
return os.path.join("student-ui-ux-portofolio/", filename)
def get_display_name(user, full_name=False):
"""
......@@ -67,12 +72,11 @@ class Student(models.Model):
photo = models.FileField(upload_to=get_student_photo_file_path, null=True, blank=True, validators=[validate_image_file_extension])
linkedin_url = models.URLField(max_length=200,blank=True, null=True)
region = models.CharField(max_length=30, blank=True, null=True)
ui_ux_portofolio = models.FileField(upload_to=get_student_ui_ux_portofolio_file_path, null=True, blank=True, validators=[validate_document_file_extension])
latest_work = models.CharField(max_length=100, blank=True, null=True)
latest_work_desc = models.TextField(blank=True, null=True)
intro = models.CharField(max_length=50, blank=True, null=True)
intro = models.CharField(max_length=50, blank=True, null=True)
@property
def name(self):
return get_display_name(self.user)
......
......@@ -180,6 +180,15 @@ class ProfileUpdateTests(APITestCase):
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
url = '/api/students/' + str(student_id) + "/profile/"
data = self._create_test_file('./assets/pdf/pdf-coba.pdf')
response = self.client.patch(url, data, format='multipart')
self.assertEqual(response.status_code, status.HTTP_200_OK)
url = '/api/students/' + str(student_id) + "/profile/"
data = self._create_test_file('./assets/img/image-coba.jpg')
response = self.client.patch(url, data, format='multipart')
self.assertEqual(response.status_code, status.HTTP_415_UNSUPPORTED_MEDIA_TYPE)
response = self.client.patch(url, {'latest_work': 'Teaching assistant at Fasilkom UI'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('latest_work'), 'Teaching assistant at Fasilkom UI')
......@@ -193,3 +202,7 @@ class ProfileUpdateTests(APITestCase):
response = self.client.patch(url, {'intro': 'Saya tertarik dengan dunia front-end development'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('intro'), 'Saya tertarik dengan dunia front-end development')
def _create_test_file(self,path):
f = open(path, 'r')
return {'pdf_file': f}
......@@ -63,12 +63,20 @@ class StudentViewSet(viewsets.ModelViewSet):
---
"""
user = self.get_object()
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)
if 'pdf_file' in request.data.keys():
if request.data['pdf_file'].content_type == 'application/pdf':
user.ui_ux_portofolio = request.data['pdf_file']
user.save()
return Response({}, status=status.HTTP_200_OK)
else:
return Response({}, status=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
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:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
@detail_route(methods=['get'], permission_classes=[IsAdminOrStudent])
def transcript(self, request, pk):
......
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