Skip to content

Commit

Permalink
Create relations between recruitment positions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias-a committed Oct 7, 2023
1 parent b2b81e8 commit a0f5c5a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.3 on 2023-10-03 20:13
# Generated by Django 4.2.3 on 2023-10-07 22:02

from django.conf import settings
from django.db import migrations, models
Expand All @@ -24,6 +24,11 @@ class Migration(migrations.Migration):
model_name='recruitmentadmission',
name='room',
),
migrations.AddField(
model_name='recruitmentposition',
name='shared_interview_positions',
field=models.ManyToManyField(blank=True, help_text='Positions with shared interview', to='samfundet.recruitmentposition'),
),
migrations.AlterField(
model_name='recruitmentposition',
name='interviewers',
Expand Down
22 changes: 22 additions & 0 deletions backend/samfundet/models/recruitment.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class RecruitmentPosition(models.Model):
blank=True,
)

shared_interview_positions = models.ManyToManyField("self", symmetrical=True, blank=True, help_text="Positions with shared interview")

# TODO: Implement tag functionality
tags = models.CharField(max_length=100, help_text='Tags for the position')

Expand Down Expand Up @@ -163,3 +165,23 @@ class RecruitmentAdmission(models.Model):

def __str__(self) -> str:
return f'Admission: {self.user} for {self.recruitment_position} in {self.recruitment}'

def save(self, *args: tuple, **kwargs: dict) -> None:
"""
If the admission is saved without an interview, try to find an interview from a shared position.
"""
if not self.interview:
# Check if there is already an interview for the same user in shared positions
shared_interview_positions = self.recruitment_position.shared_interview_positions.all()
shared_interview = RecruitmentAdmission.objects.filter(user=self.user,
recruitment_position__in=shared_interview_positions).exclude(interview=None).first()

if shared_interview:
self.interview = shared_interview.interview
else:
# Create a new interview instance if needed
new_interview = Interview()
new_interview.save()
self.interview = new_interview

super(RecruitmentAdmission, self).save(*args, **kwargs)
13 changes: 12 additions & 1 deletion backend/samfundet/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,19 @@ class Meta:

class RecruitmentAdmissionForGangSerializer(serializers.ModelSerializer):
user = ApplicantInfoSerializer(read_only=True)
interview = InterviewSerializer(many=True, read_only=False)
interview = InterviewSerializer(read_only=False)

class Meta:
model = RecruitmentAdmission
fields = '__all__'

def update(self, instance: RecruitmentAdmission, validated_data: dict) -> RecruitmentAdmission:
interview_data = validated_data.pop('interview', {})

interview_instance = instance.interview
interview_instance.interview_location = interview_data.get('interview_location', interview_instance.interview_location)
interview_instance.interview_time = interview_data.get('interview_time', interview_instance.interview_time)
interview_instance.save()

# Update other fields of RecruitmentAdmission instance
return super(RecruitmentAdmissionForGangSerializer, self).update(instance, validated_data)
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ export function RecruitmentPositionOverviewPage() {
{
content: (
<InputField
value={admission.interview_time ? utcTimestampToLocal(admission.interview_time) : ''}
value={admission.interview.interview_time ? utcTimestampToLocal(admission.interview.interview_time) : ''}
onBlur={() => putRecruitmentAdmissionForGang(admission.id.toString(), admission)}
onChange={(value: string) => {
const newAdmission = { ...admission, interview_time: value.toString() };
const updatedInterview = { ...admission.interview, interview_time: value.toString() };
const newAdmission = { ...admission, interview: updatedInterview };
setRecruitmentApplicants(immutableSet(recruitmentApplicants, admission, newAdmission));
}}
type="datetime-local"
Expand All @@ -105,10 +106,11 @@ export function RecruitmentPositionOverviewPage() {
{
content: (
<InputField
value={admission.interview_location ?? ''}
value={admission.interview.interview_location ?? ''}
onBlur={() => putRecruitmentAdmissionForGang(admission.id.toString(), admission)}
onChange={(value: string) => {
const newAdmission = { ...admission, interview_location: value.toString() };
const updatedInterview = { ...admission.interview, interview_location: value.toString() };
const newAdmission = { ...admission, interview: updatedInterview };
setRecruitmentApplicants(immutableSet(recruitmentApplicants, admission, newAdmission));
}}
/>
Expand Down

0 comments on commit a0f5c5a

Please sign in to comment.