Skip to content

Commit

Permalink
Applicant overview page (#829)
Browse files Browse the repository at this point in the history
* get data into frontend

* Add communication with backend

* fix sorting

* improve position seed script

* fix priority

* fix tests, and move choices to global file

* cleanup

* Fix tests, improve error handling

* fix migration

* finalize view own applications

* finalize view own applications

* ruff

* mmore ruff

* more ruff

* mmore ruff :)

* fix traslat

* fix

* reformat again

* ruff

* fun merge

---------

Co-authored-by: Magnus Øvre Sygard <56266980+magsyg@users.noreply.github.com>
Co-authored-by: magsyg <magsyg@github.com>
  • Loading branch information
3 people authored Feb 8, 2024
1 parent e3b7106 commit 7bf73c2
Show file tree
Hide file tree
Showing 23 changed files with 349 additions and 74 deletions.
88 changes: 43 additions & 45 deletions backend/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def seed():
position_data = POSITION_DATA.copy()
position_data.update(
{
'name_nb': f'Stilling {i}',
'name_en': f'Position {i}',
'name_nb': f'{gang.abbreviation} stilling {i}',
'name_en': f'{gang.abbreviation} position {i}',
'gang': gang,
'recruitment': recruitment,
}
Expand Down
3 changes: 0 additions & 3 deletions backend/samfundet/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,19 +587,16 @@ def admissions_count(self, obj: RecruitmentPosition) -> int:
@admin.register(RecruitmentAdmission)
class RecruitmentAdmissionAdmin(CustomBaseAdmin):
sortable_by = [
'id',
'recruitment_position',
'recruitment',
'user',
]
list_display = [
'id',
'recruitment_position',
'recruitment',
'user',
]
search_fields = [
'id',
'recruitment_position',
'recruitment',
'user',
Expand Down
1 change: 0 additions & 1 deletion backend/samfundet/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
https://docs.pytest.org/en/7.1.x/how-to/fixtures.html
"""


TestCase.databases = {'default', 'billig'}


Expand Down
20 changes: 20 additions & 0 deletions backend/samfundet/migrations/0008_alter_recruitmentadmission_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.0 on 2024-02-08 17:15

import uuid
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("samfundet", "0007_recruitmentadmission_withdrawn_and_more"),
]

operations = [
migrations.AlterField(
model_name="recruitmentadmission",
name="id",
field=models.UUIDField(
default=uuid.uuid4, editable=False, primary_key=True, serialize=False
),
),
]
12 changes: 9 additions & 3 deletions backend/samfundet/models/recruitment.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#
# This file contains models spesific to the recruitment system
#

from __future__ import annotations

import uuid

from django.db import models
from django.utils import timezone
from django.core.exceptions import ValidationError

from root.utils.mixins import CustomBaseModel, FullCleanSaveMixin

from samfundet.models.model_choices import RecruitmentStatusChoices, RecruitmentPriorityChoices

from .general import Gang, User, Organization
from .model_choices import RecruitmentStatusChoices, RecruitmentPriorityChoices


class Recruitment(CustomBaseModel):
Expand Down Expand Up @@ -155,6 +155,7 @@ class Interview(CustomBaseModel):


class RecruitmentAdmission(CustomBaseModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
admission_text = models.TextField(help_text='Admission text for the admission')
recruitment_position = models.ForeignKey(
RecruitmentPosition, on_delete=models.CASCADE, help_text='The recruitment position that is recruiting', related_name='admissions'
Expand Down Expand Up @@ -184,6 +185,11 @@ def __str__(self) -> str:

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.applicant_priority:
current_applications_count = RecruitmentAdmission.objects.filter(user=self.user).count()
# Set the applicant_priority to the number of applications + 1 (for the current application)
self.applicant_priority = current_applications_count + 1
"""If the admission is saved without an interview, try to find an interview from a shared position."""
if self.withdrawn:
self.recruiter_priority = RecruitmentPriorityChoices.NOT_WANTED
self.recruiter_status = RecruitmentStatusChoices.AUTOMATIC_REJECTION
Expand Down
35 changes: 35 additions & 0 deletions backend/samfundet/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,47 @@ def update(self, instance: RecruitmentPosition, validated_data: dict) -> Recruit
return updated_instance


class ApplicantInterviewSerializer(serializers.ModelSerializer):
class Meta:
model = Interview
fields = [
'id',
'interview_time',
'interview_location',
]


class RecruitmentPositionForApplicantSerializer(serializers.ModelSerializer):
class Meta:
model = RecruitmentPosition
fields = [
'id',
'name_nb',
'name_en',
'short_description_nb',
'short_description_en',
'long_description_nb',
'long_description_en',
'is_funksjonaer_position',
'default_admission_letter_nb',
'default_admission_letter_en',
'gang',
'recruitment',
]


class RecruitmentAdmissionForApplicantSerializer(serializers.ModelSerializer):
interview = ApplicantInterviewSerializer(read_only=True)
recruitment_position = RecruitmentPositionForApplicantSerializer(read_only=True)

class Meta:
model = RecruitmentAdmission
fields = [
'id',
'admission_text',
'recruitment_position',
'applicant_priority',
'interview',
'created_at',
'withdrawn',
]
Expand Down
2 changes: 1 addition & 1 deletion backend/samfundet/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,4 +678,4 @@ def test_recruitment_admission_for_applicant(
# Assert the returned data based on the logic in the view
assert len(response.data) == 1
assert response.data[0]['admission_text'] == fixture_recruitment_admission.admission_text
assert response.data[0]['recruitment_position'] == fixture_recruitment_admission.recruitment_position.id
assert response.data[0]['recruitment_position']['id'] == fixture_recruitment_admission.recruitment_position.id
Loading

0 comments on commit 7bf73c2

Please sign in to comment.