Fakultas Ilmu Komputer UI

Commit 3be1c46d authored by Bram Sedana Wehantouw's avatar Bram Sedana Wehantouw
Browse files

1606824502 72 Added new field to vacancy

parent 20d36906
......@@ -102,6 +102,7 @@ export default class CreateVacancy extends React.Component {
data.salary = this.state.salary;
data.open_time = this.state.open_time.format();
data.close_time = this.state.close_time.format();
data.max_accepted_applicants = this.state.max_accepted_applicants;
data.working_period = this.state.working_period;
if (!this.state.vacancyId) {
data.company = this.state.company.id;
......@@ -140,6 +141,7 @@ export default class CreateVacancy extends React.Component {
<CKEditor value={this.state.responsibilities} onChange={this.handleResponsibilities} /> }
<script>CKEDITOR.replace( 'responsibilities' );</script>
<br />
<Form.Field label="Jumlah yang Diterima" name="max_accepted_applicants" control={Input} onChange={this.handleChange} value={this.state.max_accepted_applicants} required />
<label htmlFor="benefits"> <b> Keuntungan </b> </label>
{ !this.state.loading && <CKEditor value={this.state.benefits} onChange={this.handleBenefits} /> }
<script>CKEDITOR.replace( 'benefits' );</script>
......
......@@ -25,6 +25,8 @@ describe('Vacancy', () => {
updated: '2017-03-28T07:34:13.122093Z',
working_period: 'Juli-Agustus',
verified: true,
max_accepted_applicants: 3,
total_accepted_applicants: 0,
};
const response2 = {
......@@ -46,6 +48,8 @@ describe('Vacancy', () => {
updated: '2017-03-28T07:34:13.122093Z',
working_period: 'Oktober-Desember',
verified: true,
max_accepted_applicants: 3,
total_accepted_applicants: 0,
};
const studentUser = {
......
......@@ -148,6 +148,8 @@ describe('VacancyList', () => {
status: 0,
bookmarked: false,
id: 4,
max_accepted_applicants: 3,
total_accepted_applicants: 0,
working_period: 'Juli-Agustus',
},
{
......@@ -182,6 +184,8 @@ describe('VacancyList', () => {
status: 1,
bookmarked: false,
id: 4,
max_accepted_applicants: 3,
total_accepted_applicants: 0,
working_period: 'Juli-Agustus',
},
{
......@@ -216,6 +220,8 @@ describe('VacancyList', () => {
status: 2,
bookmarked: true,
id: 4,
max_accepted_applicants: 3,
total_accepted_applicants: 0,
working_period: 'Juli-Agustus',
},
{
......@@ -250,6 +256,8 @@ describe('VacancyList', () => {
status: 3,
bookmarked: true,
id: 4,
max_accepted_applicants: 3,
total_accepted_applicants: 0,
working_period: 'Juli-Agustus',
},
{
......@@ -284,6 +292,8 @@ describe('VacancyList', () => {
status: 4,
bookmarked: true,
id: 4,
max_accepted_applicants: 3,
total_accepted_applicants: 0,
working_period: 'Juli-Agustus',
},
];
......@@ -306,6 +316,8 @@ describe('VacancyList', () => {
open_time: '2017-03-28T05:55:38Z',
updated: '2017-03-28T07:34:13.122093Z',
verified: true,
max_accepted_applicants: 3,
total_accepted_applicants: 0,
working_period: 'Juli-Agustus',
}, {
salary: '1',
......@@ -325,6 +337,8 @@ describe('VacancyList', () => {
open_time: '2017-03-28T05:55:38Z',
updated: '2017-03-28T07:34:13.122093Z',
verified: true,
max_accepted_applicants: 3,
total_accepted_applicants: 0,
working_period: 'Juli-Agustus',
}];
......@@ -346,6 +360,8 @@ describe('VacancyList', () => {
open_time: '2017-03-28T05:55:38Z',
updated: '2017-03-28T07:34:13.122093Z',
verified: true,
max_accepted_applicants: 3,
total_accepted_applicants: 0,
working_period: 'Juli-Agustus',
}];
......
......@@ -37,6 +37,7 @@ export default class CompanyVacancy extends React.Component {
<Grid.Column floated="left">
<p>{ this.state.count } Pendaftar<br/>
{ this.state.countNew } Pendaftar Baru<br/><br/>
{ this.props.data.total_accepted_applicants } / {this.props.data.max_accepted_applicants } Diterima<br/>
Ditutup {moment(moment(this.props.data.close_time)).fromNow()}</p>
</Grid.Column>
<Grid.Column floated="right">
......
......@@ -139,6 +139,10 @@ export default class Vacancy extends React.Component {
{ this.props.data.company.address }<br />
{ this.props.data.working_period}<br />
{ this.state.count } orang telah mendaftar!<br />
<b>
{ this.props.data.total_accepted_applicants }
/ { this.props.data.max_accepted_applicants }
diterima </b><br />
<b>{`Ditutup ${moment(moment(this.props.data.close_time)).fromNow()}`}</b><br />
Rp. { this.props.data.salary } <br />
<b>{this.props.data.apply_before}</b>
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.17 on 2019-10-12 15:05
# Generated by Django 1.11.17 on 2019-10-12 16:28
from __future__ import unicode_literals
from django.db import migrations, models
......@@ -17,4 +17,10 @@ class Migration(migrations.Migration):
name='benefits',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='vacancy',
name='max_accepted_applicants',
field=models.IntegerField(default=3),
preserve_default=False,
),
]
......@@ -16,6 +16,7 @@ class Vacancy(models.Model):
updated = models.DateTimeField(auto_now=True)
name = models.CharField(max_length=100, null=False)
amount = models.IntegerField(null=True)
max_accepted_applicants = models.IntegerField()
benefits = models.TextField(blank=True)
working_period = models.CharField(max_length=100, null=True)
tag = models.TextField(blank=True)
......
......@@ -9,7 +9,11 @@ class VacancySerializer(serializers.ModelSerializer):
company = CompanySerializer()
status = serializers.SerializerMethodField('_get_app_status')
bookmarked = serializers.SerializerMethodField('_get_bookmarked_status')
total_accepted_applicants = serializers.SerializerMethodField('_get_total_accepted_applicants')
def _get_total_accepted_applicants(self, instance):
return len(Application.objects.filter(vacancy = instance, status = 4))
def _get_app_status(self, instance):
try:
request = self.context.get("request")
......@@ -33,7 +37,7 @@ class VacancySerializer(serializers.ModelSerializer):
class Meta:
model = Vacancy
fields = ['company', 'verified', 'open_time', 'description', 'close_time', 'created','apply_before', 'updated', 'name', \
'status', 'bookmarked', 'id', 'salary', 'responsibilities', 'requirements','working_period', 'benefits']
'status', 'bookmarked', 'id', 'salary', 'responsibilities', 'requirements','working_period', 'benefits', 'max_accepted_applicants', 'total_accepted_applicants']
def name_position_validator(names):
for name in names.split(" "):
......
This diff is collapsed.
......@@ -112,7 +112,7 @@ class ApplicationTests(APITestCase):
new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
address=None)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
description="lalala",working_period="3 Bulan", requirements= "requirements", close_time=(timezone.now() + timedelta(days=1)))
description="lalala", max_accepted_applicants=3, working_period="3 Bulan", requirements= "requirements", close_time=(timezone.now() + timedelta(days=1)))
url = '/api/students/' + str(student_id) + '/applied-vacancies/'
response = self.client.post(url, {'vacancy_id': new_vacancy.pk, 'cover_letter': 'this is a cover letter.'},
......@@ -135,7 +135,7 @@ class ApplicationTests(APITestCase):
new_student = Student.objects.create(user=new_user2, npm=1234123412)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
description="lalala",working_period="3 Bulan" ,close_time=datetime.today())
description="lalala", close_time=datetime.today(), max_accepted_applicants=3, working_period="3 Bulan")
application = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="lorem ipsum")
......@@ -157,7 +157,7 @@ class ApplicationTests(APITestCase):
address=None)
new_student = Student.objects.create(user=new_user2, npm=1234123412)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
description="lalala", working_period="3 Bulan",close_time=datetime.today())
description="lalala", close_time=datetime.today(), max_accepted_applicants=3, working_period="3 Bulan")
url = '/api/applications/' + str(new_vacancy.pk) + '/count/'
......@@ -196,7 +196,7 @@ class ApplicationTests(APITestCase):
new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
address=None)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
description="lalala", working_period="3 Bulan",close_time=(timezone.now() - timedelta(days=1)))
description="lalala", close_time=(timezone.now() - timedelta(days=1)), max_accepted_applicants=3, working_period="3 Bulan")
url = '/api/students/' + str(student_id) + '/applied-vacancies/'
response = self.client.post(url, {'vacancy_id': new_vacancy.pk, 'cover_letter': 'this is a cover letter.'},
format='json')
......@@ -308,7 +308,7 @@ class BookmarkApplicationTests(APITestCase):
new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
address=None)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, requirements= "requirements", open_time=datetime.fromtimestamp(1541319300.0),
description="lalala", working_period="3 Bulan",close_time=timezone.now())
description="lalala", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
url = '/api/students/' + str(student_id) + '/bookmarked-vacancies/'
response = self.client.post(url, {'vacancy_id': new_vacancy.pk}, format='json')
......@@ -332,8 +332,8 @@ class VacancyTest(APITestCase):
def test_search_vacancy(self, m):
superuser = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123')
company = Company.objects.create(user=superuser, description="This is a test company")
Vacancy.objects.create(company=company, open_time=datetime.now(), close_time=datetime.now(), name="Software Engineer",working_period="3 Bulan")
Vacancy.objects.create(company=company, open_time=datetime.now(), close_time=datetime.now(), name="Data Engineer",working_period="3 Bulan")
Vacancy.objects.create(company=company, open_time=datetime.now(), close_time=datetime.now(), name="Software Engineer", max_accepted_applicants=3, working_period="3 Bulan")
Vacancy.objects.create(company=company, open_time=datetime.now(), close_time=datetime.now(), name="Data Engineer", max_accepted_applicants=3, working_period="3 Bulan")
m.get('https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG',
json={"username": 'dummy.mahasiswa', "role": 'mahasiswa', "identity_number": '1234567890'},
status_code=200)
......@@ -389,9 +389,9 @@ class VacancyTest(APITestCase):
open_time = datetime(2019, 10, 20)
close_time = datetime(2019, 12, 20)
vacancy1 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time,
description='', close_time=close_time, name='vacancy1',working_period="3 Bulan")
description='', close_time=close_time, name='vacancy1', max_accepted_applicants=3, working_period="3 Bulan")
vacancy2 = Vacancy.objects.create(company=new_company2, verified=True, open_time=open_time,
description='', close_time=close_time, name='vacancy2',working_period="3 Bulan")
description='', close_time=close_time, name='vacancy2', max_accepted_applicants=3, working_period="3 Bulan")
url = '/api/vacancies/?company={}&company={}'.format(new_company.id, new_company2.id)
response = self.client.get(url, format='json')
vacancies = Vacancy.objects.filter(company__id__in=[new_company.id, new_company2.id])
......@@ -451,7 +451,7 @@ class VacancyTest(APITestCase):
new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
address=None)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
description="expired vacancy", close_time=datetime.fromtimestamp(1541319301.0),working_period="3 Bulan")
description="expired vacancy", close_time=datetime.fromtimestamp(1541319301.0), max_accepted_applicants=3, working_period="3 Bulan")
url = '/api/vacancies/?opened_only=true'
response = self.client.get(url, format='json')
......@@ -478,7 +478,8 @@ class VacancyTest(APITestCase):
address=None)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
description="lalala", close_time=timezone.now() + timedelta(minutes = 10),working_period="3 Bulan")
description="lalala", close_time=timezone.now() + timedelta(minutes = 10),
max_accepted_applicants=3, working_period="3 Bulan")
self.client.force_authenticate(user=superuser)
response = new_vacancy.apply_before
......@@ -562,7 +563,7 @@ class CompanyListsTests(APITestCase):
new_student = Student.objects.create(user=new_user2, npm=1234123412)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
description="lalala", requirements= "requirements", close_time=timezone.now(),working_period="3 Bulan")
description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
self.client.force_authenticate(new_user)
......@@ -580,7 +581,7 @@ class CompanyListsTests(APITestCase):
new_student = Student.objects.create(user=new_user2, npm=1234123412)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
description="lalala", requirements= "requirements", close_time=timezone.now(),working_period="3 Bulan")
description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
new_user3 = User.objects.create_user('dummy.company4', 'dummy.company4@company.com', 'lalala123')
......@@ -602,7 +603,7 @@ class CompanyListsTests(APITestCase):
new_student = Student.objects.create(user=new_user2, npm=1234123412)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
description="lalala", requirements= "requirements", close_time=timezone.now(),working_period="3 Bulan")
description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
new_user3 = User.objects.create_user('dummy.company4', 'dummy.company4@company.com', 'lalala123')
......@@ -624,7 +625,7 @@ class CompanyListsTests(APITestCase):
new_student = Student.objects.create(user=new_user2, npm=1234123412)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
description="lalala", requirements= "requirements", close_time=timezone.now(),working_period="3 Bulan")
description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
self.client.force_authenticate(new_user)
......@@ -642,7 +643,7 @@ class CompanyListsTests(APITestCase):
new_student = Student.objects.create(user=new_user2, npm=1234123412)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
description="lalala", requirements= "requirements", close_time=timezone.now(),working_period="3 Bulan")
description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
self.client.force_authenticate(new_user)
......@@ -661,7 +662,7 @@ class CompanyListsTests(APITestCase):
new_student = Student.objects.create(user=new_user2, npm=1234123412)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
description="lalala", requirements= "requirements", close_time=timezone.now(),working_period="3 Bulan")
description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
self.client.force_authenticate(new_user)
......@@ -680,7 +681,7 @@ class CompanyListsTests(APITestCase):
new_student = Student.objects.create(user=new_user2, npm=1234123412)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
description="lalala", requirements= "requirements", close_time=timezone.now(),working_period="3 Bulan")
description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
self.client.force_authenticate(new_user)
......@@ -730,7 +731,7 @@ class SupervisorApprovalTests(APITestCase):
new_company2 = Company.objects.create(user=new_user2, description="lalala", status=Company.VERIFIED, logo=None,
address=None)
new_vacancy2 = Vacancy.objects.create(company=new_company2, verified=False, open_time=datetime.fromtimestamp(1541319300.0),
description="lalala", requirements= "requirements", close_time=timezone.now())
description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3)
url = '/api/vacancies/' + str(new_vacancy2.pk) + '/verify/'
response = self.client.patch(url, {'verified': True}, format='json')
......@@ -746,7 +747,7 @@ class SupervisorApprovalTests(APITestCase):
self.client.force_authenticate(user=new_user)
new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time=datetime.fromtimestamp(1541319300.0),
description="lalala", requirements= "requirements", close_time=timezone.now())
description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3)
url = '/api/vacancies/' + str(new_vacancy.pk) + '/verify/'
response = self.client.patch(url, format='json')
......@@ -1006,10 +1007,10 @@ class AcceptOneOfferTests(APITestCase):
address=None)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
description="lalala", requirements= "requirements", close_time=datetime.today())
description="lalala", requirements= "requirements", close_time=datetime.today(), max_accepted_applicants=3)
new_vacancy2 = Vacancy.objects.create(company=new_company2, verified=True, open_time=datetime.fromtimestamp(0),
description="lalala", requirements= "requirements", close_time=datetime.today())
description="lalala", requirements= "requirements", close_time=datetime.today(), max_accepted_applicants=3)
new_user3 = User.objects.create_user('dummy.student', 'dummy.student@company.com', 'lalala123')
new_student = Student.objects.create(user=new_user3, npm=1234123412)
......
......@@ -98,13 +98,14 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
# if close_time < open_time:
# raise ValidationError('Waktu tutup lowongan harus lebih dari waktu buka lowongan!')
max_accepted_applicants = data['max_accepted_applicants']
if open_time < str(datetime.today()):
raise ValidationError('Waktu buka lowongan harus lebih dari hari ini!')
elif close_time <= open_time:
raise ValidationError('Waktu tutup lowongan harus lebih dari waktu buka lowongan dan tidak sama dengan waktu pembukaan lowongan!')
elif close_time == open_time:
raise ValidationError('Waktu tutup dan buka lowongan tidak boleh sama!')
vacancy = Vacancy(company=company, open_time=open_time, close_time=close_time, name=name, description=description, salary=salary, working_period=working_period, tag=tag)
vacancy = Vacancy(company=company, open_time=open_time, close_time=close_time, name=name, description=description, salary=salary, working_period=working_period, tag=tag, max_accepted_applicants=max_accepted_applicants)
if 'benefits' in data:
vacancy.benefits = data['benefits']
if 'amount' in data:
......@@ -130,6 +131,7 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
description = data['description']
working_period = data['working_period']
requirements = data['requirements']
max_accepted_applicants = data['max_accepted_applicants']
if open_time < str(datetime.today()):
raise ValidationError('Waktu buka lowongan harus lebih dari hari ini!')
elif close_time <= open_time:
......@@ -141,6 +143,7 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
vacancy.name = name
vacancy.salary = salary
vacancy.description = description
vacancy.max_accepted_applicants = max_accepted_applicants
vacancy.working_period = working_period
vacancy.responsibilities = data.get('responsibilities')
if 'benefits' in data:
......
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