From 0dadb31338074eb34a65004470c1d45670b3cd5e Mon Sep 17 00:00:00 2001 From: Horilla Date: Tue, 29 Jul 2025 12:43:04 +0530 Subject: [PATCH] [FIX] RECRUITMENT: #853 --- recruitment/models.py | 24 +++++++++++++++--------- recruitment/views/actions.py | 1 + recruitment/views/surveys.py | 20 -------------------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/recruitment/models.py b/recruitment/models.py index 6cdf00305..eca9fc153 100644 --- a/recruitment/models.py +++ b/recruitment/models.py @@ -8,21 +8,16 @@ This module is used to register models for recruitment app import json import os import re -from datetime import date from uuid import uuid4 import django import requests from django import forms -from django.conf import settings from django.core.exceptions import ValidationError from django.core.files.storage import default_storage from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models -from django.db.models.signals import m2m_changed, post_save -from django.dispatch import receiver -from django.http import JsonResponse -from django.urls import reverse_lazy +from django.utils.text import slugify from django.utils.translation import gettext_lazy as _ from base.horilla_company_manager import HorillaCompanyManager @@ -346,6 +341,16 @@ class Stage(HorillaModel): } +def candidate_upload_path(instance, filename): + """ + Generates a unique file path for candidate profile & resume uploads. + """ + ext = filename.split(".")[-1] + name_slug = slugify(instance.name) or "candidate" + unique_filename = f"{name_slug}-{uuid4().hex[:8]}.{ext}" + return f"recruitment/{name_slug}/{unique_filename}" + + class Candidate(HorillaModel): """ Candidate model @@ -365,7 +370,7 @@ class Candidate(HorillaModel): ("other", _("Other")), ] name = models.CharField(max_length=100, null=True, verbose_name=_("Name")) - profile = models.ImageField(upload_to=candidate_photo_upload_path, null=True) + profile = models.ImageField(upload_to=candidate_upload_path, null=True) # 853 portfolio = models.URLField(max_length=200, blank=True) recruitment_id = models.ForeignKey( Recruitment, @@ -408,7 +413,7 @@ class Candidate(HorillaModel): verbose_name=_("Mobile"), ) resume = models.FileField( - upload_to="recruitment/resume", + upload_to=candidate_upload_path, # 853 validators=[ validate_pdf, ], @@ -566,7 +571,8 @@ class Candidate(HorillaModel): def get_interview(self): """ - This method is used to get the interview dates and times for the candidate for the mail templates + This method is used to get the interview dates and times + for the candidate for the mail templates """ interviews = InterviewSchedule.objects.filter(candidate_id=self.id) diff --git a/recruitment/views/actions.py b/recruitment/views/actions.py index 2bb9963d9..ec9abc8e3 100644 --- a/recruitment/views/actions.py +++ b/recruitment/views/actions.py @@ -468,6 +468,7 @@ def get_mail_preview(request): candidate_obj = Candidate.objects.get(id=candidate_id) context = { "instance": candidate_obj, + "model_instance": candidate_obj, "self": request.user.employee_get, "request": request, } diff --git a/recruitment/views/surveys.py b/recruitment/views/surveys.py index 2f003923d..ba0bb58f9 100644 --- a/recruitment/views/surveys.py +++ b/recruitment/views/surveys.py @@ -376,26 +376,6 @@ def application_form(request): candidate_obj.stage_id = stages.order_by("sequence").first() messages.success(request, _("Application saved.")) - resume = request.FILES.get("resume") - if resume: - resume_path = f"recruitment/resume/{resume.name}" - attachment_dir = os.path.dirname(default_storage.path(resume_path)) - if not os.path.exists(attachment_dir): - os.makedirs(attachment_dir) - with default_storage.open(resume_path, "wb+") as destination: - for chunk in resume.chunks(): - destination.write(chunk) - - candidate_obj.resume = resume_path - try: - profile = request.FILES["profile"] if request.FILES["profile"] else None - profile_path = f"recruitment/profile/{candidate_obj.name.replace(' ', '_')}_{profile.name}_{uuid4()}" - with default_storage.open(profile_path, "wb+") as destination: - for chunk in profile.chunks(): - destination.write(chunk) - candidate_obj.profile = profile_path - except: - pass request.session["candidate"] = serializers.serialize( "json", [candidate_obj] )