From 7cb4bb5f5e642fad8ce57514d54b464f7fdbcacd Mon Sep 17 00:00:00 2001 From: magsyg Date: Mon, 16 Dec 2024 23:44:40 +0100 Subject: [PATCH] fix: only 1 application for position per user enforced --- backend/samfundet/models/recruitment.py | 5 ++++- backend/samfundet/views.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/samfundet/models/recruitment.py b/backend/samfundet/models/recruitment.py index aebd4a9b1..88a420629 100644 --- a/backend/samfundet/models/recruitment.py +++ b/backend/samfundet/models/recruitment.py @@ -386,7 +386,10 @@ def clean(self, *args: tuple, **kwargs: dict) -> None: # noqa: C901 current_application = RecruitmentApplication.objects.filter( pk=self.pk).first() # validates if there are not two applications for same user and same recruitmentposition - if not current_application and RecruitmentApplication.objects.filter(user=self.user, recruitment=self.recruitment, recruitment_position=self.recruitment_position).first(): + if not current_application and RecruitmentApplication.objects.filter( + user=self.user, + recruitment=self.recruitment, + recruitment_position=self.recruitment_position).first(): errors['recruitment_position'].append(self.ALREADY_APPLIED_ERROR) # If there is max applications, check if applicant have applied to not to many if self.recruitment.max_applications: diff --git a/backend/samfundet/views.py b/backend/samfundet/views.py index 68d987833..7f815d5a8 100644 --- a/backend/samfundet/views.py +++ b/backend/samfundet/views.py @@ -27,9 +27,9 @@ from django.shortcuts import get_object_or_404 from django.contrib.auth import login, logout, update_session_auth_hash from django.utils.encoding import force_bytes +from django.core.exceptions import ValidationError from django.middleware.csrf import get_token from django.utils.decorators import method_decorator -from django.core.exceptions import ValidationError from django.contrib.auth.models import Group, Permission from django.views.decorators.csrf import csrf_protect, ensure_csrf_cookie