Fakultas Ilmu Komputer UI

Commit 26e073df authored by Farhan Farasdak's avatar Farhan Farasdak
Browse files

#Change Database and Function for frontend purpose

parent cec72185
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-19 13:22
# Generated by Django 1.10.5 on 2017-03-27 14:28
from __future__ import unicode_literals
import core.models.accounts
......@@ -18,6 +18,12 @@ class Migration(migrations.Migration):
]
operations = [
migrations.CreateModel(
name='Application',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
migrations.CreateModel(
name='Company',
fields=[
......@@ -38,7 +44,6 @@ class Migration(migrations.Migration):
('npm', models.IntegerField(unique=True, validators=[django.core.validators.MinValueValidator(100000000), django.core.validators.MaxValueValidator(9999999999)])),
('resume', models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_file_path)),
('phone_number', models.CharField(blank=True, db_index=True, max_length=100)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
......@@ -51,4 +56,34 @@ class Migration(migrations.Migration):
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Vacancy',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('verified', models.BooleanField(default=False)),
('open_time', models.DateTimeField()),
('close_time', models.DateTimeField()),
('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='vacancies', to='core.Company')),
],
),
migrations.AddField(
model_name='student',
name='bookmarked_vacancies',
field=models.ManyToManyField(to='core.Vacancy'),
),
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='application',
name='student_npm',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='core.Student'),
),
migrations.AddField(
model_name='application',
name='vacancy_id',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='core.Vacancy'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-20 09: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.CreateModel(
name='Application',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('student_npm', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='core.Student')),
],
),
migrations.CreateModel(
name='Vacancy',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('verified', models.BooleanField(default=False)),
('open_time', models.DateTimeField()),
('close_time', models.DateTimeField()),
('company_id', models.ManyToManyField(to='core.Company')),
],
),
migrations.AddField(
model_name='application',
name='vacancy_id',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='core.Vacancy'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-24 11:38
# Generated by Django 1.10.5 on 2017-03-27 15:07
from __future__ import unicode_literals
from django.db import migrations, models
......@@ -8,13 +8,13 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0002_auto_20170320_1650'),
('core', '0001_initial'),
]
operations = [
migrations.AddField(
migrations.AlterField(
model_name='student',
name='bookmarked_vacancies',
field=models.ManyToManyField(to='core.Vacancy'),
field=models.ManyToManyField(null=True, to='core.Vacancy'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-27 15:19
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0002_auto_20170327_2207'),
]
operations = [
migrations.AlterField(
model_name='student',
name='bookmarked_vacancies',
field=models.ManyToManyField(blank=True, null=True, to='core.Vacancy'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-27 17:36
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0003_auto_20170327_2219'),
]
operations = [
migrations.AddField(
model_name='vacancy',
name='description',
field=models.TextField(blank=True),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-27 17:43
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0004_vacancy_description'),
]
operations = [
migrations.AddField(
model_name='company',
name='alamat',
field=models.CharField(blank=True, max_length=1000, null=True),
),
migrations.AddField(
model_name='company',
name='logo',
field=models.CharField(blank=True, max_length=1000, null=True),
),
]
......@@ -41,7 +41,7 @@ class Student(models.Model):
npm = models.IntegerField(validators=[MinValueValidator(100000000), MaxValueValidator(9999999999)], unique=True)
resume = models.FileField(upload_to=get_file_path, null=True, blank=True)
phone_number = models.CharField(max_length=100, blank=True, db_index=True)
bookmarked_vacancies = models.ManyToManyField('core.Vacancy')
bookmarked_vacancies = models.ManyToManyField('core.Vacancy', null=True, blank=True)
@property
def name(self):
......@@ -60,6 +60,8 @@ class Company(models.Model):
user = models.OneToOneField(User)
description = models.TextField()
verified = models.BooleanField(default=False)
logo = models.CharField(max_length=1000, blank=True, null=True)
alamat = models.CharField(max_length=1000, blank=True, null=True)
@property
def name(self):
......
......@@ -4,9 +4,10 @@ from core.models.accounts import Company, Student
class Vacancy(models.Model):
company_id = models.ManyToManyField(Company)
company = models.ForeignKey(Company, related_name="vacancies", null=False)
verified = models.BooleanField(default=False)
open_time = models.DateTimeField()
description = models.TextField(blank=True)
close_time = models.DateTimeField()
......
from rest_framework import serializers
from core.serializers.accounts import CompanySerializer
from core.models.vacancies import Vacancy, Application
class VacancySerializer(serializers.ModelSerializer):
company = CompanySerializer()
class Meta:
model = Vacancy
fields = '__all__'
......
# from unittest import TestCase
#
# from django.urls import reverse
#
#
# class TestStudentViewSet(TestCase):
# # def setUp(self):
# # #c = Client()
# # Student.objects.create(user = User.objects.create(username = "farhan"), npm = "1406572321")
#
# def test_bookmark_vacancies(self):
# url = reverse('bookmarked-vacancies')
# data = {'company_id': 1}
# response = self.client.post(url, data, format='json')
# self.fail()
# #
# # def test_remove_vacancies(self):
# # self.fail()
from unittest import TestCase
from django.urls import reverse
class TestStudentViewSet(TestCase):
# def setUp(self):
# #c = Client()
# Student.objects.create(user = User.objects.create(username = "farhan"), npm = "1406572321")
#def test_bookmark_vacancies(self):
# url = reverse('bookmarked-vacancies')
# data = {'company_id': 1}
# response = self.client.post(url, data, format='json')
# self.fail()
#
# def test_remove_vacancies(self):
# self.fail()
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404
from rest_framework import status
from rest_framework import viewsets
from rest_framework.decorators import list_route, detail_route
from rest_framework.exceptions import ValidationError
from rest_framework.response import Response
from core.models import Vacancy
......@@ -24,16 +26,24 @@ class StudentViewSet(viewsets.ModelViewSet):
queryset = Student.objects.all()
serializer_class = StudentSerializer
@detail_route(methods=['get'], url_path='vacancies')
def vacancies(self, request, pk):
student = Student.objects.get(pk=pk)
return Response(get_display_name(student))
@detail_route(methods=['post'], url_path='bookmarked-vacancies')
def bookmark_vacancies(self, request, pk):
user = self.request.user
print("yay1")
vacancy = get_object_or_404(Vacancy.objects.all(), pk=request.data['vacancy_id'])
print("yay2")
student = get_object_or_404(Student.objects.all(), pk=pk)
print("yay3")
if student != user.student and not user.is_staff:
raise ValidationError('You must be a student')
student.bookmarked_vacancies.add(vacancy)
return Response(vacancy, status=status.HTTP_200_OK)
@detail_route(methods=['post'], url_path='vacancies')
def insert_vacancies(self, request, pk):
vacancy = Vacancy.objects.get(request.data.id)
@detail_route(methods=['delete'], url_path='bookmarked-vacancies')
def unbookmark_vacancies(self, request, pk):
vacancy = get_object_or_404(Vacancy.objects.all(), pk=request.data['vacancy_id'])
student = self.request.user.student
student.bookmarked_vacancies.add(vacancy)
student.bookmarked_vacancies.remove(vacancy)
return Response(vacancy, status=status.HTTP_200_OK)
......@@ -45,3 +55,9 @@ class CompanyViewSet(viewsets.ModelViewSet):
class SupervisorViewSet(viewsets.ModelViewSet):
queryset = Supervisor.objects.all()
serializer_class = SupervisorSerializer
......@@ -5,7 +5,7 @@ from core.serializers.vacancies import VacancySerializer, ApplicationSerializer
class VacancyViewSet(viewsets.ModelViewSet):
queryset = Vacancy.objects.all()
queryset = Vacancy.objects.all().filter(verified=True)
serializer_class = VacancySerializer
......
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