Skip to content

Commit

Permalink
Create backend for interview rooms (#695)
Browse files Browse the repository at this point in the history
* Create backend for interview rooms
  • Loading branch information
Mathias-a authored Sep 25, 2023
1 parent 5480078 commit e31ac3f
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 6 deletions.
13 changes: 12 additions & 1 deletion backend/root/utils/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
DO NOT WRITE IN THIS FILE, AS IT WILL BE OVERWRITTEN ON NEXT UPDATE.
THIS FILE WAS GENERATED BY: root.management.commands.generate_routes
LAST UPDATE: 2023-09-14 19:45:16.057665+00:00
LAST UPDATE: 2023-09-24 15:12:38.294245+00:00
"""

############################################################
Expand Down Expand Up @@ -344,6 +344,15 @@
admin__samfundet_organization_delete = 'admin:samfundet_organization_delete'
admin__samfundet_organization_change = 'admin:samfundet_organization_change'
adminsamfundetorganization__objectId = ''
admin__samfundet_interviewroom_permissions = 'admin:samfundet_interviewroom_permissions'
admin__samfundet_interviewroom_permissions_manage_user = 'admin:samfundet_interviewroom_permissions_manage_user'
admin__samfundet_interviewroom_permissions_manage_group = 'admin:samfundet_interviewroom_permissions_manage_group'
admin__samfundet_interviewroom_changelist = 'admin:samfundet_interviewroom_changelist'
admin__samfundet_interviewroom_add = 'admin:samfundet_interviewroom_add'
admin__samfundet_interviewroom_history = 'admin:samfundet_interviewroom_history'
admin__samfundet_interviewroom_delete = 'admin:samfundet_interviewroom_delete'
admin__samfundet_interviewroom_change = 'admin:samfundet_interviewroom_change'
adminsamfundetinterviewroom__objectId = ''
admin__samfundet_notification_changelist = 'admin:samfundet_notification_changelist'
admin__samfundet_notification_add = 'admin:samfundet_notification_add'
admin__samfundet_notification_history = 'admin:samfundet_notification_history'
Expand Down Expand Up @@ -404,6 +413,8 @@
samfundet__table_detail = 'samfundet:table-detail'
samfundet__text_item_list = 'samfundet:text_item-list'
samfundet__text_item_detail = 'samfundet:text_item-detail'
samfundet__interview_rooms_list = 'samfundet:interview_rooms-list'
samfundet__interview_rooms_detail = 'samfundet:interview_rooms-detail'
samfundet__infobox_list = 'samfundet:infobox-list'
samfundet__infobox_detail = 'samfundet:infobox-detail'
samfundet__key_value_list = 'samfundet:key_value-list'
Expand Down
11 changes: 10 additions & 1 deletion backend/samfundet/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
CustomGuardedModelAdmin,
)
from .models.event import (Event, EventGroup, EventRegistration)
from .models.recruitment import (Recruitment, RecruitmentPosition, RecruitmentAdmission)
from .models.recruitment import (Recruitment, RecruitmentPosition, RecruitmentAdmission, InterviewRoom)
from .models.general import (
Tag,
User,
Expand Down Expand Up @@ -567,4 +567,13 @@ class OrganizationAdmin(CustomGuardedModelAdmin):
list_select_related = True


@admin.register(InterviewRoom)
class InterviewRoomAdmin(CustomGuardedModelAdmin):
list_filter = ['name', 'location', 'recruitment', 'gang', 'start_time', 'end_time']
list_display = ['name', 'location', 'recruitment', 'gang', 'start_time', 'end_time']
search_fields = ['name', 'location', 'recruitment__name', 'gang__name']
list_display_links = ['name', 'location']
list_select_related = ['recruitment', 'gang']


### End: Our models ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 4.2.3 on 2023-09-24 15:26

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('samfundet', '0037_alter_user_options'),
]

operations = [
migrations.AlterField(
model_name='recruitmentadmission',
name='interview_location',
field=models.CharField(blank=True, help_text='Where the intevjuee should wait', max_length=100, null=True),
),
migrations.CreateModel(
name='InterviewRoom',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(help_text='Name of the room', max_length=255)),
('location', models.CharField(help_text='Physical location, eg. campus', max_length=255)),
('start_time', models.DateTimeField(help_text='Start time of availability')),
('end_time', models.DateTimeField(help_text='End time of availability')),
('gang', models.ForeignKey(blank=True, help_text='The gang that booked the room', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='rooms', to='samfundet.gang')),
('recruitment', models.ForeignKey(help_text='The recruitment that is recruiting', on_delete=django.db.models.deletion.CASCADE, related_name='rooms', to='samfundet.recruitment')),
],
),
migrations.AddField(
model_name='recruitmentadmission',
name='room',
field=models.ForeignKey(blank=True, help_text='Room where the interview is held', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='interviews', to='samfundet.interviewroom'),
),
]
28 changes: 27 additions & 1 deletion backend/samfundet/models/recruitment.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ def __str__(self) -> str:
return f'Position: {self.name_en} in {self.recruitment}'


class InterviewRoom(models.Model):
name = models.CharField(max_length=255, help_text='Name of the room')
location = models.CharField(max_length=255, help_text='Physical location, eg. campus')
start_time = models.DateTimeField(help_text='Start time of availability')
end_time = models.DateTimeField(help_text='End time of availability')
recruitment = models.ForeignKey(Recruitment, on_delete=models.CASCADE, help_text='The recruitment that is recruiting', related_name='rooms')
gang = models.ForeignKey(to=Gang, on_delete=models.CASCADE, help_text='The gang that booked the room', related_name='rooms', blank=True, null=True)

def __str__(self) -> str:
return self.name

def clean(self) -> None:
if self.start_time > self.end_time:
raise ValidationError('Start time should be before end time')

super().clean()


class RecruitmentAdmission(models.Model):
admission_text = models.TextField(help_text='Admission text for the admission')
recruitment_position = models.ForeignKey(
Expand All @@ -104,7 +122,15 @@ class RecruitmentAdmission(models.Model):
applicant_priority = models.IntegerField(help_text='The priority of the admission')

interview_time = models.DateTimeField(help_text='The time of the interview', null=True, blank=True)
interview_location = models.CharField(max_length=100, help_text='The location of the interview', null=True, blank=True)
interview_location = models.CharField(max_length=100, help_text='Where the intevjuee should wait', null=True, blank=True)
room = models.ForeignKey(
InterviewRoom,
on_delete=models.SET_NULL,
null=True,
blank=True,
help_text='Room where the interview is held',
related_name='interviews',
)

PRIORITY_CHOICES = [
(0, 'Not Set'),
Expand Down
9 changes: 8 additions & 1 deletion backend/samfundet/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rest_framework import serializers

from .models.billig import BilligEvent, BilligTicketGroup, BilligPriceGroup
from .models.recruitment import (Recruitment, RecruitmentPosition, RecruitmentAdmission)
from .models.recruitment import (Recruitment, RecruitmentPosition, RecruitmentAdmission, InterviewRoom)
from .models.event import (Event, EventGroup, EventCustomTicket)
from .models.general import (
Tag,
Expand Down Expand Up @@ -561,3 +561,10 @@ class RecruitmentAdmissionForGangSerializer(serializers.ModelSerializer):
class Meta:
model = RecruitmentAdmission
fields = '__all__'


class InterviewRoomSerializer(serializers.ModelSerializer):

class Meta:
model = InterviewRoom
fields = '__all__'
1 change: 1 addition & 0 deletions backend/samfundet/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
router.register('booking', views.BookingView, 'booking')
router.register('table', views.TableView, 'table')
router.register('textitem', views.TextItemView, 'text_item')
router.register('interview-rooms', views.InterviewRoomView, 'interview_rooms')
router.register('infobox', views.InfoboxView, 'infobox')
router.register('key-value', views.KeyValueView, 'key_value')
router.register('organizations', views.OrganizationView, 'organizations')
Expand Down
17 changes: 17 additions & 0 deletions backend/samfundet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
Recruitment,
RecruitmentPosition,
RecruitmentAdmission,
InterviewRoom,
)
from .models.general import (
Tag,
Expand Down Expand Up @@ -81,6 +82,7 @@
OrganizationSerializer,
FoodCategorySerializer,
ClosedPeriodSerializer,
InterviewRoomSerializer,
FoodPreferenceSerializer,
UserPreferenceSerializer,
InformationPageSerializer,
Expand Down Expand Up @@ -595,3 +597,18 @@ def get_queryset(self) -> Response:
Returns all active recruitment positions.
"""
return RecruitmentPosition.objects.filter(recruitment__visible_from__lte=timezone.now(), recruitment__actual_application_deadline__gte=timezone.now())


class InterviewRoomView(ModelViewSet):
permission_classes = [AllowAny]
serializer_class = InterviewRoomSerializer
queryset = InterviewRoom.objects.all()

def list(self, request: Request) -> Response:
recruitment = request.query_params.get('recruitment')
if not recruitment:
return Response({'error': 'A recruitment parameter is required'}, status=status.HTTP_400_BAD_REQUEST)

filtered_rooms = InterviewRoom.objects.filter(recruitment__id=recruitment)
serialized_rooms = self.get_serializer(filtered_rooms, many=True)
return Response(serialized_rooms.data)
15 changes: 13 additions & 2 deletions frontend/src/routes/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ THIS FILE IS AUTOGENERATED.
DO NOT WRITE IN THIS FILE, AS IT WILL BE OVERWRITTEN ON NEXT UPDATE.
THIS FILE WAS GENERATED BY: root.management.commands.generate_routes
LAST UPDATE: 2023-09-22 09:21:59.070385+00:00
LAST UPDATE: 2023-09-24 15:12:38.294245+00:00
"""
*/
// ############################################################
Expand Down Expand Up @@ -343,6 +343,15 @@ export const ROUTES_BACKEND = {
admin__samfundet_organization_delete: '/admin/samfundet/organization/:objectId/delete/',
admin__samfundet_organization_change: '/admin/samfundet/organization/:objectId/change/',
adminsamfundetorganization__objectId: '/admin/samfundet/organization/:objectId/',
admin__samfundet_interviewroom_permissions: '/admin/samfundet/interviewroom/:objectPk/permissions/',
admin__samfundet_interviewroom_permissions_manage_user: '/admin/samfundet/interviewroom/:objectPk/permissions/user-manage/:userId/',
admin__samfundet_interviewroom_permissions_manage_group: '/admin/samfundet/interviewroom/:objectPk/permissions/group-manage/:groupId/',
admin__samfundet_interviewroom_changelist: '/admin/samfundet/interviewroom/',
admin__samfundet_interviewroom_add: '/admin/samfundet/interviewroom/add/',
admin__samfundet_interviewroom_history: '/admin/samfundet/interviewroom/:objectId/history/',
admin__samfundet_interviewroom_delete: '/admin/samfundet/interviewroom/:objectId/delete/',
admin__samfundet_interviewroom_change: '/admin/samfundet/interviewroom/:objectId/change/',
adminsamfundetinterviewroom__objectId: '/admin/samfundet/interviewroom/:objectId/',
admin__samfundet_notification_changelist: '/admin/samfundet/notification/',
admin__samfundet_notification_add: '/admin/samfundet/notification/add/',
admin__samfundet_notification_history: '/admin/samfundet/notification/:objectId/history/',
Expand Down Expand Up @@ -403,6 +412,8 @@ export const ROUTES_BACKEND = {
samfundet__table_detail: '/api/table/:pk/',
samfundet__text_item_list: '/api/textitem/',
samfundet__text_item_detail: '/api/textitem/:pk/',
samfundet__interview_rooms_list: '/api/interview-rooms/',
samfundet__interview_rooms_detail: '/api/interview-rooms/:pk/',
samfundet__infobox_list: '/api/infobox/',
samfundet__infobox_detail: '/api/infobox/:pk/',
samfundet__key_value_list: '/api/key-value/',
Expand Down Expand Up @@ -436,4 +447,4 @@ export const ROUTES_BACKEND = {
samfundet__applicants_without_interviews: '/applicants-without-interviews/',
static__path: '/static/:path',
media__path: '/media/:path',
} as const;
} as const;

0 comments on commit e31ac3f

Please sign in to comment.