From aadcdcdbd3e9caa012257ab830b3ccdd96eb4577 Mon Sep 17 00:00:00 2001 From: Horilla Date: Mon, 9 Oct 2023 16:17:34 +0530 Subject: [PATCH] [UPDT] RECRUITMENT: Candidate profile update method --- .../candidate/candidate_create_form.html | 289 +++++++++++------- recruitment/urls.py | 11 +- recruitment/views/views.py | 33 +- 3 files changed, 218 insertions(+), 115 deletions(-) diff --git a/recruitment/templates/candidate/candidate_create_form.html b/recruitment/templates/candidate/candidate_create_form.html index aeb7f6777..5de92b934 100644 --- a/recruitment/templates/candidate/candidate_create_form.html +++ b/recruitment/templates/candidate/candidate_create_form.html @@ -1,14 +1,25 @@ -{% extends 'index.html' %} -{% block content %} -{% load static %} -{% load i18n %} +{% extends 'index.html' %} {% block content %} {% load static %} {% load i18n %} {% comment %} {% include 'candidate/candidate_nav.html' %} {% endcomment %} - {{form.load}} -
-
-
-
+
+ +
+
{% if messages %}
@@ -22,154 +33,190 @@
{% csrf_token %}
-
-
- {% if form.instance == None or form.instance.profile == None %} - +
+
+ {% if form.instance.profile %} + Username {% else %} - - {% endif %} + Username + {% endif %}
- + {{form.profile.errors}}
- - {{form.name}} - {{form.name.errors}} + + {{form.name}} {{form.name.errors}}
-
- {{form.email}} - {{form.email.errors}} + {{form.email}} {{form.email.errors}}
- {{form.mobile}} - {{form.mobile.errors}} + {{form.mobile}} {{form.mobile.errors}}
- -
- {{form.recruitment_id}} -
+ +
{{form.recruitment_id}}
{{form.recruitment_id.errors}}
- -
- {{form.job_position_id}} -
+ +
{{form.job_position_id}}
{{form.job_position_id.errors}}
- {% comment %}
+ {% comment %} +
- {{form.stage_id}} - {{form.stage_id.errors}} -
{% endcomment %} + {{form.stage_id}} {{form.stage_id.errors}} +
+ {% endcomment %}
-
- - {{form.dob}} - {{form.dob.errors}} +
+ + {{form.dob}} {{form.dob.errors}}
-
+
- {{form.gender}} - {{form.gender.errors}} + {{form.gender}} {{form.gender.errors}}
- {{form.address}} - {{form.address.errors}} + {{form.address}} {{form.address.errors}}
- + {{form.country.errors}} -
- + {{form.state.errors}}
- - {{form.zip}} - {{form.zip.errors}} + + {{form.zip}} {{form.zip.errors}}
- - {{form.resume}} - {{form.resume.errors}} + + {{form.resume}} {{form.resume.errors}}
-
-
- +
- {{form.canceled}} - {{form.canceled.errors}} + {{form.canceled}} {{form.canceled.errors}}
- +
- {{form.is_active}} - {{form.is_active.errors}} + {{form.is_active}} {{form.is_active.errors}}
- +
+
-
-
- - - - - -
- -{% endblock content %} \ No newline at end of file diff --git a/recruitment/urls.py b/recruitment/urls.py index 64cbfb1c8..563fffbfa 100644 --- a/recruitment/urls.py +++ b/recruitment/urls.py @@ -97,7 +97,11 @@ urlpatterns = [ path("create-note//", views.create_note, name="create-note"), path("create-note", views.create_note, name="create-note-post"), path("note-update//", views.note_update, name="note-update"), - path("note-update-individual//", views.note_update_individual, name="note-update-individual"), + path( + "note-update-individual//", + views.note_update_individual, + name="note-update-individual", + ), path( "note-delete//", recruitment.views.actions.note_delete, @@ -132,6 +136,11 @@ urlpatterns = [ views.candidate_update, name="rec-candidate-update", ), + path( + "delete-profile-image//", + views.delete_profile_image, + name="delete-profile-image", + ), path( "candidate-delete//", recruitment.views.actions.candidate_delete, diff --git a/recruitment/views/views.py b/recruitment/views/views.py index 1dc3c453a..62b00ebcc 100644 --- a/recruitment/views/views.py +++ b/recruitment/views/views.py @@ -11,9 +11,10 @@ This module is part of the recruitment project and is intended to provide the main entry points for interacting with the application's functionality. """ - -import contextlib +import os import json +import contextlib +from django.conf import settings from django.http import JsonResponse, HttpResponse, HttpResponseRedirect from django.shortcuts import render, redirect from django.core import serializers @@ -144,7 +145,7 @@ def recruitment_view(request): if not request.GET: request.GET.copy().update({"is_active": "on"}) form = RecruitmentCreationForm() - queryset=Recruitment.objects.all() + queryset = Recruitment.objects.all() if queryset.exists(): template = "recruitment/recruitment_view.html" else: @@ -595,6 +596,7 @@ def note_update(request, note_id): request, "pipeline/pipeline_components/update_note.html", {"form": form} ) + @login_required @permission_required(perm="recruitment.change_stagenote") def note_update_individual(request, note_id): @@ -611,7 +613,9 @@ def note_update_individual(request, note_id): form.save() messages.success(request, _("Note updated successfully...")) response = render( - request, "pipeline/pipeline_components/update_note_individual.html", {"form": form} + request, + "pipeline/pipeline_components/update_note_individual.html", + {"form": form}, ) return HttpResponse( response.content.decode("utf-8") + "" @@ -813,7 +817,7 @@ def candidate_view(request): previous_data = request.GET.urlencode() candidates = Candidate.objects.filter(is_active=True) candidate_all = Candidate.objects.all() - filter_obj = CandidateFilter(request.GET,queryset=candidates) + filter_obj = CandidateFilter(request.GET, queryset=candidates) if candidate_all.exists(): template = "candidate/candidate_view.html" else: @@ -922,6 +926,25 @@ def candidate_update(request, cand_id): return render(request, "candidate/candidate_create_form.html", {"form": form}) +@login_required +@manager_can_enter(perm="recruitment.change_candidate") +def delete_profile_image(request, obj_id): + candidate_obj = Candidate.objects.get(id=obj_id) + try: + if candidate_obj.profile: + file_path = candidate_obj.profile.path + absolute_path = os.path.join(settings.MEDIA_ROOT, file_path) + os.remove(absolute_path) + candidate_obj.profile = None + candidate_obj.save() + messages.success(request, _("Profile image removed.")) + except Exception as e: + pass + return redirect('rec-candidate-update', cand_id=obj_id) + + + + @login_required @permission_required(perm="recruitment.view_history") def candidate_history(request, cand_id):