Fakultas Ilmu Komputer UI

Commit 2a386125 authored by Izzan Fakhril Islam's avatar Izzan Fakhril Islam
Browse files

[Sprint 2] Fitur menyimpan rekomendasi dari pihak lain di serializer milik mahasiswa

parent dff304e4
# -*- coding: utf-8 -*-
# Generated by Django 1.11.17 on 2019-11-15 20:12
# Generated by Django 1.11.17 on 2019-11-16 08:22
from __future__ import unicode_literals
import core.lib.validators
......@@ -37,9 +37,9 @@ class Migration(migrations.Migration):
('status', models.IntegerField(default=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)),
('category', models.CharField(default=b'Belum ada kategori perusahaan', max_length=140)),
('size', models.CharField(blank=True, default=0, max_length=10, null=True)),
('website', models.CharField(default='Belum ada link website', max_length=100)),
('website', models.CharField(default=b'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)),
],
......@@ -52,7 +52,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateTimeField(auto_now_add=True)),
('title', models.CharField(blank=True, default='', max_length=100)),
('title', models.CharField(blank=True, default=b'', max_length=100)),
('content', models.TextField()),
('companyId', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='core.Company')),
],
......@@ -60,6 +60,18 @@ class Migration(migrations.Migration):
'ordering': ['created'],
},
),
migrations.CreateModel(
name='Recommendation',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content', models.TextField()),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
],
options={
'ordering': ['-updated'],
},
),
migrations.CreateModel(
name='Student',
fields=[
......@@ -67,16 +79,16 @@ class Migration(migrations.Migration):
('created', models.DateTimeField(auto_now_add=True)),
('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=[django.core.validators.FileExtensionValidator(['pdf'])])),
('resume', models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_student_resume_file_path, validators=[django.core.validators.FileExtensionValidator([b'pdf'])])),
('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}$')])),
('phone_number', models.CharField(blank=True, db_index=True, max_length=100, null=True, validators=[django.core.validators.RegexValidator(b'^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)),
('birth_date', models.DateField(blank=True, null=True)),
('major', models.CharField(blank=True, max_length=30, null=True)),
('batch', models.CharField(blank=True, max_length=4, null=True)),
('show_transcript', models.BooleanField(default=False)),
('photo', models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_student_photo_file_path, validators=[django.core.validators.FileExtensionValidator(['jpg', 'jpeg', 'png'])])),
('photo', models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_student_photo_file_path, validators=[django.core.validators.FileExtensionValidator([b'jpg', b'jpeg', b'png'])])),
('self_description', models.CharField(blank=True, db_index=True, max_length=500, null=True)),
('portfolio_link', models.URLField(blank=True, null=True)),
('linkedin_url', models.URLField(blank=True, null=True)),
......@@ -86,16 +98,15 @@ class Migration(migrations.Migration):
('region', models.CharField(blank=True, max_length=30, null=True)),
('alamat', models.CharField(blank=True, max_length=50, null=True)),
('skills', models.CharField(blank=True, max_length=50, null=True)),
('recommendations', models.CharField(blank=True, max_length=500, null=True)),
('ui_ux_portofolio', 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])),
('latest_work', models.CharField(blank=True, max_length=100, null=True)),
('latest_work_desc', models.TextField(blank=True, null=True)),
('github_url', models.URLField(blank=True, null=True)),
('gitlab_url', models.URLField(blank=True, null=True)),
('intro', models.CharField(blank=True, max_length=50, null=True)),
('expected_salary', models.CharField(blank=True, max_length=10, null=True, validators=[django.core.validators.RegexValidator('^\\d{0,10}$')])),
('expected_salary', models.CharField(blank=True, max_length=10, null=True, validators=[django.core.validators.RegexValidator(b'^\\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_gpa', models.FloatField(blank=True, db_column=b'student_gpa', default=1.0, null=True, validators=[core.lib.validators.validate_student_gpa])),
('volunteer', models.CharField(blank=True, max_length=100, null=True)),
('awards', models.CharField(blank=True, max_length=100, null=True)),
('projects', models.CharField(blank=True, max_length=100, null=True)),
......@@ -103,7 +114,7 @@ class Migration(migrations.Migration):
('languages', models.CharField(blank=True, max_length=100, null=True)),
('seminar', models.CharField(blank=True, max_length=100, null=True)),
('interests', models.CharField(blank=True, max_length=100, null=True)),
('dependants', models.IntegerField(blank=True, db_column='dependants', default=0, null=True)),
('dependants', models.IntegerField(blank=True, db_column=b'dependants', default=0, null=True)),
],
options={
'ordering': ['-updated'],
......@@ -163,7 +174,7 @@ class Migration(migrations.Migration):
name='ReasonRejected',
fields=[
('application', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='core.Application')),
('reason', models.TextField(default='Tidak memenuhi kualifikasi perusahaan.')),
('reason', models.TextField(default=b'Tidak memenuhi kualifikasi perusahaan.')),
],
),
migrations.AddField(
......@@ -176,11 +187,26 @@ class Migration(migrations.Migration):
name='bookmarked_vacancies',
field=models.ManyToManyField(blank=True, related_name='bookmarked_vacancies', to='core.Vacancy'),
),
migrations.AddField(
model_name='student',
name='recommendations',
field=models.ManyToManyField(blank=True, related_name='recommendations', to='core.Recommendation'),
),
migrations.AddField(
model_name='student',
name='user',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='recommendation',
name='recommendation_giver',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='giver', to='core.Student'),
),
migrations.AddField(
model_name='recommendation',
name='recommendation_receiver',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='receiver', to='core.Student'),
),
migrations.AddField(
model_name='feedback',
name='studentId',
......@@ -196,6 +222,10 @@ class Migration(migrations.Migration):
name='vacancy',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Vacancy'),
),
migrations.AlterUniqueTogether(
name='recommendation',
unique_together=set([('recommendation_giver', 'recommendation_receiver')]),
),
migrations.AlterUniqueTogether(
name='application',
unique_together=set([('student', 'vacancy')]),
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.17 on 2019-11-16 08:50
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='recommendation',
name='content',
field=models.TextField(blank=True),
),
migrations.AlterField(
model_name='recommendation',
name='recommendation_giver',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='giver', to='core.Student'),
),
migrations.AlterField(
model_name='recommendation',
name='recommendation_receiver',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='receiver', to='core.Student'),
),
]
......@@ -5,3 +5,5 @@ from core.models.accounts import Supervisor
from core.models.vacancies import Vacancy
from core.models.vacancies import Application
from core.models.vacancies import VacancyMilestone
from core.models.recommendations import Recommendation
# from core.models.feedbacks import Feedback
......@@ -91,7 +91,7 @@ class Student(models.Model):
region = models.CharField(max_length=30, blank=True, null=True)
alamat = models.CharField(max_length=50, blank=True, null=True)
skills = models.CharField(max_length=50, blank=True, null=True)
recommendations = models.CharField(max_length=500, blank=True, null=True)
recommendations = models.ManyToManyField('core.Recommendation', related_name="recommendations", blank=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)
......
from django.db import models
from core.models.accounts import get_display_name
from core.models.accounts import Student
class Recommendation(models.Model):
recommendation_giver = models.ForeignKey('core.Student', related_name='giver', null=True, on_delete=models.CASCADE)
recommendation_receiver = models.ForeignKey('core.Student', related_name='receiver', null=True, on_delete=models.CASCADE)
content = models.TextField(blank=True)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
@property
def name(self):
return "Recommendation from {} to {}".format(get_display_name(self.recommendation_giver.user), get_display_name(self.recommendation_receiver.user))
def __unicode__(self):
return u"Recommendation from {} to {}".format(get_display_name(self.recommendation_giver.user), get_display_name(self.recommendation_receiver.user))
class Meta:
unique_together = (("recommendation_giver", "recommendation_receiver"),)
ordering = ['-updated']
......@@ -20,7 +20,7 @@ class StudentSerializer(serializers.ModelSerializer):
class Meta:
model = Student
fields = ['id', 'name', 'full_name', 'user', 'npm', 'resume', 'phone_number', 'gender', 'birth_place', 'birth_date', 'major', 'batch',
'show_transcript', 'photo', 'accepted_no', 'linkedin_url', 'hackerrank_url', 'region', 'intro', 'portfolio_link', 'website_url', 'student_gpa', 'age', 'recommendations',
'show_transcript', 'photo', 'accepted_no', 'linkedin_url', 'hackerrank_url', 'region', 'intro', 'portfolio_link', 'website_url', 'student_gpa', 'age',
'work_experience', 'latest_work', 'latest_work_desc', 'read_no', 'volunteer', 'job_seeking_status', 'skills', 'expected_salary',
'self_description', 'github_url', 'gitlab_url', 'awards', 'certification', 'languages', 'seminar', 'interests', 'alamat', 'projects', 'dependants']
......@@ -63,7 +63,6 @@ class StudentUpdateSerializer(serializers.ModelSerializer):
'volunteer': instance.volunteer,
'linkedin_url': instance.linkedin_url,
'hackerrank_url': instance.hackerrank_url,
'recommendations': instance.recommendations,
'work_experience': instance.work_experience,
'latest_work': instance.latest_work,
'latest_work_desc': instance.latest_work_desc,
......@@ -98,7 +97,6 @@ class StudentUpdateSerializer(serializers.ModelSerializer):
instance.volunteer = validated_data.get('volunteer', instance.volunteer)
instance.linkedin_url = validated_data.get('linkedin_url', instance.linkedin_url)
instance.website_url = validated_data.get('website_url', instance.website_url)
instance.recommendations = validated_data.get('recommendations', instance.recommendations)
instance.latest_work = validated_data.get('latest_work', instance.latest_work)
instance.latest_work_desc = validated_data.get('latest_work_desc', instance.latest_work_desc)
instance.alamat = validated_data.get('alamat', instance.alamat)
......@@ -119,8 +117,6 @@ class StudentUpdateSerializer(serializers.ModelSerializer):
instance.skills = validated_data.get('skills', instance.skills)
instance.work_experience = validated_data.get(
'work_experience', instance.work_experience)
instance.recommendations = validated_data.get(
'recommendations', instance.recommendations)
instance.latest_work = validated_data.get(
'latest_work', instance.latest_work)
instance.latest_work_desc = validated_data.get(
......@@ -149,7 +145,7 @@ class StudentUpdateSerializer(serializers.ModelSerializer):
class Meta:
model = Student
fields = ['resume', 'email', 'phone_number', 'gender', 'photo', 'show_transcript', 'linkedin_url', 'hackerrank_url', 'region', 'intro', 'portfolio_link', 'website_url', 'student_gpa',
'recommendations', 'work_experience', 'latest_work', 'latest_work_desc', 'volunteer', 'job_seeking_status', 'skills', 'expected_salary',
'work_experience', 'latest_work', 'latest_work_desc', 'volunteer', 'job_seeking_status', 'skills', 'expected_salary',
'self_description', 'github_url', 'gitlab_url', 'awards', 'certification', 'languages', 'seminar', 'interests', 'alamat', 'projects', 'dependants']
......
from rest_framework import serializers
from core.models.recommendations import Recommendation
class RecommendationSerializer(serializers.ModelSerializer):
class Meta:
model = Recommendation
fields = ['id', 'recommendation_giver', 'recommendation_receiver', 'content']
......@@ -80,7 +80,7 @@ class LoginTests(APITestCase):
class RegisterTests(APITestCase):
def test_create_and_recreate(self):
url = '/api/register/'
tc_post = {'password': 'corporatepass', 'name':'tutuplapak', 'description':'menutup lapak', 'email': 'email@email.com',
tc_post = {'password': 'corporatepass', 'name':'tutuplapak', 'description':'menutup lapak', 'email': 'email@email.com',
'logo':'lalala', 'address':'alamat', 'category':'Perusahaan Jasa', 'website':'www.tutuplapak.com', 'size':'1000'}
response = self.client.post(url, tc_post, format='multipart')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
......@@ -203,11 +203,6 @@ class ProfileUpdateTests(APITestCase):
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('alamat'), 'JL.Satya Raya No.41')
url = '/api/students/' + str(student_id) + "/profile/"
response = self.client.patch(url, {'recommendations': 'mantap kak'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('recommendations'), 'mantap kak')
response = self.client.patch(url, {'region': 'Indonesia'}, format='multipart')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual(response.data.get('region'), 'Indonesia')
......
......@@ -2,6 +2,8 @@ import re
from rest_framework import viewsets, status
from rest_framework.decorators import detail_route
from rest_framework.exceptions import PermissionDenied
from rest_framework.generics import get_object_or_404
from rest_framework.parsers import FormParser, MultiPartParser
from rest_framework.permissions import IsAdminUser, IsAuthenticated
from rest_framework.response import Response
......@@ -10,6 +12,12 @@ from core.models.accounts import Student
from core.lib.permissions import IsAdminOrStudent, IsAdminOrSelfOrReadOnly, IsAdminOrSupervisor, \
IsAdminOrSupervisorOrCompanyOrSelf
from core.serializers.accounts import StudentSerializer, StudentUpdateSerializer
from core.views.sso_login import get_access_token, verify_user, get_riwayat_user
def credentials(args):
pass
class StudentViewSet(viewsets.ModelViewSet):
queryset = Student.objects.all()
......@@ -98,4 +106,4 @@ class StudentViewSet(viewsets.ModelViewSet):
return Response({'name': student.full_name, 'transcript': response.json()}, status=status.HTTP_200_OK)
else:
return Response({'name': student.full_name, 'error': 'student does not allow transcript to be shown'},
status=status.HTTP_200_OK)
\ No newline at end of file
status=status.HTTP_200_OK)
from rest_framework import viewsets, status
from rest_framework.response import Response
from core.lib.permissions import IsAdminOrStudent
from core.models.recommendations import Recommendation
from core.serializers.recommendations import RecommendationSerializer
class RecommendationViewSet(viewsets.GenericViewSet):
"""
This viewset automatically provides `list`, `create`, `retrieve`,
`update` and `destroy` feedback actions.
Additionally we also provide an extra `highlight` action.
"""
queryset = Recommendation.objects.all()
serializer_class = RecommendationSerializer
permission_classes = [IsAdminOrStudent]
def list(self, request):
"""
Get list of recommendations
---
"""
recommendations = Recommendation.objects.all()
page = self.paginate_queryset(recommendations)
serialized_page_data = RecommendationSerializer(page, many=True, context={'request': request}).data
print(serialized_page_data)
return self.get_paginated_response(serialized_page_data)
def create(self, request):
"""
Create a recommendation
---
"""
if 'recommendation_giver' in request.data and 'recommendation_receiver' in request.data and 'content' in request.data:
new_recommendation = Recommendation(recommendation_giver=request.data['recommendation_giver'],
recommendation_receiver=request.data['recommendation_receiver'],
content=request.data['content'])
new_recommendation.save()
new_recommendation_serialized = RecommendationSerializer(new_recommendation, context={'request': request})
new_recommendation_serialized_data = new_recommendation_serialized.data
print(new_recommendation_serialized_data)
return Response(new_recommendation_serialized_data)
else:
message = {"detail": "Please send a json object that have title and content property"}
print(message)
return Response(message, status=status.HTTP_400_BAD_REQUEST)
def destroy(self, request, pk):
"""
Remove recommendation {id}
---
"""
if Recommendation.objects.filter(id=pk).count() != 0:
print(request.data)
delete_recommendation = Recommendation.objects.filter(id=pk)
delete_recommendation.delete()
message = {
'detail': "Recommendation with id {} has been removed".format(pk)
}
print(message)
return Response(message, status=status.HTTP_200_OK)
else:
message = {"detail": "Recommendation with id {} doesn't exist".format(pk)}
print(message)
return Response(message, status=status.HTTP_400_BAD_REQUEST)
def update(self, request, pk):
"""
Update recommendation {pk}
---
"""
if Recommendation.objects.filter(id=pk).count() != 0:
print(request.data)
update_recommendation = Recommendation.objects.filter(id=pk)
update_recommendation.update(content=request.data['content'])
update_recommendation = Recommendation.objects.get(id=pk)
update_recommendation_serialized = RecommendationSerializer(update_recommendation, context={'request': request})
update_recommendation_serialized_data = update_recommendation_serialized.data
message = {
"detail": "Recommendation with id {} has been updated".format(pk)
}
message.update(update_recommendation_serialized_data)
print(message)
return Response(message, status=status.HTTP_200_OK)
else:
message = {"detail": "Recommendation with id {} doesn't exist".format(pk)}
print(message)
return Response(message, status=status.HTTP_400_BAD_REQUEST)
This diff is collapsed.
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