Files
ihrm/horilla_crumbs/context_processors.py

322 lines
9.2 KiB
Python
Raw Normal View History

import uuid
2023-11-21 16:41:10 +05:30
from urllib.parse import urlparse
[IMP] Remove inter module dependency (#274) This commit introduces significant changes to the architecture of the Horilla HRMS system by decoupling interdependent modules. The following modifications were made: 1. **Module Independence**: Each module has been refactored to eliminate reliance on other modules, promoting a more modular and maintainable codebase. 2. **Refactored Imports and Dependencies**: Adjusted import statements and dependency injections to support independent module operation. 3. **Compatibility and Functionality**: Ensured that all modules are compatible with existing systems and maintain their intended functionality both independently and when integrated with other modules. These changes enhance the modularity, maintainability, and scalability of the Horilla HRMS, allowing developers to work on individual modules without affecting the entire system. Future development and deployment will be more efficient and less prone to issues arising from tightly coupled code. **NOTE** For existing Horilla users, if you face any issues during the migrations, please run the following command and try again the migrations. - `python3 manage.py makemigrations` - `python3 manage.py migrate base` - `python3 manage.py migrate` * [IMP] ASSET: Asset module dependency removal from other Horilla apps * [IMP] ATTENDANCE: Attendance module dependency removal from other Horilla apps * [IMP] BASE: Base module dependency removal from other Horilla apps * [IMP] EMPLOYEE: Employee module dependency removal from other Horilla apps * [IMP] HELPDESK: Helpdesk module dependency removal from other Horilla apps * [IMP] HORILLA AUDIT: Horilla Audit module dependency removal from other Horilla apps * [IMP] HORILLA CRUMBS: Horilla Crumbs module dependency removal from other Horilla apps * [IMP] HORILLA AUTOMATIONS: Horilla Automations module dependency removal from other Horilla apps * [IMP] HORILLA VIEWS: Horilla Views module dependency removal from other Horilla apps * [IMP] LEAVE: Leave module dependency removal from other Horilla apps * [IMP] OFFBOARDING: Offboarding module dependency removal from other Horilla apps * [IMP] ONBOARDING: Onboarding module dependency removal from other Horilla apps * [IMP] PMS: PMS module dependency removal from other Horilla apps * [IMP] PAYROLL: Payroll module dependency removal from other Horilla apps * [IMP] RECRUITMENT: Recruitment module dependency removal from other Horilla apps * [IMP] HORILLA: Dependency removal updates * [IMP] TEMPLATES: Dependency removal updates * [IMP] STATIC: Dependency removal updates * [IMP] HORILLA DOCUMENTS: Horilla Documents module dependency removal from other Horilla apps * [ADD] HORILLA: methods.py * [UPDT] HORILLA: Settings.py * [FIX] EMPLOYEE: About tab issue * Update horilla_settings.py * Remove dummy db init password
2024-08-05 14:22:44 +05:30
from django.apps import apps
2023-11-21 16:41:10 +05:30
from django.shortcuts import redirect
from django.urls import Resolver404, path, resolve, reverse
2023-11-21 16:41:10 +05:30
from employee.models import Employee
from horilla.urls import urlpatterns
2023-11-21 16:41:10 +05:30
def is_valid_uuid(uuid_string):
try:
uuid.UUID(uuid_string, version=4)
return True
except ValueError:
return False
2023-11-21 16:41:10 +05:30
def _split_path(self, path=None):
"""Returns a list of the path components between slashes"""
if not path:
path = self.path
if path.endswith("/"):
path = path[:-1]
if path.startswith("/"):
path = path[1:]
if path == "":
return list()
result = path.split("/")
return result
sidebar_urls = [
"dashboard",
"pipeline",
"recruitment-survey-question-template-view",
"candidate-view",
"recruitment-view",
"stage-view",
"view-onboarding-dashboard",
"onboarding-view",
"candidates-view",
"employee-profile",
"employee-view",
"shift-request-view",
"work-type-request-view",
"rotating-shift-assign",
"rotating-work-type-assign",
"view-payroll-dashboard",
"view-contract",
"view-allowance",
"view-deduction",
"view-payslip",
"filing-status-view",
"attendance-view",
"work-records",
2023-11-21 16:41:10 +05:30
"request-attendance-view",
"attendance-overtime-view",
"attendance-activity-view",
"late-come-early-out-view",
"view-my-attendance",
"leave-dashboard",
"leave-employee-dashboard",
"user-leave",
"user-request-view",
"leave-allocation-request-view",
"type-view",
"assign-view",
"request-view",
"holiday-view",
"company-leave-view",
"dashboard-view",
"objective-list-view",
"feedback-view",
"period-view",
"question-template-view",
"asset-category-view",
"asset-request-allocation-view",
"settings",
"attendance-settings",
"employee-permission-assign",
"user-group-assign",
"currency",
"department-view",
"job-position-view",
"job-role-view",
"work-type-view",
"rotating-work-type-view",
"employee-type-view",
"employee-shift-view",
"employee-shift-schedule-view",
"rotating-shift-view",
"attendance-settings-view",
"user-group-view",
"company-view",
"document-request-view",
"faq-category-view",
"ticket-view",
"tag-view",
"ticket-type-view",
"mail-server-conf",
"multiple-approval-condition",
"skill-zone-view",
"view-mail-templates",
"view-loan",
"view-reimbursement",
"department-manager-view",
"date-settings",
"offboarding-pipeline",
"pagination-settings-view",
"organisation-chart",
"disciplinary-actions",
"view-policies",
"resignation-requests-view",
"action-type",
"general-settings",
"view-biometric-devices",
"employee-tag-view",
"grace-settings-view",
"helpdesk-tag-view",
"restrict-view",
"asset-history",
"view-key-result",
"view-meetings",
"interview-view",
"view-compensatory-leave",
"compensatory-leave-settings-view",
"project-dashboard-view",
"project-view",
"view-time-sheet",
"templates",
"sidebar.html",
"objective-detailed-view",
"mail-automations",
"faq-view",
"auto-payslip-settings-view",
"bonus-point-setting",
"employee-past-leave-restriction",
"track-late-come-early-out",
"enable-biometric-attendance",
"allowed-ips",
"self-tracking-feature",
"candidate-reject-reasons",
"skills-view",
"employee-bonus-point",
"mail-automations",
2023-11-21 16:41:10 +05:30
]
remove_urls = [
"feedback-detailed-view",
"question-template-detailed-view",
"employee-view-new",
"objective-detailed-view",
"ticket-detail",
"faq-view",
"get-job-positions",
2023-11-21 16:41:10 +05:30
]
user_breadcrumbs = {}
def breadcrumbs(request):
base_url = request.build_absolute_uri("/")
# Initialize breadcrumbs in the session if not already present
if "breadcrumbs" not in request.session:
request.session["breadcrumbs"] = [
2023-11-21 16:41:10 +05:30
{"url": base_url, "name": "Horilla", "found": True}
]
try:
breadcrumbs = request.session["breadcrumbs"]
2023-11-21 16:41:10 +05:30
qs = request.META.get("QUERY_STRING", "")
pairs = qs.split("&")
filtered_pairs = [pair for pair in pairs if "=" in pair and pair.split("=")[1]]
filtered_query_string = "&".join(filtered_pairs)
emp_query_string = None
for item in breadcrumbs:
if item["name"] in ["employee-view", "candidate-view"]:
items = item["url"].split("?", 1)
if len(items) > 1:
emp_query_string = items[1]
break
2023-11-21 16:41:10 +05:30
parts = _split_path(request)
path = base_url
[IMP] Remove inter module dependency (#274) This commit introduces significant changes to the architecture of the Horilla HRMS system by decoupling interdependent modules. The following modifications were made: 1. **Module Independence**: Each module has been refactored to eliminate reliance on other modules, promoting a more modular and maintainable codebase. 2. **Refactored Imports and Dependencies**: Adjusted import statements and dependency injections to support independent module operation. 3. **Compatibility and Functionality**: Ensured that all modules are compatible with existing systems and maintain their intended functionality both independently and when integrated with other modules. These changes enhance the modularity, maintainability, and scalability of the Horilla HRMS, allowing developers to work on individual modules without affecting the entire system. Future development and deployment will be more efficient and less prone to issues arising from tightly coupled code. **NOTE** For existing Horilla users, if you face any issues during the migrations, please run the following command and try again the migrations. - `python3 manage.py makemigrations` - `python3 manage.py migrate base` - `python3 manage.py migrate` * [IMP] ASSET: Asset module dependency removal from other Horilla apps * [IMP] ATTENDANCE: Attendance module dependency removal from other Horilla apps * [IMP] BASE: Base module dependency removal from other Horilla apps * [IMP] EMPLOYEE: Employee module dependency removal from other Horilla apps * [IMP] HELPDESK: Helpdesk module dependency removal from other Horilla apps * [IMP] HORILLA AUDIT: Horilla Audit module dependency removal from other Horilla apps * [IMP] HORILLA CRUMBS: Horilla Crumbs module dependency removal from other Horilla apps * [IMP] HORILLA AUTOMATIONS: Horilla Automations module dependency removal from other Horilla apps * [IMP] HORILLA VIEWS: Horilla Views module dependency removal from other Horilla apps * [IMP] LEAVE: Leave module dependency removal from other Horilla apps * [IMP] OFFBOARDING: Offboarding module dependency removal from other Horilla apps * [IMP] ONBOARDING: Onboarding module dependency removal from other Horilla apps * [IMP] PMS: PMS module dependency removal from other Horilla apps * [IMP] PAYROLL: Payroll module dependency removal from other Horilla apps * [IMP] RECRUITMENT: Recruitment module dependency removal from other Horilla apps * [IMP] HORILLA: Dependency removal updates * [IMP] TEMPLATES: Dependency removal updates * [IMP] STATIC: Dependency removal updates * [IMP] HORILLA DOCUMENTS: Horilla Documents module dependency removal from other Horilla apps * [ADD] HORILLA: methods.py * [UPDT] HORILLA: Settings.py * [FIX] EMPLOYEE: About tab issue * Update horilla_settings.py * Remove dummy db init password
2024-08-05 14:22:44 +05:30
if apps.is_installed("recruitment"):
from recruitment.models import Candidate
candidates = Candidate.objects.filter(is_active=True)
else:
candidates = None
employees = Employee.objects.all()
if len(parts) > 1:
if "recruitment" in parts:
if "search-candidate" in parts:
pass
elif "candidate-view" in parts:
pass
elif "get-mail-log-rec" in parts:
pass
else:
# Store the candidates in the session
request.session["filtered_candidates"] = [
candidate.id for candidate in candidates
]
if "employee-filter-view" in parts:
pass
elif "employee-view" in parts:
pass
elif "view-penalties" in parts:
pass
elif parts[0] == "employee" and parts[-1].isdigit():
pass
else:
# Store the employees in the session
request.session["filtered_employees"] = [
employee.id for employee in employees
]
2023-11-21 16:41:10 +05:30
if len(parts) == 0:
request.session["breadcrumbs"].clear()
breadcrumbs.append({"url": base_url, "name": "Horilla", "found": True})
2023-11-21 16:41:10 +05:30
if len(parts) > 1:
last_path = parts[-1]
if (
last_path in sidebar_urls
or parts[-2] == "employee-view"
or parts[-2] == "candidate-view"
or parts[-2] == "view-payslip"
):
2023-11-21 16:41:10 +05:30
first_path = breadcrumbs[0]
request.session["breadcrumbs"].clear()
request.session["breadcrumbs"].append(first_path)
2023-11-21 16:41:10 +05:30
for i, item in enumerate(parts):
path = path + item + "/"
parsed_url = urlparse(path)
check_path = parsed_url.path
try:
resolver_match = resolve(check_path)
found = True
except Resolver404:
2023-11-21 16:41:10 +05:30
found = False
new_dict = {"url": path, "name": item, "found": found}
if item.isdigit() or is_valid_uuid(item):
2023-11-21 16:41:10 +05:30
# Handle the case when item is a digit (e.g., an ID)
current_url = resolve(request.path_info)
url_kwargs = current_url.kwargs
model_value = url_kwargs.get("model")
if model_value:
try:
obj = model_value.objects.get(id=item) # completed
new_dict["name"] = str(obj)
2023-11-21 16:41:10 +05:30
except:
pass
key = "HTTP_HX_REQUEST"
names = [d["name"] for d in breadcrumbs]
2023-11-21 16:41:10 +05:30
if (
new_dict not in breadcrumbs
and new_dict["name"] not in remove_urls + names
2023-11-21 16:41:10 +05:30
and key not in request.META.keys()
and not new_dict["name"].isdigit()
):
if new_dict["name"] in ["employee-view", "candidate-view"]:
new_dict["url"] = f'{new_dict["url"]}?{emp_query_string}'
breadcrumbs.append(new_dict)
2023-11-21 16:41:10 +05:30
try:
prev_url = breadcrumbs[-1]
prev_url["url"] = prev_url["url"].split("?")[0]
if filtered_query_string:
prev_url["url"] = f'{prev_url["url"]}?{filtered_query_string}'
else:
prev_url["url"] = f'{prev_url["url"]}'
except:
pass
request.session["breadcrumbs"] = breadcrumbs
2023-11-21 16:41:10 +05:30
except Exception as e:
request.session["breadcrumbs"] = [
2023-11-21 16:41:10 +05:30
{"url": base_url, "name": "Horilla", "found": True}
]
return {"breadcrumbs": request.session["breadcrumbs"]}
2023-11-21 16:41:10 +05:30
urlpatterns.append(
path("recruitment/", lambda request: redirect("recruitment-dashboard"))
)
urlpatterns.append(
path("onboarding/", lambda request: redirect("view-onboarding-dashboard"))
)
urlpatterns.append(path("employee/", lambda request: redirect("employee-view")))
urlpatterns.append(
path("attendance/", lambda request: redirect("attendance-dashboard"))
)
urlpatterns.append(
path(
"leave/",
lambda request: redirect(
reverse("leave-employee-dashboard") + "?dashboard=true"
),
)
)
2023-11-21 16:41:10 +05:30
urlpatterns.append(path("payroll/", lambda request: redirect("view-payroll-dashboard")))
urlpatterns.append(path("pms/", lambda request: redirect("dashboard-view")))