Skip to content

Commit 0b4ee68

Browse files
committed
feat: ApplicationAttachment
1 parent 193369f commit 0b4ee68

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

backend/samfundet/models/recruitment.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class RecruitmentPosition(CustomBaseModel):
167167
# TODO: Implement interviewer functionality
168168
interviewers = models.ManyToManyField(to=User, help_text='Interviewers for the position', blank=True, related_name='interviewers')
169169

170+
#FIX: Add functionality for setting allowed attachments for application
170171
recruitment = models.ForeignKey(
171172
Recruitment,
172173
on_delete=models.CASCADE,
@@ -319,14 +320,15 @@ def resolve_gang(self, *, return_id: bool = False) -> Gang | int:
319320
return self.room.resolve_gang(return_id=return_id)
320321

321322

323+
322324
class RecruitmentApplication(CustomBaseModel):
323325
# UUID so that applicants cannot see recruitment info with their own id number
324326
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
325327
application_text = models.TextField(help_text='Application text')
326328
recruitment_position = models.ForeignKey(
327329
RecruitmentPosition, on_delete=models.CASCADE, help_text='The position which is recruiting', related_name='applications'
328330
)
329-
recruitment = models.ForeignKey(Recruitment, on_delete=models.CASCADE, help_text='The recruitment that is recruiting', related_name='applications')
331+
recruitment = models.ForeignKey(Recruitment, on_delete=models.CASCADE, null=True, help_text='The recruitment that is recruiting', related_name='applications')
330332
user = models.ForeignKey(User, on_delete=models.CASCADE, help_text='The user that is applying', related_name='applications')
331333
applicant_priority = models.PositiveIntegerField(null=True, blank=True, help_text='The priority of the application')
332334

@@ -490,6 +492,30 @@ def update_applicant_state(self) -> None:
490492
application.applicant_state = RecruitmentApplicantStates.NOT_WANTED
491493
application.save()
492494

495+
class ApplicationFileAttachment(CustomBaseModel):
496+
application = models.ForeignKey(RecruitmentApplication,
497+
on_delete=models.CASCADE,
498+
related_name="attachments",
499+
help_text="The recruitment application this file is attached to")
500+
application_file = models.FileField(upload_to="some/path")
501+
application_file_type = models.CharField(max_length=50, blank=True)
502+
503+
def clean(self) -> None:
504+
super().clean()
505+
if self.file:
506+
file_type = self.file.content_type
507+
self.file_type = file_type
508+
allowed_types = [
509+
'image/jpeg', 'image/png', # Images
510+
'video/mp4' # Video
511+
]
512+
if file_type not in allowed_types:
513+
raise ValidationError('Wrong filetype')
514+
if self.file.size > 10 * 1024 * 1024: # 10MB limit
515+
raise ValidationError('File size must be less than 10MB.')
516+
517+
def __str__(self):
518+
return f'Attachment for {self.application} - {self.file.name}'
493519

494520
class RecruitmentInterviewAvailability(CustomBaseModel):
495521
"""This models all possible times for interviews for the given recruitment.

backend/samfundet/serializers.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
UserFeedbackModel,
5555
)
5656
from .models.recruitment import (
57+
ApplicationFileAttachment,
5758
Interview,
5859
Recruitment,
5960
InterviewRoom,
@@ -80,6 +81,21 @@
8081
from rest_framework.utils.serializer_helpers import ReturnList
8182

8283

84+
class ApplicationFileAttachmentSerializer(CustomBaseSerializer):
85+
class Meta:
86+
model = ApplicationFileAttachment
87+
88+
def validate(self, attrs: dict) -> dict:
89+
admission_image = attrs.get('admission_image')
90+
91+
# if admission_image:
92+
# is_image_valid(admission_image)
93+
# else:
94+
# msg = 'Image is invalid'
95+
# raise serializers.ValidationError(msg, code="authorization")
96+
# if
97+
98+
8399
class TagSerializer(CustomBaseSerializer):
84100
class Meta:
85101
model = Tag
@@ -1167,6 +1183,7 @@ class RecruitmentApplicationForGangSerializer(CustomBaseSerializer):
11671183
interview = InterviewSerializer(read_only=False)
11681184
interviewers = InterviewerSerializer(many=True, read_only=True)
11691185
recruitment_position = RecruitmentPositionSerializer(read_only=True)
1186+
application_attachment = ApplicationFileAttachmentSerializer(read_only=True)
11701187
application_count = serializers.SerializerMethodField(method_name='get_application_count', read_only=True)
11711188

11721189
class Meta:

0 commit comments

Comments
 (0)