Fakultas Ilmu Komputer UI

Commit 99cd96d8 authored by Benny William Pardede's avatar Benny William Pardede
Browse files

[GREEN] Implemented first name last name interpreter function and inject it...

[GREEN] Implemented first name last name interpreter function and inject it when creating User model
parent cb158678
...@@ -111,7 +111,7 @@ export default class ProfilePage extends React.Component { ...@@ -111,7 +111,7 @@ export default class ProfilePage extends React.Component {
(data) => { (data) => {
this.setState({ this.setState({
id: data.id, id: data.id,
name: data.name, name: data.full_name,
npm: data.npm, npm: data.npm,
resume: data.resume, resume: data.resume,
major: data.major, major: data.major,
...@@ -173,7 +173,7 @@ export default class ProfilePage extends React.Component { ...@@ -173,7 +173,7 @@ export default class ProfilePage extends React.Component {
parseIndonesianDateFormat(dateIndex) { parseIndonesianDateFormat(dateIndex) {
const monthNameIndex = { const monthNameIndex = {
'01': 'Januarxi', '01': 'Januari',
'02': 'Februari', '02': 'Februari',
'03': 'Maret', '03': 'Maret',
'04': 'April', '04': 'April',
......
...@@ -114,7 +114,7 @@ export default class ProfilePage extends React.Component { ...@@ -114,7 +114,7 @@ export default class ProfilePage extends React.Component {
(data) => { (data) => {
this.setState({ this.setState({
id: data.id, id: data.id,
name: data.name, name: data.full_name,
npm: data.npm, npm: data.npm,
resume: data.resume, resume: data.resume,
major: data.major, major: data.major,
...@@ -177,7 +177,7 @@ export default class ProfilePage extends React.Component { ...@@ -177,7 +177,7 @@ export default class ProfilePage extends React.Component {
parseIndonesianDateFormat(dateIndex) { parseIndonesianDateFormat(dateIndex) {
const monthNameIndex = { const monthNameIndex = {
'01': 'Januarxi', '01': 'Januari',
'02': 'Februari', '02': 'Februari',
'03': 'Maret', '03': 'Maret',
'04': 'April', '04': 'April',
......
...@@ -19,7 +19,7 @@ class StudentSerializer(serializers.ModelSerializer): ...@@ -19,7 +19,7 @@ class StudentSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Student model = Student
fields = ['id', 'name', 'user', 'npm', 'resume', 'phone_number', 'gender', 'birth_place', 'birth_date', 'major', 'batch', 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', 'recommendations',
'work_experience', 'latest_work', 'latest_work_desc', 'read_no', 'volunteer', 'job_seeking_status', 'skills', 'expected_salary', 'work_experience', 'latest_work', 'latest_work_desc', 'read_no', 'volunteer', 'job_seeking_status', 'skills', 'expected_salary',
'self_description', 'github_url', 'awards', 'certification', 'languages', 'seminar', 'interests', 'alamat', 'projects', 'dependants'] 'self_description', 'github_url', 'awards', 'certification', 'languages', 'seminar', 'interests', 'alamat', 'projects', 'dependants']
...@@ -156,7 +156,7 @@ class CompanyUpdateSerializer(serializers.ModelSerializer): ...@@ -156,7 +156,7 @@ class CompanyUpdateSerializer(serializers.ModelSerializer):
'address': instance.address, 'address': instance.address,
'description': instance.description, 'description': instance.description,
'name': instance.user.first_name, 'name': instance.user.first_name,
'website' : instance.website, 'website' : instance.website,
} }
def update(self, instance, validated_data): def update(self, instance, validated_data):
...@@ -172,7 +172,7 @@ class CompanyUpdateSerializer(serializers.ModelSerializer): ...@@ -172,7 +172,7 @@ class CompanyUpdateSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Company model = Company
fields = ['address', 'description', 'name' , 'website'] fields = ['address', 'description', 'name' , 'website']
class CompanySerializer(serializers.ModelSerializer): class CompanySerializer(serializers.ModelSerializer):
......
import requests_mock
from datetime import date, timedelta from datetime import date, timedelta
from rest_framework import status
from rest_framework.test import APIClient, APITestCase
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import ValidationError from rest_framework.test import APITestCase
from StringIO import StringIO
from core.models.accounts import get_current_age,get_display_name from core.models.accounts import get_current_age, get_display_name
from core.views.accounts import determine_first_name_last_name
class ProfileAccountsTests(APITestCase): class ProfileAccountsTests(APITestCase):
...@@ -16,12 +16,12 @@ class ProfileAccountsTests(APITestCase): ...@@ -16,12 +16,12 @@ class ProfileAccountsTests(APITestCase):
return user return user
def test_display_full_name(self): def test_display_full_name(self):
self.assertEqual('Riansyah Tohamba', self.assertEqual('Riansyah Tohamba',
get_display_name(self.create_first_last_name(),full_name=True) get_display_name(self.create_first_last_name(),full_name=True)
) )
def test_display_last_name_shortened(self): def test_display_last_name_shortened(self):
self.assertEqual('Riansyah T.', self.assertEqual('Riansyah T.',
get_display_name(self.create_first_last_name(),full_name=False) get_display_name(self.create_first_last_name(),full_name=False)
) )
...@@ -42,3 +42,21 @@ class ProfileAccountsTests(APITestCase): ...@@ -42,3 +42,21 @@ class ProfileAccountsTests(APITestCase):
def test_return_age(self): def test_return_age(self):
birth_day = (date.today() -timedelta(days = 700)) birth_day = (date.today() -timedelta(days = 700))
self.assertEqual(1, get_current_age(birth_day)) self.assertEqual(1, get_current_age(birth_day))
def test_determine_first_name_last_name_if_singluar_name(self):
name = "Benny"
self.assertEqual(("Benny", ""), determine_first_name_last_name(name))
def test_determine_first_name_last_name_if_name_lte_3_words(self):
name = "Fadhlan Hazmi"
self.assertEqual(("Fadhlan", "Hazmi"), determine_first_name_last_name(name))
name = "Benny William Pardede"
self.assertEqual(("Benny William", "Pardede"), determine_first_name_last_name(name))
def test_determine_first_name_last_name_if_name_gt_3_words(self):
name = "Kevin Frankly Samuel Pardede"
self.assertEqual(("Kevin Frankly", "Pardede"), determine_first_name_last_name(name))
name = "Sergio Leonel Aguero del Castillo"
self.assertEqual(("Sergio Leonel", "Castillo"), determine_first_name_last_name(name))
...@@ -140,6 +140,18 @@ class SupervisorViewSet(viewsets.ModelViewSet): ...@@ -140,6 +140,18 @@ class SupervisorViewSet(viewsets.ModelViewSet):
permission_classes = [IsAdminOrSelfOrReadOnly, IsAdminOrSupervisor] permission_classes = [IsAdminOrSelfOrReadOnly, IsAdminOrSupervisor]
def determine_first_name_last_name(name):
name = name.split(" ")
if len(name) == 1:
return name[0], ""
elif len(name) > 3:
return " ".join(name[0:2]), name[-1]
else:
return " ".join(name[0:-1]), name[-1]
class LoginViewSet(viewsets.GenericViewSet): class LoginViewSet(viewsets.GenericViewSet):
permission_classes = (AllowAny, ) permission_classes = (AllowAny, )
serializer_class = UserSerializer serializer_class = UserSerializer
...@@ -180,10 +192,8 @@ class LoginViewSet(viewsets.GenericViewSet): ...@@ -180,10 +192,8 @@ class LoginViewSet(viewsets.GenericViewSet):
resp = r.json() resp = r.json()
if resp.get('state') != 0: if resp.get('state') != 0:
# create user # create user
name = resp.get('nama').split(" ") name = resp.get('nama')
first_name = name[0] first_name, last_name = determine_first_name_last_name(name)
name.pop(0)
last_name = " ".join(name)
user, created = User.objects.get_or_create( user, created = User.objects.get_or_create(
username=username, username=username,
defaults={ defaults={
......
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