2023-12-01 15:36:51 +05:30
|
|
|
"""
|
|
|
|
|
context_processor.py
|
|
|
|
|
|
|
|
|
|
This module is used to register context processor`
|
|
|
|
|
"""
|
2024-03-10 19:37:46 +05:30
|
|
|
|
2024-08-05 14:22:44 +05:30
|
|
|
from django.apps import apps
|
2023-12-01 15:36:51 +05:30
|
|
|
from django.http import HttpResponse
|
2024-05-07 12:23:36 +05:30
|
|
|
from django.urls import path
|
|
|
|
|
|
2024-07-22 10:55:53 +05:30
|
|
|
from base.models import Company, TrackLateComeEarlyOut
|
2023-12-01 15:36:51 +05:30
|
|
|
from base.urls import urlpatterns
|
2024-02-01 13:09:43 +05:30
|
|
|
from employee.models import EmployeeGeneralSetting
|
2024-05-23 14:29:29 +05:30
|
|
|
from horilla import horilla_apps
|
2024-07-10 16:11:23 +05:30
|
|
|
from horilla.decorators import hx_request_required, login_required, permission_required
|
2024-08-05 14:22:44 +05:30
|
|
|
from horilla.methods import get_horilla_model_class
|
2023-12-01 15:36:51 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
class AllCompany:
|
|
|
|
|
"""
|
|
|
|
|
Dummy class
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
class Urls:
|
|
|
|
|
url = "https://ui-avatars.com/api/?name=All+Company&background=random"
|
|
|
|
|
|
|
|
|
|
company = "All Company"
|
|
|
|
|
icon = Urls()
|
|
|
|
|
text = "All companies"
|
|
|
|
|
id = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_companies(request):
|
|
|
|
|
"""
|
|
|
|
|
This method will return the history additional field form
|
|
|
|
|
"""
|
|
|
|
|
companies = list(
|
|
|
|
|
[company.id, company.company, company.icon.url, False]
|
|
|
|
|
for company in Company.objects.all()
|
|
|
|
|
)
|
|
|
|
|
companies = [
|
|
|
|
|
[
|
|
|
|
|
"all",
|
|
|
|
|
"All Company",
|
|
|
|
|
"https://ui-avatars.com/api/?name=All+Company&background=random",
|
|
|
|
|
False,
|
|
|
|
|
],
|
|
|
|
|
] + companies
|
|
|
|
|
selected_company = request.session.get("selected_company")
|
|
|
|
|
company_selected = False
|
|
|
|
|
if selected_company and selected_company == "all":
|
|
|
|
|
companies[0][3] = True
|
|
|
|
|
company_selected = True
|
|
|
|
|
else:
|
|
|
|
|
for company in companies:
|
|
|
|
|
if str(company[0]) == selected_company:
|
|
|
|
|
company[3] = True
|
|
|
|
|
company_selected = True
|
|
|
|
|
return {"all_companies": companies, "company_selected": company_selected}
|
|
|
|
|
|
|
|
|
|
|
2024-07-10 16:11:23 +05:30
|
|
|
@login_required
|
|
|
|
|
@hx_request_required
|
|
|
|
|
@permission_required("base.change_company")
|
2023-12-01 15:36:51 +05:30
|
|
|
def update_selected_company(request):
|
|
|
|
|
"""
|
|
|
|
|
This method is used to update the selected company on the session
|
|
|
|
|
"""
|
|
|
|
|
company_id = request.GET.get("company_id")
|
|
|
|
|
request.session["selected_company"] = company_id
|
|
|
|
|
company = (
|
|
|
|
|
AllCompany()
|
|
|
|
|
if company_id == "all"
|
|
|
|
|
else (
|
|
|
|
|
Company.objects.filter(id=company_id).first()
|
|
|
|
|
if Company.objects.filter(id=company_id).first()
|
|
|
|
|
else AllCompany()
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
text = "Other Company"
|
|
|
|
|
if company_id == request.user.employee_get.employee_work_info.company_id:
|
|
|
|
|
text = "My Company"
|
|
|
|
|
if company_id == "all":
|
|
|
|
|
text = "All companies"
|
|
|
|
|
company = {
|
|
|
|
|
"company": company.company,
|
|
|
|
|
"icon": company.icon.url,
|
|
|
|
|
"text": text,
|
|
|
|
|
"id": company.id,
|
|
|
|
|
}
|
|
|
|
|
request.session["selected_company_instance"] = company
|
|
|
|
|
return HttpResponse("<script>window.location.reload();</script>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
urlpatterns.append(
|
|
|
|
|
path(
|
|
|
|
|
"update-selected-company",
|
|
|
|
|
update_selected_company,
|
|
|
|
|
name="update-selected-company",
|
|
|
|
|
)
|
|
|
|
|
)
|
2024-01-25 16:36:49 +05:30
|
|
|
|
|
|
|
|
|
2024-05-23 14:29:29 +05:30
|
|
|
def white_labelling_company(request):
|
|
|
|
|
white_labelling = getattr(horilla_apps, "WHITE_LABELLING", False)
|
|
|
|
|
if white_labelling:
|
|
|
|
|
hq = Company.objects.filter(hq=True).last()
|
|
|
|
|
try:
|
|
|
|
|
company = (
|
|
|
|
|
request.user.employee_get.get_company()
|
|
|
|
|
if request.user.employee_get.get_company()
|
|
|
|
|
else hq
|
|
|
|
|
)
|
|
|
|
|
except:
|
|
|
|
|
company = hq
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"white_label_company_name": company.company if company else "Horilla",
|
|
|
|
|
"white_label_company": company,
|
|
|
|
|
}
|
|
|
|
|
else:
|
|
|
|
|
return {
|
|
|
|
|
"white_label_company_name": "Horilla",
|
|
|
|
|
"white_label_company": None,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-01-25 16:36:49 +05:30
|
|
|
def resignation_request_enabled(request):
|
|
|
|
|
"""
|
|
|
|
|
Check weather resignation_request enabled of not in offboarding
|
|
|
|
|
"""
|
2024-05-21 13:04:25 +05:30
|
|
|
enabled_resignation_request = False
|
2024-08-05 14:22:44 +05:30
|
|
|
first = None
|
|
|
|
|
if apps.is_installed("offboarding"):
|
|
|
|
|
OffboardingGeneralSetting = get_horilla_model_class(
|
|
|
|
|
app_label="offboarding", model="offboardinggeneralsetting"
|
|
|
|
|
)
|
|
|
|
|
first = OffboardingGeneralSetting.objects.first()
|
2024-01-25 16:36:49 +05:30
|
|
|
if first:
|
|
|
|
|
enabled_resignation_request = first.resignation_request
|
|
|
|
|
return {"enabled_resignation_request": enabled_resignation_request}
|
2024-01-29 15:08:36 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def timerunner_enabled(request):
|
|
|
|
|
"""
|
|
|
|
|
Check weather resignation_request enabled of not in offboarding
|
|
|
|
|
"""
|
2024-08-05 14:22:44 +05:30
|
|
|
first = None
|
2024-01-29 15:08:36 +05:30
|
|
|
enabled_timerunner = True
|
2024-08-05 14:22:44 +05:30
|
|
|
if apps.is_installed("attendance"):
|
|
|
|
|
AttendanceGeneralSetting = get_horilla_model_class(
|
|
|
|
|
app_label="attendance", model="attendancegeneralsetting"
|
|
|
|
|
)
|
|
|
|
|
first = AttendanceGeneralSetting.objects.first()
|
2024-01-29 15:08:36 +05:30
|
|
|
if first:
|
|
|
|
|
enabled_timerunner = first.time_runner
|
|
|
|
|
return {"enabled_timerunner": enabled_timerunner}
|
2024-01-30 19:10:54 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def intial_notice_period(request):
|
|
|
|
|
"""
|
|
|
|
|
Check weather resignation_request enabled of not in offboarding
|
|
|
|
|
"""
|
2024-03-21 14:22:49 +05:30
|
|
|
initial = 30
|
2024-08-05 14:22:44 +05:30
|
|
|
first = None
|
|
|
|
|
if apps.is_installed("payroll"):
|
|
|
|
|
PayrollGeneralSetting = get_horilla_model_class(
|
|
|
|
|
app_label="payroll", model="payrollgeneralsetting"
|
|
|
|
|
)
|
|
|
|
|
first = PayrollGeneralSetting.objects.first()
|
2024-01-30 19:10:54 +05:30
|
|
|
if first:
|
|
|
|
|
initial = first.notice_period
|
|
|
|
|
return {"get_initial_notice_period": initial}
|
2024-01-31 11:42:29 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_candidate_self_tracking(request):
|
|
|
|
|
"""
|
|
|
|
|
This method is used to get the candidate self tracking is enabled or not
|
|
|
|
|
"""
|
2024-08-05 14:22:44 +05:30
|
|
|
|
2024-01-31 11:42:29 +05:30
|
|
|
candidate_self_tracking = False
|
2024-08-05 14:22:44 +05:30
|
|
|
if apps.is_installed("recruitment"):
|
|
|
|
|
RecruitmentGeneralSetting = get_horilla_model_class(
|
|
|
|
|
app_label="recruitment", model="recruitmentgeneralsetting"
|
|
|
|
|
)
|
|
|
|
|
first = RecruitmentGeneralSetting.objects.first()
|
|
|
|
|
else:
|
|
|
|
|
first = None
|
2024-01-31 11:42:29 +05:30
|
|
|
if first:
|
|
|
|
|
candidate_self_tracking = first.candidate_self_tracking
|
|
|
|
|
return {"check_candidate_self_tracking": candidate_self_tracking}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_candidate_self_tracking_rating(request):
|
|
|
|
|
"""
|
|
|
|
|
This method is used to check enabled/disabled of rating option
|
|
|
|
|
"""
|
|
|
|
|
rating_option = False
|
2024-08-05 14:22:44 +05:30
|
|
|
if apps.is_installed("recruitment"):
|
|
|
|
|
RecruitmentGeneralSetting = get_horilla_model_class(
|
|
|
|
|
app_label="recruitment", model="recruitmentgeneralsetting"
|
|
|
|
|
)
|
|
|
|
|
first = RecruitmentGeneralSetting.objects.first()
|
|
|
|
|
else:
|
|
|
|
|
first = None
|
2024-01-31 11:42:29 +05:30
|
|
|
if first:
|
|
|
|
|
rating_option = first.show_overall_rating
|
|
|
|
|
return {"check_candidate_self_tracking_rating": rating_option}
|
2024-02-01 13:09:43 +05:30
|
|
|
|
|
|
|
|
|
2024-04-15 16:23:21 +05:30
|
|
|
def get_initial_prefix(request):
|
2024-02-01 13:09:43 +05:30
|
|
|
"""
|
2024-04-15 16:23:21 +05:30
|
|
|
This method is used to get the initial prefix
|
2024-02-01 13:09:43 +05:30
|
|
|
"""
|
|
|
|
|
settings = EmployeeGeneralSetting.objects.first()
|
|
|
|
|
instance_id = None
|
|
|
|
|
prefix = "PEP"
|
|
|
|
|
if settings:
|
|
|
|
|
instance_id = settings.id
|
|
|
|
|
prefix = settings.badge_id_prefix
|
2024-04-15 16:23:21 +05:30
|
|
|
return {"get_initial_prefix": prefix, "prefix_instance_id": instance_id}
|
2024-04-17 21:56:01 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def biometric_app_exists(request):
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
|
|
biometric_app_exists = "biometric" in settings.INSTALLED_APPS
|
|
|
|
|
return {"biometric_app_exists": biometric_app_exists}
|
2024-07-22 10:55:53 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def enable_late_come_early_out_tracking(request):
|
|
|
|
|
tracking = TrackLateComeEarlyOut.objects.first()
|
|
|
|
|
enable = tracking.is_enable if tracking else True
|
|
|
|
|
return {"tracking": enable, "late_come_early_out_tracking": enable}
|