From ba1095d58a4df5f262c4e92ef03ca0e7cc58006a Mon Sep 17 00:00:00 2001 From: Horilla Date: Mon, 7 Jul 2025 17:25:18 +0530 Subject: [PATCH] [FIX] RECRUITMENT: #811 --- recruitment/forms.py | 21 +- .../templates/candidate/application_form.html | 817 ++++++++---------- recruitment/views/surveys.py | 11 +- templates/country.js | 45 +- 4 files changed, 391 insertions(+), 503 deletions(-) diff --git a/recruitment/forms.py b/recruitment/forms.py index df13f7ee1..857535ab3 100644 --- a/recruitment/forms.py +++ b/recruitment/forms.py @@ -532,19 +532,23 @@ class ApplicationForm(RegistrationForm): self.fields["profile"].required = False def clean(self, *args, **kwargs): - name = self.cleaned_data["name"] + name = self.cleaned_data.get("name") request = getattr(_thread_locals, "request", None) errors = {} - profile = self.cleaned_data["profile"] - resume = self.cleaned_data["resume"] - recruitment: Recruitment = self.cleaned_data["recruitment_id"] - if not resume and not recruitment.optional_resume: - errors["resume"] = _("This field is required") - if not profile and not recruitment.optional_profile_image: - errors["profile"] = _("This field is required") + profile = self.cleaned_data.get("profile") + resume = self.cleaned_data.get("resume") + recruitment: Recruitment = self.cleaned_data.get("recruitment_id") + + if recruitment: + if not resume and not recruitment.optional_resume: + errors["resume"] = _("This field is required") + if not profile and not recruitment.optional_profile_image: + errors["profile"] = _("This field is required") + if errors: raise ValidationError(errors) + if ( not profile and request @@ -552,6 +556,7 @@ class ApplicationForm(RegistrationForm): ): profile_pic_url = f"https://ui-avatars.com/api/?name={name}" self.cleaned_data["profile"] = profile_pic_url + super().clean() return self.cleaned_data diff --git a/recruitment/templates/candidate/application_form.html b/recruitment/templates/candidate/application_form.html index d7faa748c..3501b37aa 100644 --- a/recruitment/templates/candidate/application_form.html +++ b/recruitment/templates/candidate/application_form.html @@ -1,490 +1,365 @@ {% extends 'candidate/application_form_component.html' %} {% block content %} -{% load static %} {% load i18n %} {{form.load}} +{% load static %} {% load i18n %} {{ form.load }}
-
-
-
-
-
-
- {% if messages %} -
- {% for message in messages %} -
- {{ message }} -
- {% endfor %} -
- {% endif %} {% csrf_token %} -
- -
-{% endblock content %} +{% endblock content %} diff --git a/recruitment/views/surveys.py b/recruitment/views/surveys.py index 70ec61180..2f003923d 100644 --- a/recruitment/views/surveys.py +++ b/recruitment/views/surveys.py @@ -338,7 +338,6 @@ def application_form(request): """ This method renders candidate form to create candidate """ - form = ApplicationForm() recruitment = None recruitment_id = request.GET.get("recruitmentId") resume_id = request.GET.get("resumeId") @@ -357,12 +356,7 @@ def application_form(request): messages.error(request, _("Invalid Recruitment ID")) return redirect("open-recruitments") - if resume_obj: - initial_data = {"resume": resume_obj.file.url if resume_obj else None} - form = ApplicationForm(initial=initial_data) - if request.POST: - if "resume" not in request.FILES and resume_id: if resume_obj and resume_obj.file: file_content = resume_obj.file.read() @@ -428,6 +422,11 @@ def application_form(request): form.fields["job_position_id"].queryset = ( form.instance.recruitment_id.open_positions.all() ) + else: + # 811 + initial_data = {"resume": resume_obj.file.url} if resume_obj else {} + form = ApplicationForm(initial=initial_data) + return render( request, "candidate/application_form.html", diff --git a/templates/country.js b/templates/country.js index e92acd7a1..1bf1637eb 100644 --- a/templates/country.js +++ b/templates/country.js @@ -687,43 +687,49 @@ s_a[252] = "Bulawayo|Harare|ManicalandMashonaland Central|Mashonaland East|Mashonaland West|Masvingo|Matabeleland North|Matabeleland South|Midlands"; function populateStates(countryElementId, stateElementId) { - var selectedCountryIndex = - document.getElementById(countryElementId).selectedIndex; - + var selectedCountryIndex = document.getElementById(countryElementId).selectedIndex; var stateElement = document.getElementById(stateElementId); + var selectedState = stateElement?.dataset.selected; stateElement.length = 0; stateElement.options[0] = new Option("Select State", ""); stateElement.selectedIndex = 0; + if (s_a[selectedCountryIndex]) { state_arr = s_a[selectedCountryIndex].split("|"); for (var i = 0; i < state_arr.length; i++) { - let state = state_arr[i].replace(/'/g, '`'); - stateElement.options[stateElement.length] = new Option( - state_arr[i], - state - ); + let stateValue = state_arr[i].replace(/'/g, '`'); + let option = new Option(state_arr[i], stateValue); + if (selectedState && selectedState === stateValue) { + option.selected = true; + } + stateElement.options[stateElement.length] = option; } } } + function populateCountries(countryElementId, stateElementId) { - // given the id of the