Fakultas Ilmu Komputer UI

Commit d82d6ddb authored by Ryan Karyadiputera's avatar Ryan Karyadiputera
Browse files

test3

parent 11856a6d
Pipeline #76867 passed with stages
in 8 minutes and 8 seconds
stages: stages:
- test
- flake8 - flake8
- build - build
# - sonarqube
- deploy - deploy
variables: variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
DOCKER_DRIVER: overlay2
image: python:latest image: python:latest
...@@ -25,6 +30,65 @@ before_script: ...@@ -25,6 +30,65 @@ before_script:
- echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> sip/settings/.env - echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> sip/settings/.env
- echo "AWS_STORAGE_BUCKET_NAME=$AWS_STORAGE_BUCKET_NAME" >> sip/settings/.env - echo "AWS_STORAGE_BUCKET_NAME=$AWS_STORAGE_BUCKET_NAME" >> sip/settings/.env
dev-test:
stage: test
script:
- python3 manage.py collectstatic --settings=sip.settings.staging --no-input
- python3 manage.py makemigrations --settings=sip.settings.dev
- python3 manage.py migrate --settings=sip.settings.dev
- python3 manage.py test --settings=sip.settings.dev
only:
- development
- /^.*PBI-.*$/
staging-test:
stage: test
script:
- python3 manage.py collectstatic --settings=sip.settings.staging --no-input
- python3 manage.py makemigrations --settings=sip.settings.staging
- python3 manage.py migrate --settings=sip.settings.staging
- python3 manage.py test --settings=sip.settings.staging
only:
- staging
lint:
stage: flake8
script:
- flake8
allow_failure: true
except:
- CI-CD
# sonarqube:
# image: nuga99/sonar-scanner-python
# stage: sonarqube
# cache:
# key: sonarqube
# paths:
# - .cache/pip
# before_script:
# - python3 -V
# - pip3 install -r requirements.txt
# - echo "DJANGO_SECRET_KEY=$DJANGO_SECRET_KEY" > sip/settings/.env
# - echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> sip/settings/.env
# - echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> sip/settings/.env
# - echo "AWS_STORAGE_BUCKET_NAME=$AWS_STORAGE_BUCKET_NAME" >> sip/settings/.env
# script:
# - if [[ $CI_COMMIT_REF_NAME == staging ]]; then ENVIRON="sip.settings.staging"; else ENVIRON="sip.settings.dev"; fi
# - coverage run --omit='manage.py,**/venv/*,**/python3*/**,core/**,laporan_praktikum/error_message/**,laporan_praktikum/custom_module/**,authentication/cas_wrapper.py,/usr/**' manage.py test --settings=${ENVIRON}
# - coverage report -m
# - coverage xml -i
# - sonar-scanner
# -Dsonar.host.url=https://pmpl.cs.ui.ac.id/sonarqube
# -Dsonar.projectKey=$SONARQUBE_PROJECT_KEY
# -Dsonar.login=$SONARQUBE_TOKEN
# -Dsonar.branch.name=$CI_COMMIT_REF_NAME
# only:
# - master
# - staging
# - development
# - /^.*PBI-.*$/
heroku-deploy: heroku-deploy:
image: ruby:2.4 image: ruby:2.4
stage: deploy stage: deploy
......
...@@ -42,10 +42,7 @@ POSTGRES_DB=postgres_db_name ...@@ -42,10 +42,7 @@ POSTGRES_DB=postgres_db_name
``` ```
### __How To Run on Local Development__ ### __How To Run on Local Development__
1. Buat .env di folder sip/settings/ dengan secret key-nya. Tambahin line ini di file-nya: 1. Buat .env di folder sip/settings/ dengan secret key-nya
```bash
DJANGO_SECRET_KEY="s3cr3t_k3y_c4nn0t_h4ck3d_by_l33t_1337"
```
2. Lakukan makemigrations dan migrate 2. Lakukan makemigrations dan migrate
```bash ```bash
python manage.py makemigrations --settings=sip.settings.dev python manage.py makemigrations --settings=sip.settings.dev
...@@ -57,6 +54,5 @@ POSTGRES_DB=postgres_db_name ...@@ -57,6 +54,5 @@ POSTGRES_DB=postgres_db_name
``` ```
### __Pipelines and Coverage__ ### __Pipelines and Coverage__
[![pipeline status](https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/2021/BB/departemen-ilmu-kesejahteraan-sosial-ui-sistem-informasi-penilaian-dan-database-praktikum-i-dan-ii/praktikum-backend/badges/staging/pipeline.svg)](https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/2021/BB/departemen-ilmu-kesejahteraan-sosial-ui-sistem-informasi-penilaian-dan-database-praktikum-i-dan-ii/praktikum-backend/commits/staging/) [![pipeline status](https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/itproject-2020/group-a/praktikum-backend/badges/staging/pipeline.svg)](https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/itproject-2020/group-a/praktikum-backend) [![coverage report](https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/itproject-2020/group-a/praktikum-backend/badges/staging/coverage.svg)](https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/itproject-2020/group-a/praktikum-backend)
[![coverage report](https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/2021/BB/departemen-ilmu-kesejahteraan-sosial-ui-sistem-informasi-penilaian-dan-database-praktikum-i-dan-ii/praktikum-backend/badges/staging/coverage.svg)](https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/2021/BB/departemen-ilmu-kesejahteraan-sosial-ui-sistem-informasi-penilaian-dan-database-praktikum-i-dan-ii/praktikum-backend/commits/staging/)
...@@ -89,7 +89,6 @@ class Mahasiswa(models.Model): ...@@ -89,7 +89,6 @@ class Mahasiswa(models.Model):
faculty = models.CharField('faculty', max_length=128, blank=True) faculty = models.CharField('faculty', max_length=128, blank=True)
major = models.CharField('major', max_length=128, blank=True) major = models.CharField('major', max_length=128, blank=True)
program = models.CharField('program', max_length=128, blank=True) program = models.CharField('program', max_length=128, blank=True)
lastLogin = models.CharField('last login', max_length=128, blank=True)
periode = models.ForeignKey(Periode, related_name="periode", on_delete=models.CASCADE, null=True, blank=True) periode = models.ForeignKey(Periode, related_name="periode", on_delete=models.CASCADE, null=True, blank=True)
supervisor_sekolah = models.ForeignKey(SupervisorSekolah, related_name='mahasiswa', \ supervisor_sekolah = models.ForeignKey(SupervisorSekolah, related_name='mahasiswa', \
to_field='user', on_delete=models.CASCADE, null=True, blank=True) to_field='user', on_delete=models.CASCADE, null=True, blank=True)
......
...@@ -12,6 +12,7 @@ from lembaga.models import ( ...@@ -12,6 +12,7 @@ from lembaga.models import (
Institusi, Institusi,
Tema, Tema,
Lembaga, Lembaga,
LingkupKerja,
) )
from .serializers import ( from .serializers import (
UserSerializer, UserSerializer,
...@@ -107,6 +108,11 @@ class ModelsTest(TestCase): ...@@ -107,6 +108,11 @@ class ModelsTest(TestCase):
tema = Tema.objects.create( tema = Tema.objects.create(
nama="testing" nama="testing"
) )
lingkup_kerja = LingkupKerja.objects.create(
nama="testing"
)
self.lembaga = Lembaga.objects.create( self.lembaga = Lembaga.objects.create(
nama="testing", nama="testing",
jenis_pelayanan="testing", jenis_pelayanan="testing",
...@@ -118,6 +124,7 @@ class ModelsTest(TestCase): ...@@ -118,6 +124,7 @@ class ModelsTest(TestCase):
beneficaries="test_beneficaries" beneficaries="test_beneficaries"
) )
self.lembaga.lingkup_kerja.add(lingkup_kerja)
self.lembaga.gambar = self.get_image_file() self.lembaga.gambar = self.get_image_file()
self.lembaga.save() self.lembaga.save()
...@@ -293,6 +300,10 @@ class SerializersTest(TestCase): ...@@ -293,6 +300,10 @@ class SerializersTest(TestCase):
nama="testing" nama="testing"
) )
lingkup_kerja = LingkupKerja.objects.create(
nama="testing"
)
self.lembaga = Lembaga.objects.create( self.lembaga = Lembaga.objects.create(
nama="testing", nama="testing",
jenis_pelayanan="testing", jenis_pelayanan="testing",
...@@ -304,6 +315,7 @@ class SerializersTest(TestCase): ...@@ -304,6 +315,7 @@ class SerializersTest(TestCase):
alamat="test_alamat" alamat="test_alamat"
) )
self.lembaga.lingkup_kerja.add(lingkup_kerja)
self.lembaga.gambar = self.get_image_file() self.lembaga.gambar = self.get_image_file()
self.lembaga.save() self.lembaga.save()
...@@ -545,11 +557,17 @@ class SSOUITest(TestCase): ...@@ -545,11 +557,17 @@ class SSOUITest(TestCase):
supervisor_sekolah=None supervisor_sekolah=None
) )
# def test_login_url_exists(self): def test_login_url_exists(self):
# """Test if login url exists and redirects to CAS server (response code 302).""" """Test if login url exists and redirects to CAS server (response code 302)."""
# response = self.client.get(reverse('authentication:login-sivitas')) response = self.client.get(reverse('authentication:login-sivitas'))
# self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
# self.assertTrue(response.url.startswith(settings.CAS_SERVER_URL)) self.assertTrue(response.url.startswith(settings.CAS_SERVER_URL))
def test_logout_url_exists(self):
"""Test if logout url exists and redirects to CAS server (response code 302)."""
response = self.client.get(reverse('authentication:logout'))
self.assertEqual(response.status_code, 302)
self.assertTrue(response.url.startswith(settings.CAS_SERVER_URL))
# def test_profile_can_save_attributes_if_user_mahasiswa_not_yet_registered(self): # def test_profile_can_save_attributes_if_user_mahasiswa_not_yet_registered(self):
# """Test if Profile Mahasiswa model can save the attributes from CAS.""" # """Test if Profile Mahasiswa model can save the attributes from CAS."""
...@@ -708,6 +726,10 @@ class AuthenticationJSONWebTokenTest(APITestCase): ...@@ -708,6 +726,10 @@ class AuthenticationJSONWebTokenTest(APITestCase):
nama="testing" nama="testing"
) )
lingkup_kerja = LingkupKerja.objects.create(
nama="testing"
)
self.lembaga = Lembaga.objects.create( self.lembaga = Lembaga.objects.create(
nama="testing", nama="testing",
jenis_pelayanan="testing", jenis_pelayanan="testing",
...@@ -719,6 +741,7 @@ class AuthenticationJSONWebTokenTest(APITestCase): ...@@ -719,6 +741,7 @@ class AuthenticationJSONWebTokenTest(APITestCase):
alamat="test_alamat" alamat="test_alamat"
) )
self.lembaga.lingkup_kerja.add(lingkup_kerja)
self.lembaga.gambar = self.get_image_file() self.lembaga.gambar = self.get_image_file()
self.lembaga.save() self.lembaga.save()
......
...@@ -5,8 +5,7 @@ from django.urls import include, path ...@@ -5,8 +5,7 @@ from django.urls import include, path
app_name = 'authentication' app_name = 'authentication'
urlpatterns = [ urlpatterns = [
path('login/sivitas/', APILoginView.as_view(), name='login-sivitas'), path('login/sivitas/', APILoginView.as_view(), name='login-sivitas'),
# path('logout/', APILogoutView.as_view(), name='logout'), path('logout/', APILogoutView.as_view(), name='logout'),
path('logout/', views.ManualLogoutView.as_view(), name='logout'),
path('register/supervisor-lembaga/', views.UserRegistrationView.as_view(), name='register-supervisor-lembaga'), path('register/supervisor-lembaga/', views.UserRegistrationView.as_view(), name='register-supervisor-lembaga'),
path('login/supervisor-lembaga/', views.UserLoginView.as_view(), name='login-supervisor-lembaga'), path('login/supervisor-lembaga/', views.UserLoginView.as_view(), name='login-supervisor-lembaga'),
path('register/supervisor-lembaga/', views.UserRegistrationView.as_view(), name='register-supervisor-lembaga'), path('register/supervisor-lembaga/', views.UserRegistrationView.as_view(), name='register-supervisor-lembaga'),
...@@ -20,5 +19,5 @@ urlpatterns = [ ...@@ -20,5 +19,5 @@ urlpatterns = [
path('profile/administrator', views.UserProfileAdministratorView.as_view(), name='profile-administrator'), path('profile/administrator', views.UserProfileAdministratorView.as_view(), name='profile-administrator'),
path('profile/user', views.UserProfileUserView.as_view(), name='profile-user'), path('profile/user', views.UserProfileUserView.as_view(), name='profile-user'),
path('periode/list', views.PeriodeListView.as_view(), name='periode-list'), path('periode/list', views.PeriodeListView.as_view(), name='periode-list'),
path('login/sso/', views.ManualSSOLoginView.as_view(), name='login-sso'), path('login/sso/', views.ManualSSOLoginView.as_view(), name='login-sso')
] ]
...@@ -21,10 +21,8 @@ from .serializers import ( ...@@ -21,10 +21,8 @@ from .serializers import (
AdministratorLoginSerializer AdministratorLoginSerializer
) )
from .role import Role from .role import Role
from datetime import datetime
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.http import JsonResponse, HttpResponseRedirect from django.http import JsonResponse
from django.contrib.auth.models import update_last_login
from django.shortcuts import render from django.shortcuts import render
from rest_framework import status from rest_framework import status
from rest_framework.decorators import api_view from rest_framework.decorators import api_view
...@@ -107,14 +105,6 @@ class ManualSSOLoginView(RetrieveAPIView): ...@@ -107,14 +105,6 @@ class ManualSSOLoginView(RetrieveAPIView):
return Response(response, status=status.HTTP_200_OK) return Response(response, status=status.HTTP_200_OK)
class ManualLogoutView(RetrieveAPIView):
permission_classes = (AllowAny,)
def get(self, request):
update_last_login(datetime.now(), request.user)
return HttpResponseRedirect("http://ppl-berkah.herokuapp.com/")
class UserProfileMahasiswaView(RetrieveAPIView): # pragma: no cover class UserProfileMahasiswaView(RetrieveAPIView): # pragma: no cover
permission_classes = (IsAuthenticated,) permission_classes = (IsAuthenticated,)
......
This diff is collapsed.
from django.db import models from django.db import models
from lembaga.models import Lembaga from lembaga.models import Lembaga, LingkupKerja
from authentication.models import Administrator, KoordinatorKuliah, Mahasiswa, \ from authentication.models import Administrator, KoordinatorKuliah, Mahasiswa, \
SupervisorLembaga, SupervisorSekolah SupervisorLembaga, SupervisorSekolah
from django.core.files.storage import FileSystemStorage from django.core.files.storage import FileSystemStorage
......
from laporan_praktikum.models import Praktikum, KelolaLaporanPraktikum, MahasiswaPraktikum from laporan_praktikum.models import Praktikum, KelolaLaporanPraktikum, MahasiswaPraktikum
from authentication.models import Mahasiswa, SupervisorLembaga, SupervisorSekolah, User, Periode from authentication.models import Mahasiswa, SupervisorLembaga, SupervisorSekolah, User, Periode
from lembaga.models import Lembaga, Tema, Institusi from lembaga.models import Lembaga, Tema, Institusi, LingkupKerja
from django.test import TestCase from django.test import TestCase
from django.core.files import File from django.core.files import File
from io import BytesIO from io import BytesIO
...@@ -91,6 +91,8 @@ class SupervisorSekolahDashboardAPITest(APITestCase): ...@@ -91,6 +91,8 @@ class SupervisorSekolahDashboardAPITest(APITestCase):
Institusi Institusi
), tema=mixer.blend( ), tema=mixer.blend(
Tema Tema
), lingkup_kerja=mixer.blend(
LingkupKerja
), gambar=self.get_image_file() ), gambar=self.get_image_file()
), user=mixer.blend(User) ), user=mixer.blend(User)
) )
......
...@@ -15,7 +15,7 @@ from laporan_praktikum.models import ( ...@@ -15,7 +15,7 @@ from laporan_praktikum.models import (
from laporan_praktikum.serializers import ( from laporan_praktikum.serializers import (
RiwayatLaporanPraktikumMahasiswaSerializer RiwayatLaporanPraktikumMahasiswaSerializer
) )
from lembaga.models import Lembaga, Tema, Institusi from lembaga.models import Lembaga, Tema, Institusi, LingkupKerja
from laporan_praktikum.models import LaporanAkhirPraktikum from laporan_praktikum.models import LaporanAkhirPraktikum
from django.test import TestCase from django.test import TestCase
...@@ -365,6 +365,8 @@ class PeriodeAPITest(APITestCase): ...@@ -365,6 +365,8 @@ class PeriodeAPITest(APITestCase):
Institusi Institusi
), tema=mixer.blend( ), tema=mixer.blend(
Tema Tema
), lingkup_kerja=mixer.blend(
LingkupKerja
), gambar=self.get_image_file() ), gambar=self.get_image_file()
), user=mixer.blend( ), user=mixer.blend(
User User
...@@ -485,6 +487,8 @@ class KoordinatorKuliahDashboardAPITest(APITestCase): ...@@ -485,6 +487,8 @@ class KoordinatorKuliahDashboardAPITest(APITestCase):
Institusi Institusi
), tema=mixer.blend( ), tema=mixer.blend(
Tema Tema
), lingkup_kerja=mixer.blend(
LingkupKerja
), gambar=self.get_image_file() ), gambar=self.get_image_file()
), user=mixer.blend( ), user=mixer.blend(
User User
...@@ -855,7 +859,9 @@ class AdministratorDashboardAPITest(APITestCase): ...@@ -855,7 +859,9 @@ class AdministratorDashboardAPITest(APITestCase):
Institusi Institusi
), tema=mixer.blend( ), tema=mixer.blend(
Tema Tema
), ), lingkup_kerja=mixer.blend(
LingkupKerja
)
), user=mixer.blend( ), user=mixer.blend(
User, User,
username="username2", username="username2",
......
...@@ -214,14 +214,6 @@ def get_list_laporan_praktikum_detail(request): ...@@ -214,14 +214,6 @@ def get_list_laporan_praktikum_detail(request):
response_field[1]: status_code, response_field[1]: status_code,
response_field[2]: error_message_404_praktikum response_field[2]: error_message_404_praktikum
} }
except TemplateBorangPenilaianPraktikum.DoesNotExist:
status_code = status.HTTP_404_NOT_FOUND
response = {
response_field[0]: 'False',
response_field[1]: status_code,
response_field[2]: "Your Supervisor Sekolah hasn't been uploaded the Template Borang"
}
return Response(response, status=status_code) return Response(response, status=status_code)
......
...@@ -5,4 +5,4 @@ from lembaga import models ...@@ -5,4 +5,4 @@ from lembaga import models
admin.site.register(models.Lembaga) admin.site.register(models.Lembaga)
admin.site.register(models.Institusi) admin.site.register(models.Institusi)
admin.site.register(models.Tema) admin.site.register(models.Tema)
admin.site.register(models.ErrorMessage) admin.site.register(models.LingkupKerja)
...@@ -20,6 +20,13 @@ class Migration(migrations.Migration): ...@@ -20,6 +20,13 @@ class Migration(migrations.Migration):
('nama', models.CharField(max_length=255)), ('nama', models.CharField(max_length=255)),
], ],
), ),
migrations.CreateModel(
name='LingkupKerja',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nama', models.CharField(max_length=255)),
],
),
migrations.CreateModel( migrations.CreateModel(
name='Tema', name='Tema',
fields=[ fields=[
...@@ -39,6 +46,7 @@ class Migration(migrations.Migration): ...@@ -39,6 +46,7 @@ class Migration(migrations.Migration):
('alamat', models.CharField(max_length=1024)), ('alamat', models.CharField(max_length=1024)),
('praktikum_ke', models.IntegerField()), ('praktikum_ke', models.IntegerField()),
('institusi', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lembaga.Institusi')), ('institusi', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lembaga.Institusi')),
('lingkup_kerja', models.ManyToManyField(related_name='lembaga', to='lembaga.LingkupKerja')),
('tema', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lembaga.Tema')), ('tema', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lembaga.Tema')),
], ],
), ),
......
...@@ -15,6 +15,11 @@ class Migration(migrations.Migration): ...@@ -15,6 +15,11 @@ class Migration(migrations.Migration):
name='nama', name='nama',
field=models.CharField(max_length=255, unique=True), field=models.CharField(max_length=255, unique=True),
), ),
migrations.AlterField(
model_name='lingkupkerja',
name='nama',
field=models.CharField(max_length=255, unique=True),
),
migrations.AlterField( migrations.AlterField(
model_name='tema', model_name='tema',
name='nama', name='nama',
......
...@@ -20,6 +20,14 @@ class Tema(models.Model): ...@@ -20,6 +20,14 @@ class Tema(models.Model):
return self.nama return self.nama
class LingkupKerja(models.Model):
""" Models for Lingkup Kerja """
nama = models.CharField(max_length=255, unique=True)
def __str__(self):
return self.nama
def upload_location(instance, filename): def upload_location(instance, filename):
_, extension = filename.split('.') _, extension = filename.split('.')
return '%s.%s' % (instance.nama, extension) return '%s.%s' % (instance.nama, extension)
...@@ -28,6 +36,7 @@ def upload_location(instance, filename): ...@@ -28,6 +36,7 @@ def upload_location(instance, filename):
class Lembaga(models.Model): class Lembaga(models.Model):
""" Models for Lembaga """ """ Models for Lembaga """
nama = models.CharField(max_length=255) nama = models.CharField(max_length=255)
lingkup_kerja = models.ManyToManyField(LingkupKerja, related_name="lembaga")
jenis_pelayanan = models.CharField(max_length=255) jenis_pelayanan = models.CharField(max_length=255)
institusi = models.ForeignKey(Institusi, on_delete=models.CASCADE) institusi = models.ForeignKey(Institusi, on_delete=models.CASCADE)
tema = models.ForeignKey(Tema, on_delete=models.CASCADE) tema = models.ForeignKey(Tema, on_delete=models.CASCADE)
...@@ -38,9 +47,3 @@ class Lembaga(models.Model): ...@@ -38,9 +47,3 @@ class Lembaga(models.Model):
def __str__(self): def __str__(self):
return self.nama return self.nama
class ErrorMessage(models.Model):
""" Models for Error Messages """
def not_found(self):
return "tidak ditemukan"
from rest_framework import serializers from rest_framework import serializers
from lembaga.models import Lembaga, Institusi, Tema, ErrorMessage from lembaga.models import Lembaga, Institusi, Tema, LingkupKerja
from rest_framework.exceptions import NotFound from rest_framework.exceptions import NotFound
from drf_extra_fields.fields import Base64ImageField from drf_extra_fields.fields import Base64ImageField
...@@ -22,8 +22,18 @@ class TemaSerializer(serializers.ModelSerializer): ...@@ -22,8 +22,18 @@ class TemaSerializer(serializers.ModelSerializer):
} }
class LingkupKerjaSerializer(serializers.ModelSerializer):
class Meta:
model = LingkupKerja
fields = '__all__'
extra_kwargs = {
'nama': {'validators': []},
}
class LembagaSerializer(serializers.ModelSerializer): class LembagaSerializer(serializers.ModelSerializer):
tema = TemaSerializer() tema = TemaSerializer()
lingkup_kerja = LingkupKerjaSerializer(many=True)
institusi = InstitusiSerializer() institusi = InstitusiSerializer()
class Meta: class Meta:
...@@ -41,18 +51,27 @@ class LembagaSerializer(serializers.ModelSerializer): ...@@ -41,18 +51,27 @@ class LembagaSerializer(serializers.ModelSerializer):
nama_tema = validated_data.pop('tema')['nama'] nama_tema = validated_data.pop('tema')['nama']
error = ErrorMessage
try: try:
tema = Tema.objects.get(nama=nama_tema) tema = Tema.objects.get(nama=nama_tema)
except Tema.DoesNotExist: except Tema.DoesNotExist:
raise NotFound(detail="Tema dengan nama " + str(nama_tema) + ErrorMessage.not_found(error)) raise NotFound(detail="Tema dengan nama " + str(nama_tema) + " tidak ditemukan")
nama_lingkup_kerja = validated_data.pop('lingkup_kerja')
final_query = []
for lingkup in nama_lingkup_kerja:
try:
lingkup_kerja = LingkupKerja.objects.get(nama=lingkup["nama"])
except LingkupKerja.DoesNotExist:
raise NotFound(detail="Lingkup kerja dengan nama " + str(lingkup["nama"]) + " tidak ditemukan")
final_query.append(lingkup_kerja)
nama_institusi = validated_data.pop('institusi')['nama'] nama_institusi