2023-06-06 12:27:41 +05:30
|
|
|
"""
|
|
|
|
|
filters.py
|
|
|
|
|
|
|
|
|
|
This page is used to register filter for recruitment models
|
|
|
|
|
|
|
|
|
|
"""
|
2023-05-10 15:06:57 +05:30
|
|
|
import django_filters
|
|
|
|
|
from django import forms
|
2023-08-14 14:49:11 +05:30
|
|
|
from recruitment.models import Candidate, Recruitment, Stage, RecruitmentSurvey
|
2023-05-10 15:06:57 +05:30
|
|
|
|
2023-06-06 12:27:41 +05:30
|
|
|
# from django.forms.widgets import Boo
|
|
|
|
|
|
2023-05-10 15:06:57 +05:30
|
|
|
|
|
|
|
|
class FilterSet(django_filters.FilterSet):
|
2023-06-06 12:27:41 +05:30
|
|
|
"""
|
|
|
|
|
Custom FilterSet class that applies specific CSS classes to filter
|
|
|
|
|
widgets.
|
|
|
|
|
|
|
|
|
|
The class applies CSS classes to different types of filter widgets,
|
|
|
|
|
such as NumberInput, EmailInput, TextInput, Select, Textarea,
|
|
|
|
|
CheckboxInput, CheckboxSelectMultiple, and ModelChoiceField. The
|
|
|
|
|
CSS classes are applied to enhance the styling and behavior of the
|
|
|
|
|
filter widgets.
|
|
|
|
|
"""
|
|
|
|
|
|
2023-05-10 15:06:57 +05:30
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super().__init__(*args, **kwargs)
|
2023-06-06 12:27:41 +05:30
|
|
|
for _, filter_widget in self.filters.items():
|
2023-05-10 15:06:57 +05:30
|
|
|
widget = filter_widget.field.widget
|
2023-08-14 14:49:11 +05:30
|
|
|
if isinstance(
|
|
|
|
|
widget, (forms.NumberInput, forms.EmailInput, forms.TextInput)
|
|
|
|
|
):
|
2023-06-06 12:27:41 +05:30
|
|
|
widget.attrs.update({"class": "oh-input w-100"})
|
|
|
|
|
elif isinstance(widget, (forms.Select,)):
|
2023-08-14 14:49:11 +05:30
|
|
|
widget.attrs.update(
|
|
|
|
|
{"class": "oh-select oh-select-2 select2-hidden-accessible"}
|
|
|
|
|
)
|
2023-06-06 12:27:41 +05:30
|
|
|
elif isinstance(widget, (forms.Textarea)):
|
|
|
|
|
widget.attrs.update({"class": "oh-input w-100"})
|
2023-08-14 14:49:11 +05:30
|
|
|
elif isinstance(
|
|
|
|
|
widget, (forms.CheckboxInput, forms.CheckboxSelectMultiple)
|
|
|
|
|
):
|
2023-06-06 12:27:41 +05:30
|
|
|
widget.attrs.update({"class": "oh-switch__checkbox"})
|
|
|
|
|
elif isinstance(widget, (forms.ModelChoiceField)):
|
2023-08-14 14:49:11 +05:30
|
|
|
widget.attrs.update(
|
|
|
|
|
{"class": "oh-select oh-select-2 select2-hidden-accessible"}
|
|
|
|
|
)
|
2023-05-10 15:06:57 +05:30
|
|
|
|
|
|
|
|
|
2023-06-06 12:27:41 +05:30
|
|
|
class CandidateFilter(FilterSet):
|
|
|
|
|
"""
|
|
|
|
|
Filter set class for Candidate model
|
2023-05-10 15:06:57 +05:30
|
|
|
|
2023-06-06 12:27:41 +05:30
|
|
|
Args:
|
|
|
|
|
FilterSet (class): custom filter set class to apply styling
|
|
|
|
|
"""
|
2023-05-10 15:06:57 +05:30
|
|
|
|
2023-06-06 12:27:41 +05:30
|
|
|
name = django_filters.CharFilter(field_name="name", lookup_expr="icontains")
|
2023-05-10 15:06:57 +05:30
|
|
|
start_date = django_filters.DateFilter(
|
2023-06-06 12:27:41 +05:30
|
|
|
field_name="recruitment_id__start_date",
|
|
|
|
|
widget=forms.DateInput(attrs={"type": "date"}),
|
2023-05-10 15:06:57 +05:30
|
|
|
)
|
|
|
|
|
end_date = django_filters.DateFilter(
|
2023-06-06 12:27:41 +05:30
|
|
|
field_name="recruitment_id__end_date",
|
|
|
|
|
widget=forms.DateInput(attrs={"type": "date"}),
|
2023-05-10 15:06:57 +05:30
|
|
|
)
|
|
|
|
|
scheduled_from = django_filters.DateFilter(
|
2023-06-06 12:27:41 +05:30
|
|
|
field_name="schedule_date",
|
|
|
|
|
lookup_expr="gte",
|
|
|
|
|
widget=forms.DateInput(attrs={"type": "date"}),
|
2023-05-10 15:06:57 +05:30
|
|
|
)
|
|
|
|
|
scheduled_till = django_filters.DateFilter(
|
2023-06-06 12:27:41 +05:30
|
|
|
field_name="schedule_date",
|
|
|
|
|
lookup_expr="lte",
|
|
|
|
|
widget=forms.DateInput(attrs={"type": "date"}),
|
2023-05-10 15:06:57 +05:30
|
|
|
)
|
2023-06-06 12:27:41 +05:30
|
|
|
|
2023-05-10 15:06:57 +05:30
|
|
|
class Meta:
|
2023-06-06 12:27:41 +05:30
|
|
|
"""
|
|
|
|
|
Meta class to add the additional info
|
|
|
|
|
"""
|
2023-08-14 14:49:11 +05:30
|
|
|
|
2023-05-10 15:06:57 +05:30
|
|
|
model = Candidate
|
2023-06-06 12:27:41 +05:30
|
|
|
fields = [
|
|
|
|
|
"recruitment_id",
|
|
|
|
|
"stage_id",
|
|
|
|
|
"schedule_date",
|
|
|
|
|
"email",
|
|
|
|
|
"mobile",
|
|
|
|
|
"country",
|
|
|
|
|
"state",
|
|
|
|
|
"city",
|
|
|
|
|
"zip",
|
|
|
|
|
"gender",
|
|
|
|
|
"start_onboard",
|
|
|
|
|
"hired",
|
|
|
|
|
"canceled",
|
|
|
|
|
"is_active",
|
|
|
|
|
"recruitment_id__company_id",
|
2023-08-31 17:03:45 +05:30
|
|
|
"job_position_id",
|
2023-06-06 12:27:41 +05:30
|
|
|
"recruitment_id__closed",
|
|
|
|
|
"recruitment_id__is_active",
|
2023-08-31 17:03:45 +05:30
|
|
|
"job_position_id__department_id",
|
2023-06-06 12:27:41 +05:30
|
|
|
"recruitment_id__recruitment_managers",
|
|
|
|
|
"stage_id__stage_managers",
|
|
|
|
|
"stage_id__stage_type",
|
2023-05-10 15:06:57 +05:30
|
|
|
]
|
2023-06-06 12:27:41 +05:30
|
|
|
|
2023-05-10 15:06:57 +05:30
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super().__init__(*args, **kwargs)
|
2023-06-06 12:27:41 +05:30
|
|
|
self.form.fields["is_active"].initial = True
|
2023-05-10 15:06:57 +05:30
|
|
|
|
|
|
|
|
|
2023-06-06 12:27:41 +05:30
|
|
|
BOOLEAN_CHOICES = (
|
|
|
|
|
("", ""),
|
|
|
|
|
("false", "False"),
|
|
|
|
|
("true", "True"),
|
|
|
|
|
)
|
2023-05-10 15:06:57 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
class RecruitmentFilter(FilterSet):
|
2023-06-06 12:27:41 +05:30
|
|
|
"""
|
|
|
|
|
Filter set class for Recruitment model
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
FilterSet (class): custom filter set class to apply styling
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
description = django_filters.CharFilter(lookup_expr="icontains")
|
2023-05-10 15:06:57 +05:30
|
|
|
start_date = django_filters.DateFilter(
|
2023-06-06 12:27:41 +05:30
|
|
|
field_name="start_date", widget=forms.DateInput(attrs={"type": "date"})
|
2023-05-10 15:06:57 +05:30
|
|
|
)
|
|
|
|
|
end_date = django_filters.DateFilter(
|
2023-06-06 12:27:41 +05:30
|
|
|
field_name="end_date", widget=forms.DateInput(attrs={"type": "date"})
|
2023-05-10 15:06:57 +05:30
|
|
|
)
|
|
|
|
|
start_from = django_filters.DateFilter(
|
2023-06-06 12:27:41 +05:30
|
|
|
field_name="start_date",
|
|
|
|
|
lookup_expr="gte",
|
|
|
|
|
widget=forms.DateInput(attrs={"type": "date"}),
|
2023-05-10 15:06:57 +05:30
|
|
|
)
|
|
|
|
|
end_till = django_filters.DateFilter(
|
2023-06-06 12:27:41 +05:30
|
|
|
field_name="end_date",
|
|
|
|
|
lookup_expr="lte",
|
|
|
|
|
widget=forms.DateInput(attrs={"type": "date"}),
|
2023-05-10 15:06:57 +05:30
|
|
|
)
|
2023-06-06 12:27:41 +05:30
|
|
|
search = django_filters.CharFilter(method="filter_by_name")
|
|
|
|
|
|
2023-05-10 15:06:57 +05:30
|
|
|
class Meta:
|
2023-06-06 12:27:41 +05:30
|
|
|
"""
|
|
|
|
|
Meta class to add the additional info
|
|
|
|
|
"""
|
|
|
|
|
|
2023-05-10 15:06:57 +05:30
|
|
|
model = Recruitment
|
|
|
|
|
fields = [
|
2023-06-06 12:27:41 +05:30
|
|
|
"recruitment_managers",
|
|
|
|
|
"company_id",
|
|
|
|
|
"title",
|
|
|
|
|
"is_event_based",
|
|
|
|
|
"start_date",
|
|
|
|
|
"end_date",
|
|
|
|
|
"closed",
|
|
|
|
|
"is_active",
|
|
|
|
|
"job_position_id",
|
2023-05-10 15:06:57 +05:30
|
|
|
]
|
|
|
|
|
|
2023-06-06 12:27:41 +05:30
|
|
|
def filter_by_name(self, queryset, _, value):
|
2023-05-10 15:06:57 +05:30
|
|
|
"""
|
|
|
|
|
Filter queryset by first name or last name.
|
|
|
|
|
"""
|
|
|
|
|
# Split the search value into first name and last name
|
|
|
|
|
parts = value.split()
|
|
|
|
|
first_name = parts[0]
|
2023-06-06 12:27:41 +05:30
|
|
|
last_name = " ".join(parts[1:]) if len(parts) > 1 else ""
|
2023-05-10 15:06:57 +05:30
|
|
|
|
2023-06-06 12:27:41 +05:30
|
|
|
job_queryset = queryset.filter(
|
|
|
|
|
open_positions__job_position__icontains=value
|
|
|
|
|
) | queryset.filter(title__icontains=value)
|
2023-05-10 15:06:57 +05:30
|
|
|
if first_name and last_name:
|
2023-06-06 12:27:41 +05:30
|
|
|
queryset = queryset.filter(
|
|
|
|
|
recruitment_managers__employee_first_name__icontains=first_name,
|
|
|
|
|
recruitment_managers__employee_last_name__icontains=last_name,
|
|
|
|
|
)
|
2023-05-10 15:06:57 +05:30
|
|
|
elif first_name:
|
2023-06-06 12:27:41 +05:30
|
|
|
queryset = queryset.filter(
|
|
|
|
|
recruitment_managers__employee_first_name__icontains=first_name
|
|
|
|
|
)
|
2023-05-10 15:06:57 +05:30
|
|
|
elif last_name:
|
2023-06-06 12:27:41 +05:30
|
|
|
queryset = queryset.filter(
|
|
|
|
|
recruitment_managers__employee_last_name__icontains=last_name
|
|
|
|
|
)
|
2023-05-10 15:06:57 +05:30
|
|
|
|
2023-06-06 12:27:41 +05:30
|
|
|
queryset = queryset | job_queryset
|
|
|
|
|
return queryset.distinct()
|
2023-05-10 15:06:57 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
class StageFilter(FilterSet):
|
2023-06-06 12:27:41 +05:30
|
|
|
"""
|
|
|
|
|
Filter set class for Stage model
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
FilterSet (class): custom filter set class to apply styling
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
search = django_filters.CharFilter(method="filter_by_name")
|
2023-05-10 15:06:57 +05:30
|
|
|
|
|
|
|
|
class Meta:
|
2023-06-06 12:27:41 +05:30
|
|
|
"""
|
|
|
|
|
Meta class to add the additional info
|
|
|
|
|
"""
|
2023-08-14 14:49:11 +05:30
|
|
|
|
2023-05-10 15:06:57 +05:30
|
|
|
model = Stage
|
|
|
|
|
fields = [
|
2023-06-06 12:27:41 +05:30
|
|
|
"recruitment_id",
|
|
|
|
|
"recruitment_id__job_position_id",
|
|
|
|
|
"recruitment_id__job_position_id__department_id",
|
|
|
|
|
"recruitment_id__company_id",
|
|
|
|
|
"recruitment_id__recruitment_managers",
|
|
|
|
|
"stage_managers",
|
|
|
|
|
"stage_type",
|
2023-05-10 15:06:57 +05:30
|
|
|
]
|
2023-06-06 12:27:41 +05:30
|
|
|
|
|
|
|
|
def filter_by_name(self, queryset, _, value):
|
2023-05-10 15:06:57 +05:30
|
|
|
"""
|
|
|
|
|
Filter queryset by first name or last name.
|
|
|
|
|
"""
|
|
|
|
|
# Split the search value into first name and last name
|
|
|
|
|
parts = value.split()
|
|
|
|
|
first_name = parts[0]
|
2023-06-06 12:27:41 +05:30
|
|
|
last_name = " ".join(parts[1:]) if len(parts) > 1 else ""
|
2023-05-10 15:06:57 +05:30
|
|
|
|
|
|
|
|
# Filter the queryset by first name and last name
|
2023-06-06 12:27:41 +05:30
|
|
|
stage_queryset = queryset.filter(stage__icontains=value)
|
2023-05-10 15:06:57 +05:30
|
|
|
if first_name and last_name:
|
2023-06-06 12:27:41 +05:30
|
|
|
queryset = queryset.filter(
|
|
|
|
|
stage_managers__employee_first_name__icontains=first_name,
|
|
|
|
|
stage_managers__employee_last_name__icontains=last_name,
|
|
|
|
|
)
|
2023-05-10 15:06:57 +05:30
|
|
|
elif first_name:
|
2023-06-06 12:27:41 +05:30
|
|
|
queryset = queryset.filter(
|
|
|
|
|
stage_managers__employee_first_name__icontains=first_name
|
|
|
|
|
)
|
2023-05-10 15:06:57 +05:30
|
|
|
elif last_name:
|
2023-06-06 12:27:41 +05:30
|
|
|
queryset = queryset.filter(
|
|
|
|
|
stage_managers__employee_last_name__icontains=last_name
|
|
|
|
|
)
|
2023-05-10 15:06:57 +05:30
|
|
|
|
|
|
|
|
return queryset | stage_queryset
|
2023-08-14 14:49:11 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
class SurveyFilter(FilterSet):
|
|
|
|
|
"""
|
|
|
|
|
SurveyFIlter
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
options = django_filters.CharFilter(
|
|
|
|
|
lookup_expr="icontains",
|
|
|
|
|
label="Options",
|
|
|
|
|
field_name="options",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
question = django_filters.CharFilter(
|
|
|
|
|
lookup_expr="icontains",
|
|
|
|
|
label="Question",
|
|
|
|
|
field_name="question",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
"""
|
|
|
|
|
class Meta for additional options
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
model = RecruitmentSurvey
|
|
|
|
|
fields = "__all__"
|
|
|
|
|
exclude = [
|
|
|
|
|
"sequence",
|
|
|
|
|
]
|