[FIX] RECRUITMENT: #853

This commit is contained in:
Horilla
2025-07-29 12:43:04 +05:30
parent f019a10739
commit 0dadb31338
3 changed files with 16 additions and 29 deletions

View File

@@ -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)

View File

@@ -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,
}

View File

@@ -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]
)