Fakultas Ilmu Komputer UI

Commit 6ec41816 authored by ALIF AHSANIL SATRIA's avatar ALIF AHSANIL SATRIA
Browse files

add implementation to pass the test

parent 6a8d2ba2
Pipeline #21977 failed with stages
in 175 minutes and 8 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]),
),
]
......@@ -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):
"""
......@@ -66,7 +71,7 @@ class Student(models.Model):
show_transcript = models.BooleanField(default=False)
photo = models.FileField(upload_to=get_student_photo_file_path, null=True, blank=True, validators=[validate_image_file_extension])
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])
@property
def name(self):
return get_display_name(self.user)
......
......@@ -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