Fakultas Ilmu Komputer UI

Commit 2475179b authored by Benny William Pardede's avatar Benny William Pardede
Browse files

Merge branch '1606917550-107' into 'master'

1606917550-107 Mengubah cara model menyimpan nama

Closes #107

See merge request !162
parents cb158678 99cd96d8
Pipeline #25164 passed with stages
in 12 minutes and 18 seconds
......@@ -111,7 +111,7 @@ export default class ProfilePage extends React.Component {
(data) => {
this.setState({
id: data.id,
name: data.name,
name: data.full_name,
npm: data.npm,
resume: data.resume,
major: data.major,
......@@ -173,7 +173,7 @@ export default class ProfilePage extends React.Component {
parseIndonesianDateFormat(dateIndex) {
const monthNameIndex = {
'01': 'Januarxi',
'01': 'Januari',
'02': 'Februari',
'03': 'Maret',
'04': 'April',
......
......@@ -114,7 +114,7 @@ export default class ProfilePage extends React.Component {
(data) => {
this.setState({
id: data.id,
name: data.name,
name: data.full_name,
npm: data.npm,
resume: data.resume,
major: data.major,
......@@ -177,7 +177,7 @@ export default class ProfilePage extends React.Component {
parseIndonesianDateFormat(dateIndex) {
const monthNameIndex = {
'01': 'Januarxi',
'01': 'Januari',
'02': 'Februari',
'03': 'Maret',
'04': 'April',
......
......@@ -19,7 +19,7 @@ class StudentSerializer(serializers.ModelSerializer):
class Meta:
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',
'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']
......@@ -156,7 +156,7 @@ class CompanyUpdateSerializer(serializers.ModelSerializer):
'address': instance.address,
'description': instance.description,
'name': instance.user.first_name,
'website' : instance.website,
'website' : instance.website,
}
def update(self, instance, validated_data):
......@@ -172,7 +172,7 @@ class CompanyUpdateSerializer(serializers.ModelSerializer):
class Meta:
model = Company
fields = ['address', 'description', 'name' , 'website']
fields = ['address', 'description', 'name' , 'website']
class CompanySerializer(serializers.ModelSerializer):
......
import requests_mock
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.core.exceptions import ValidationError
from StringIO import StringIO
from core.models.accounts import get_current_age,get_display_name
from rest_framework.test import APITestCase
from core.models.accounts import get_current_age, get_display_name
from core.views.accounts import determine_first_name_last_name
class ProfileAccountsTests(APITestCase):
......@@ -16,12 +16,12 @@ class ProfileAccountsTests(APITestCase):
return user
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)
)
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)
)
......@@ -42,3 +42,21 @@ class ProfileAccountsTests(APITestCase):
def test_return_age(self):
birth_day = (date.today() -timedelta(days = 700))
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):
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):
permission_classes = (AllowAny, )
serializer_class = UserSerializer
......@@ -180,10 +192,8 @@ class LoginViewSet(viewsets.GenericViewSet):
resp = r.json()
if resp.get('state') != 0:
# create user
name = resp.get('nama').split(" ")
first_name = name[0]
name.pop(0)
last_name = " ".join(name)
name = resp.get('nama')
first_name, last_name = determine_first_name_last_name(name)
user, created = User.objects.get_or_create(
username=username,
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