[UPDT] RECRUITMENT: Candidate create and update form updated to as_p style
This commit is contained in:
@@ -344,16 +344,27 @@ class CandidateCreationForm(ModelForm):
|
||||
"""
|
||||
|
||||
model = Candidate
|
||||
fields = "__all__"
|
||||
exclude = [
|
||||
"confirmation",
|
||||
"scheduled_for",
|
||||
"schedule_date",
|
||||
"joining_date",
|
||||
"sequence",
|
||||
"stage_id",
|
||||
"offerletter_status",
|
||||
fields = [
|
||||
"profile",
|
||||
"name",
|
||||
"portfolio",
|
||||
"email",
|
||||
"mobile",
|
||||
"recruitment_id",
|
||||
"job_position_id",
|
||||
"dob",
|
||||
"gender",
|
||||
"address",
|
||||
"source",
|
||||
"country",
|
||||
"state",
|
||||
"zip",
|
||||
"resume",
|
||||
"referral",
|
||||
"canceled",
|
||||
"is_active",
|
||||
]
|
||||
|
||||
widgets = {
|
||||
"scheduled_date": forms.DateInput(attrs={"type": "date"}),
|
||||
"dob": forms.DateInput(attrs={"type": "date"}),
|
||||
@@ -384,6 +395,16 @@ class CandidateCreationForm(ModelForm):
|
||||
self.instance.job_position_id = job_position
|
||||
return super().save(commit)
|
||||
|
||||
def as_p(self, *args, **kwargs):
|
||||
"""
|
||||
Render the form fields as HTML table rows with Bootstrap styling.
|
||||
"""
|
||||
context = {"form": self}
|
||||
table_html = render_to_string(
|
||||
"candidate/candidate_create_form_as_p.html", context
|
||||
)
|
||||
return table_html
|
||||
|
||||
def clean(self):
|
||||
if self.instance.name is not None:
|
||||
self.errors.pop("job_position_id", None)
|
||||
@@ -644,9 +665,7 @@ class QuestionForm(ModelForm):
|
||||
required=False,
|
||||
label=_("Recruitment"),
|
||||
)
|
||||
# job_positions = forms.ModelMultipleChoiceField(
|
||||
# queryset=JobPosition.objects.all(), required=False, label=_("Job Positions")
|
||||
# )
|
||||
options = forms.CharField(widget=forms.TextInput, label=_("Options"), required=True)
|
||||
|
||||
class Meta:
|
||||
"""
|
||||
@@ -655,11 +674,7 @@ class QuestionForm(ModelForm):
|
||||
|
||||
model = RecruitmentSurvey
|
||||
fields = "__all__"
|
||||
exclude = [
|
||||
"recruitment_ids",
|
||||
"job_position_ids",
|
||||
"is_active",
|
||||
]
|
||||
exclude = ["recruitment_ids", "job_position_ids", "is_active", "options"]
|
||||
labels = {
|
||||
"question": _("Question"),
|
||||
"sequence": _("Sequence"),
|
||||
@@ -679,33 +694,78 @@ class QuestionForm(ModelForm):
|
||||
return table_html
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
cleaned_data = super().clean()
|
||||
recruitment = self.cleaned_data["recruitment"]
|
||||
# jobs = self.cleaned_data["job_positions"]
|
||||
qtype = self.cleaned_data["type"]
|
||||
question_type = self.cleaned_data["type"]
|
||||
options = self.cleaned_data["options"]
|
||||
if not recruitment.exists(): # or jobs.exists()):
|
||||
raise ValidationError(
|
||||
{"recruitment": _("Choose any recruitment to apply this question")}
|
||||
)
|
||||
self.recruitment = recruitment
|
||||
# self.job_positions = jobs
|
||||
|
||||
if qtype in ["options", "multiple"] and (options is None or options == ""):
|
||||
if question_type in ["options", "multiple"] and (
|
||||
options is None or options == ""
|
||||
):
|
||||
raise ValidationError({"options": "Options field is required"})
|
||||
return cleaned_data
|
||||
|
||||
return
|
||||
def save(self, commit=True):
|
||||
instance = super().save(commit=False)
|
||||
if instance.type in ["options", "multiple"]:
|
||||
additional_options = []
|
||||
for key, value in self.cleaned_data.items():
|
||||
if key.startswith("options") and value:
|
||||
additional_options.append(value)
|
||||
|
||||
instance.options = ",".join(additional_options)
|
||||
if commit:
|
||||
instance.save()
|
||||
self.save_m2m()
|
||||
else:
|
||||
instance.options = ""
|
||||
return instance
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
instance = kwargs.get("instance", None)
|
||||
self.option_count = 1
|
||||
|
||||
def create_options_field(option_key, initial=None):
|
||||
self.fields[option_key] = forms.CharField(
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"name": option_key,
|
||||
"id": f"id_{option_key}",
|
||||
"class": "oh-input w-100",
|
||||
}
|
||||
),
|
||||
label=_("Options"),
|
||||
required=True,
|
||||
initial=initial,
|
||||
)
|
||||
|
||||
if instance:
|
||||
split_options = instance.options.split(",")
|
||||
for i, option in enumerate(split_options):
|
||||
if i == 0:
|
||||
create_options_field("options", option)
|
||||
else:
|
||||
self.option_count += 1
|
||||
create_options_field(f"options{i}", option)
|
||||
|
||||
if instance:
|
||||
self.fields["recruitment"].initial = instance.recruitment_ids.all()
|
||||
# self.fields["job_positions"].initial = instance.job_position_ids.all()
|
||||
self.fields["type"].widget.attrs.update(
|
||||
{"class": " w-100", "style": "border:solid 1px #6c757d52;height:50px;"}
|
||||
)
|
||||
self.fields["options"].required = False
|
||||
for key, value in self.data.items():
|
||||
if key.startswith("options"):
|
||||
self.option_count += 1
|
||||
create_options_field(key, initial=value)
|
||||
fields_order = list(self.fields.keys())
|
||||
fields_order.remove("recruitment")
|
||||
fields_order.insert(2, "recruitment")
|
||||
self.fields = {field: self.fields[field] for field in fields_order}
|
||||
|
||||
|
||||
class SurveyForm(forms.Form):
|
||||
|
||||
@@ -51,152 +51,8 @@
|
||||
</div>
|
||||
<input type="file" hidden name="profile" id="hidden_profile" />
|
||||
{{form.profile.errors}}
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-12">
|
||||
<label class="oh-label" for="firstname"
|
||||
>{% trans "Candidate Name" %} *</label
|
||||
>
|
||||
{{form.name}} {{form.name.errors}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<label class="oh-label" for="email">{% trans "Email" %} *</label>
|
||||
{{form.email}} {{form.email.errors}}
|
||||
</div>
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<label class="oh-label" for="phone">{% trans "Phone" %}</label>
|
||||
{{form.mobile}} {{form.mobile.errors}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<label class="oh-label" for="recruitment"
|
||||
>{% trans "Recruitment" %} *</label
|
||||
>
|
||||
<div id="select2-container">{{form.recruitment_id}}</div>
|
||||
{{form.recruitment_id.errors}}
|
||||
</div>
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<label class="oh-label" for="recruitment"
|
||||
>{% trans "Job Position" %}</label
|
||||
>
|
||||
<div id="select2-container">{{form.job_position_id}}</div>
|
||||
{{form.job_position_id.errors}}
|
||||
</div>
|
||||
{% comment %}
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<label class="oh-label" for="stage">{% trans "Stage" %}</label>
|
||||
{{form.stage_id}} {{form.stage_id.errors}}
|
||||
</div>
|
||||
{% endcomment %}
|
||||
</div>
|
||||
<div class="row" data-select2-id="select2-data-46-nz80">
|
||||
<div
|
||||
class="col-12 col-sm-12 col-md-12 col-lg-6"
|
||||
style="position: relative"
|
||||
>
|
||||
<label class="oh-label" for="dob"
|
||||
>{% trans "Date of Birth" %}</label
|
||||
>
|
||||
{{form.dob}} {{form.dob.errors}}
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="col-12 col-sm-12 col-md-12 col-lg-6"
|
||||
data-select2-id="select2-data-45-37n6"
|
||||
>
|
||||
<label class="oh-label" for="gender">{% trans "Gender" %} *</label>
|
||||
{{form.gender}} {{form.gender.errors}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<label class="oh-label" for="address">{% trans "Address" %}</label>
|
||||
{{form.address}} {{form.address.errors}}
|
||||
</div>
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<label class="oh-label" for="address">{% trans "Source" %}</label>
|
||||
{{form.source}} {{form.source.errors}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<label class="oh-label" for="country">{% trans "Country" %}</label>
|
||||
<select
|
||||
name="country"
|
||||
id="id_country"
|
||||
class="oh-select oh-select-2"
|
||||
>
|
||||
<option value="{{form.instance.country}}" selected>
|
||||
{{form.instance.country}}
|
||||
</option>
|
||||
</select>
|
||||
{{form.country.errors}}
|
||||
<span class="dropdown-wrapper" aria-hidden="true"></span>
|
||||
</div>
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<label class="oh-label d-block" for="state"
|
||||
>{% trans "State" %}</label
|
||||
>
|
||||
{{form.state.errors}}
|
||||
<select name="state" id="id_state" class="oh-select oh-select-2">
|
||||
<option value="{{form.instance.state}}" selected>
|
||||
{{form.instance.state}}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<label class="oh-label d-block" for="state"
|
||||
>{% trans "Zip Code" %}</label
|
||||
>
|
||||
{{form.zip}} {{form.zip.errors}}
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<label class="oh-label d-block" for="state"
|
||||
>{% trans "Resume" %} *</label
|
||||
>
|
||||
{{form.resume}} {{form.resume.errors}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<label class="oh-label d-block" for="state"
|
||||
>{% trans "Referral" %}</label
|
||||
>
|
||||
{{form.referral}} {{form.referral.errors}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<label class="oh-label d-block" for="experience"
|
||||
>{% trans "Canceled" %}?</label
|
||||
>
|
||||
<div class="oh-switch">
|
||||
{{form.canceled}} {{form.canceled.errors}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<label class="oh-label me-2" for="isActive"
|
||||
>{% trans "Is Active" %}?</label
|
||||
>
|
||||
<div class="oh-switch">
|
||||
{{form.is_active}} {{form.is_active.errors}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
|
||||
<input type="file" name="profile" hidden id="hidden_profile" />
|
||||
</div>
|
||||
<hr class="mt-5 mb-3 d-flex flex-row-reverse" />
|
||||
</div>
|
||||
{{ form.as_p }}
|
||||
|
||||
<div class="w-100 d-flex align-items-center justify-content-end">
|
||||
<button
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
{% load i18n %} {% load basefilters %}{% load widget_tweaks %}
|
||||
{{ form.non_field_errors }}
|
||||
|
||||
<div class="row">
|
||||
{% for field in form %}
|
||||
{% if field.label != "Profile" and field.label != 'Country' and field.label != 'State' and field.label != 'Badge id' %}
|
||||
<div class="col-lg-6">
|
||||
<div class="oh-input__group">
|
||||
<label
|
||||
class="oh-label {% if field.field.required %}required-star{% endif %}"
|
||||
for="id_{{ field.name }}"
|
||||
title="{{ field.help_text|safe }}"
|
||||
>
|
||||
{{ field.label }}
|
||||
</label>
|
||||
|
||||
{% if field.field.widget.input_type == 'checkbox' %}
|
||||
<div class="oh-switch" style="width: 30px;">{{ field|add_class:'oh-switch__checkbox' }}</div>
|
||||
{% else %}
|
||||
{{ field|add_class:'form-control' }}
|
||||
{% endif %}
|
||||
|
||||
{{ field.errors }}
|
||||
</div>
|
||||
</div>
|
||||
{% elif field.label == 'Country' %}
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<label class="oh-label" for="country">{% trans "Country" %}</label>
|
||||
<select name="country" class="w-100 oh-select-2" id="id_country">
|
||||
<option value="{{form.instance.country}}" selected>{{form.instance.country}}</option>
|
||||
</select>
|
||||
{{form.country.errors}}
|
||||
<span class="dropdown-wrapper" aria-hidden="true"></span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<label class="oh-label d-block" for="state">{% trans "State" %}</label>
|
||||
<select name="state" class="w-100 oh-select-2" id="id_state">
|
||||
<option value="{{form.instance.state}}" selected>{{form.instance.state}}</option>
|
||||
|
||||
</select>
|
||||
{{form.state.errors}}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user