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
89 lines
2.6 KiB
Python
89 lines
2.6 KiB
Python
"""
|
|
horilla/config.py
|
|
|
|
Horilla app configurations
|
|
"""
|
|
|
|
import importlib
|
|
import logging
|
|
|
|
from django.apps import apps
|
|
from django.conf import settings
|
|
from django.contrib.auth.context_processors import PermWrapper
|
|
|
|
from horilla.horilla_apps import SIDEBARS
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def get_apps_in_base_dir():
|
|
return SIDEBARS
|
|
|
|
|
|
def import_method(accessibility):
|
|
module_path, method_name = accessibility.rsplit(".", 1)
|
|
module = __import__(module_path, fromlist=[method_name])
|
|
accessibility_method = getattr(module, method_name)
|
|
return accessibility_method
|
|
|
|
|
|
ALL_MENUS = {}
|
|
|
|
|
|
def sidebar(request):
|
|
|
|
base_dir_apps = get_apps_in_base_dir()
|
|
|
|
if not request.user.is_anonymous:
|
|
request.MENUS = []
|
|
MENUS = request.MENUS
|
|
|
|
for app in base_dir_apps:
|
|
if apps.is_installed(app):
|
|
try:
|
|
sidebar = importlib.import_module(app + ".sidebar")
|
|
|
|
except Exception as e:
|
|
logger.error(e)
|
|
continue
|
|
|
|
if sidebar:
|
|
accessibility = None
|
|
if getattr(sidebar, "ACCESSIBILITY", None):
|
|
accessibility = import_method(sidebar.ACCESSIBILITY)
|
|
|
|
if not accessibility or accessibility(
|
|
request,
|
|
sidebar.MENU,
|
|
PermWrapper(request.user),
|
|
):
|
|
MENU = {}
|
|
MENU["menu"] = sidebar.MENU
|
|
MENU["app"] = app
|
|
MENU["img_src"] = sidebar.IMG_SRC
|
|
MENU["submenu"] = []
|
|
MENUS.append(MENU)
|
|
for submenu in sidebar.SUBMENUS:
|
|
|
|
accessibility = None
|
|
|
|
if submenu.get("accessibility"):
|
|
accessibility = import_method(submenu["accessibility"])
|
|
redirect: str = submenu["redirect"]
|
|
redirect = redirect.split("?")
|
|
submenu["redirect"] = redirect[0]
|
|
|
|
if not accessibility or accessibility(
|
|
request,
|
|
submenu,
|
|
PermWrapper(request.user),
|
|
):
|
|
MENU["submenu"].append(submenu)
|
|
ALL_MENUS[request.session.session_key] = MENUS
|
|
|
|
|
|
def get_MENUS(request):
|
|
ALL_MENUS[request.session.session_key] = []
|
|
sidebar(request)
|
|
return {"sidebar": ALL_MENUS.get(request.session.session_key)}
|