[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
This commit is contained in:
@@ -7,6 +7,7 @@ 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
|
||||
|
||||
@@ -38,46 +39,46 @@ def sidebar(request):
|
||||
MENUS = request.MENUS
|
||||
|
||||
for app in base_dir_apps:
|
||||
if apps.is_installed(app):
|
||||
try:
|
||||
sidebar = importlib.import_module(app + ".sidebar")
|
||||
|
||||
try:
|
||||
sidebar = importlib.import_module(app + ".sidebar")
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
continue
|
||||
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
continue
|
||||
if sidebar:
|
||||
accessibility = None
|
||||
if getattr(sidebar, "ACCESSIBILITY", None):
|
||||
accessibility = import_method(sidebar.ACCESSIBILITY)
|
||||
|
||||
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:
|
||||
|
||||
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
|
||||
|
||||
accessibility = None
|
||||
if submenu.get("accessibility"):
|
||||
accessibility = import_method(submenu["accessibility"])
|
||||
redirect: str = submenu["redirect"]
|
||||
redirect = redirect.split("?")
|
||||
submenu["redirect"] = redirect[0]
|
||||
|
||||
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)
|
||||
if not accessibility or accessibility(
|
||||
request,
|
||||
submenu,
|
||||
PermWrapper(request.user),
|
||||
):
|
||||
MENU["submenu"].append(submenu)
|
||||
ALL_MENUS[request.session.session_key] = MENUS
|
||||
|
||||
|
||||
|
||||
@@ -193,7 +193,6 @@ def is_recruitment_manager(function, perm):
|
||||
|
||||
user = request.user
|
||||
perm = "recruitment.view_recruitmentsurvey"
|
||||
employee = user.employee_get
|
||||
is_manager = False
|
||||
recs = Recruitment.objects.all()
|
||||
for i in recs:
|
||||
|
||||
@@ -47,39 +47,37 @@ def filter_by_name(queryset, name, value):
|
||||
class FilterSet(django_filters.FilterSet):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
# exlude below loop if now need of form by just adding additional attr(exclude_form_setup) to the request
|
||||
if not getattr(kwargs.get("request"), "exclude_form_setup", False):
|
||||
reload_queryset(self.form.fields)
|
||||
for field_name, field in self.form.fields.items():
|
||||
filter_widget = self.filters[field_name]
|
||||
widget = filter_widget.field.widget
|
||||
if isinstance(
|
||||
widget, (forms.NumberInput, forms.EmailInput, forms.TextInput)
|
||||
):
|
||||
field.widget.attrs.update({"class": "oh-input w-100"})
|
||||
elif isinstance(widget, (forms.Select,)):
|
||||
field.widget.attrs.update(
|
||||
{
|
||||
"class": "oh-select oh-select-2 select2-hidden-accessible",
|
||||
"id": uuid.uuid4(),
|
||||
}
|
||||
)
|
||||
elif isinstance(widget, (forms.Textarea)):
|
||||
field.widget.attrs.update({"class": "oh-input w-100"})
|
||||
elif isinstance(
|
||||
widget,
|
||||
(
|
||||
forms.CheckboxInput,
|
||||
forms.CheckboxSelectMultiple,
|
||||
),
|
||||
):
|
||||
field.widget.attrs.update({"class": "oh-switch__checkbox"})
|
||||
elif isinstance(widget, (forms.ModelChoiceField)):
|
||||
field.widget.attrs.update(
|
||||
{
|
||||
"class": "oh-select oh-select-2 select2-hidden-accessible",
|
||||
}
|
||||
)
|
||||
reload_queryset(self.form.fields)
|
||||
for field_name, field in self.form.fields.items():
|
||||
filter_widget = self.filters[field_name]
|
||||
widget = filter_widget.field.widget
|
||||
if isinstance(
|
||||
widget, (forms.NumberInput, forms.EmailInput, forms.TextInput)
|
||||
):
|
||||
field.widget.attrs.update({"class": "oh-input w-100"})
|
||||
elif isinstance(widget, (forms.Select,)):
|
||||
field.widget.attrs.update(
|
||||
{
|
||||
"class": "oh-select oh-select-2 select2-hidden-accessible",
|
||||
"id": uuid.uuid4(),
|
||||
}
|
||||
)
|
||||
elif isinstance(widget, (forms.Textarea)):
|
||||
field.widget.attrs.update({"class": "oh-input w-100"})
|
||||
elif isinstance(
|
||||
widget,
|
||||
(
|
||||
forms.CheckboxInput,
|
||||
forms.CheckboxSelectMultiple,
|
||||
),
|
||||
):
|
||||
field.widget.attrs.update({"class": "oh-switch__checkbox"})
|
||||
elif isinstance(widget, (forms.ModelChoiceField)):
|
||||
field.widget.attrs.update(
|
||||
{
|
||||
"class": "oh-select oh-select-2 select2-hidden-accessible",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class HorillaPaginator(Paginator):
|
||||
@@ -118,7 +116,7 @@ class HorillaFilterSet(FilterSet):
|
||||
"""
|
||||
Search in generic method for filter field
|
||||
"""
|
||||
search = self.data.get("search", "").lower()
|
||||
search = self.data.get("search", "")
|
||||
search_field = self.data.get("search_field")
|
||||
if not search_field:
|
||||
search_field = self.filters[name].field_name
|
||||
|
||||
@@ -7,17 +7,17 @@ This module is used to register horilla addons
|
||||
from horilla import settings
|
||||
from horilla.settings import INSTALLED_APPS
|
||||
|
||||
INSTALLED_APPS.append("biometric")
|
||||
INSTALLED_APPS.append("horilla_audit")
|
||||
INSTALLED_APPS.append("horilla_widgets")
|
||||
INSTALLED_APPS.append("horilla_crumbs")
|
||||
INSTALLED_APPS.append("horilla_documents")
|
||||
INSTALLED_APPS.append("haystack")
|
||||
INSTALLED_APPS.append("helpdesk")
|
||||
INSTALLED_APPS.append("offboarding")
|
||||
INSTALLED_APPS.append("horilla_views")
|
||||
INSTALLED_APPS.append("horilla_automations")
|
||||
INSTALLED_APPS.append("auditlog")
|
||||
INSTALLED_APPS.append("biometric")
|
||||
INSTALLED_APPS.append("helpdesk")
|
||||
INSTALLED_APPS.append("offboarding")
|
||||
|
||||
|
||||
AUDITLOG_INCLUDE_ALL_MODELS = True
|
||||
|
||||
45
horilla/methods.py
Normal file
45
horilla/methods.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import contextlib
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
|
||||
def get_horilla_model_class(app_label, model):
|
||||
"""
|
||||
Retrieves the model class for the given app label and model name using Django's ContentType framework.
|
||||
|
||||
Args:
|
||||
app_label (str): The label of the application where the model is defined.
|
||||
model (str): The name of the model to retrieve.
|
||||
|
||||
Returns:
|
||||
Model: The Django model class corresponding to the specified app label and model name.
|
||||
|
||||
"""
|
||||
content_type = ContentType.objects.get(app_label=app_label, model=model)
|
||||
model_class = content_type.model_class()
|
||||
return model_class
|
||||
|
||||
|
||||
def dynamic_attr(obj, attribute_path):
|
||||
"""
|
||||
Retrieves the value of a nested attribute from a related object dynamically.
|
||||
|
||||
Args:
|
||||
obj: The base object from which to start accessing attributes.
|
||||
attribute_path (str): The path of the nested attribute to retrieve, using
|
||||
double underscores ('__') to indicate relationship traversal.
|
||||
|
||||
Returns:
|
||||
The value of the nested attribute if it exists, or None if it doesn't exist.
|
||||
"""
|
||||
attributes = attribute_path.split("__")
|
||||
|
||||
for attr in attributes:
|
||||
with contextlib.suppress(Exception):
|
||||
Contract = get_horilla_model_class(app_label="payroll", model="contract")
|
||||
if isinstance(obj.first(), Contract):
|
||||
obj = obj.filter(is_active=True).first()
|
||||
|
||||
obj = getattr(obj, attr, None)
|
||||
if obj is None:
|
||||
break
|
||||
return obj
|
||||
@@ -1,3 +1,13 @@
|
||||
"""
|
||||
models.py
|
||||
=========
|
||||
|
||||
This module defines the abstract base model `HorillaModel` for the Horilla HRMS project.
|
||||
The `HorillaModel` provides common fields and functionalities for other models within
|
||||
the application, such as tracking creation and modification timestamps and user
|
||||
information, audit logging, and active/inactive status management.
|
||||
"""
|
||||
|
||||
from auditlog.models import AuditlogHistoryField
|
||||
from auditlog.registry import auditlog
|
||||
from django.contrib.auth.models import User
|
||||
@@ -25,6 +35,11 @@ setattr(FieldFile, "url", url)
|
||||
|
||||
|
||||
class HorillaModel(models.Model):
|
||||
"""
|
||||
An abstract base model that includes common fields and functionalities
|
||||
for models within the Horilla application.
|
||||
"""
|
||||
|
||||
created_at = models.DateTimeField(
|
||||
auto_now_add=True,
|
||||
null=True,
|
||||
@@ -50,16 +65,23 @@ class HorillaModel(models.Model):
|
||||
related_name="%(class)s_modified_by",
|
||||
)
|
||||
horilla_history = AuditlogHistoryField()
|
||||
objects = models.Manager()
|
||||
is_active = models.BooleanField(default=True, verbose_name=_("Is Active"))
|
||||
|
||||
class Meta:
|
||||
"""
|
||||
Meta class for HorillaModel
|
||||
"""
|
||||
|
||||
abstract = True
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""
|
||||
Override the save method to automatically set the created_by and
|
||||
modified_by fields based on the current request user.
|
||||
"""
|
||||
request = getattr(_thread_locals, "request", None)
|
||||
# also here will have scheduled activities
|
||||
# at the time there will no change to the modified user,
|
||||
# its remains same as previous
|
||||
|
||||
if request:
|
||||
user = request.user
|
||||
|
||||
@@ -79,18 +101,25 @@ class HorillaModel(models.Model):
|
||||
|
||||
@classmethod
|
||||
def find(cls, object_id):
|
||||
"""
|
||||
Find an object of this class by its ID.
|
||||
"""
|
||||
try:
|
||||
object = cls.objects.filter(id=object_id).first()
|
||||
return object
|
||||
except:
|
||||
obj = cls.objects.filter(id=object_id).first()
|
||||
return obj
|
||||
except Exception as e:
|
||||
# Log the exception if needed
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def activate_deactivate(cls, object_id):
|
||||
object = cls.find(object_id)
|
||||
if object:
|
||||
object.is_active = not object.is_active
|
||||
object.save()
|
||||
"""
|
||||
Toggle the is_active status of an object of this class.
|
||||
"""
|
||||
obj = cls.find(object_id)
|
||||
if obj:
|
||||
obj.is_active = not obj.is_active
|
||||
obj.save()
|
||||
|
||||
|
||||
auditlog.register(HorillaModel, serialize_data=True)
|
||||
|
||||
@@ -14,34 +14,23 @@ import os
|
||||
from os.path import join
|
||||
from pathlib import Path
|
||||
|
||||
import environ
|
||||
from django.contrib.messages import constants as messages
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
|
||||
|
||||
env = environ.Env(
|
||||
DEBUG=(bool, True),
|
||||
SECRET_KEY=(
|
||||
str,
|
||||
"django-insecure-j8op9)1q8$1&0^s&p*_0%d#pr@w9qj@1o=3#@d=a(^@9@zd@%j",
|
||||
),
|
||||
ALLOWED_HOSTS=(list, ["*"]),
|
||||
CSRF_TRUSTED_ORIGINS=(list, ["http://localhost:8000"]),
|
||||
)
|
||||
|
||||
env.read_env(os.path.join(BASE_DIR, ".env"), overwrite=True)
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = env("SECRET_KEY")
|
||||
SECRET_KEY = "django-insecure-j8op9)1q8$1&0^s&p*_0%d#pr@w9qj@1o=3#@d=a(^@9@zd@%j"
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = env("DEBUG")
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
|
||||
ALLOWED_HOSTS = env("ALLOWED_HOSTS")
|
||||
|
||||
# Application definition
|
||||
|
||||
@@ -58,8 +47,8 @@ INSTALLED_APPS = [
|
||||
"simple_history",
|
||||
"django_filters",
|
||||
"base",
|
||||
"recruitment",
|
||||
"employee",
|
||||
"recruitment",
|
||||
"leave",
|
||||
"pms",
|
||||
"onboarding",
|
||||
@@ -114,27 +103,13 @@ WSGI_APPLICATION = "horilla.wsgi.application"
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
|
||||
|
||||
if env("DATABASE_URL", default=None):
|
||||
DATABASES = {
|
||||
"default": env.db(),
|
||||
}
|
||||
else:
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": env("DB_ENGINE", default="django.db.backends.sqlite3"),
|
||||
"NAME": env(
|
||||
"DB_NAME",
|
||||
default=os.path.join(
|
||||
BASE_DIR,
|
||||
"TestDB_Horilla.sqlite3",
|
||||
),
|
||||
),
|
||||
"USER": env("DB_USER", default=""),
|
||||
"PASSWORD": env("DB_PASSWORD", default=""),
|
||||
"HOST": env("DB_HOST", default=""),
|
||||
"PORT": env("DB_PORT", default=""),
|
||||
}
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": BASE_DIR / "TestDB_Horilla.sqlite3",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
|
||||
@@ -155,17 +130,29 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/4.1/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = "en-us"
|
||||
|
||||
TIME_ZONE = "Asia/Kolkata"
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.1/howto/static-files/
|
||||
|
||||
STATIC_URL = "static/"
|
||||
STATIC_ROOT = BASE_DIR / "staticfiles"
|
||||
STATIC_ROOT = "/static/"
|
||||
|
||||
STATICFILES_DIRS = [
|
||||
BASE_DIR / "static",
|
||||
]
|
||||
|
||||
STATICFILES_STORAGE = "whitenoise.storage.CompressedStaticFilesStorage"
|
||||
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
|
||||
|
||||
MEDIA_URL = "/media/"
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, "media/")
|
||||
@@ -184,7 +171,10 @@ MESSAGE_TAGS = {
|
||||
}
|
||||
|
||||
|
||||
CSRF_TRUSTED_ORIGINS = env("CSRF_TRUSTED_ORIGINS")
|
||||
CSRF_TRUSTED_ORIGINS = [
|
||||
"http://localhost:8000",
|
||||
]
|
||||
|
||||
|
||||
LOGIN_URL = "/login"
|
||||
|
||||
@@ -202,6 +192,8 @@ DJANGO_NOTIFICATIONS_CONFIG = {
|
||||
|
||||
X_FRAME_OPTIONS = "SAMEORIGIN"
|
||||
|
||||
LANGUAGE_CODE = "en-us"
|
||||
|
||||
LANGUAGES = (
|
||||
("en", "English (US)"),
|
||||
("de", "Deutsche"),
|
||||
@@ -214,12 +206,6 @@ LOCALE_PATHS = [
|
||||
join(BASE_DIR, "horilla", "locale"),
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/4.1/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = "en-us"
|
||||
|
||||
TIME_ZONE = "Asia/Kolkata"
|
||||
|
||||
USE_I18N = True
|
||||
@@ -227,15 +213,3 @@ USE_I18N = True
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
# Production settings
|
||||
if not DEBUG:
|
||||
SECURE_BROWSER_XSS_FILTER = True
|
||||
SECURE_SSL_REDIRECT = True
|
||||
SECURE_HSTS_SECONDS = 31536000
|
||||
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
|
||||
SECURE_HSTS_PRELOAD = True
|
||||
SECURE_CONTENT_TYPE_NOSNIFF = True
|
||||
SESSION_COOKIE_SECURE = True
|
||||
CSRF_COOKIE_SECURE = True
|
||||
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
horilla/signals.py
|
||||
"""
|
||||
|
||||
from django.dispatch import Signal, receiver
|
||||
from django.dispatch import Signal
|
||||
|
||||
pre_bulk_update = Signal()
|
||||
post_bulk_update = Signal()
|
||||
|
||||
@@ -19,7 +19,6 @@ from django.contrib import admin
|
||||
from django.urls import include, path, re_path
|
||||
|
||||
import notifications.urls
|
||||
from base.views import home, login_user, logout_user
|
||||
|
||||
from . import settings
|
||||
|
||||
@@ -30,16 +29,7 @@ urlpatterns = [
|
||||
path("", include("base.urls")),
|
||||
path("", include("horilla_automations.urls")),
|
||||
path("", include("horilla_views.urls")),
|
||||
path("recruitment/", include("recruitment.urls")),
|
||||
path("employee/", include("employee.urls")),
|
||||
path("leave/", include("leave.urls")),
|
||||
path("onboarding/", include("onboarding.urls")),
|
||||
path("pms/", include("pms.urls")),
|
||||
path("asset/", include("asset.urls")),
|
||||
path("attendance/", include("attendance.urls")),
|
||||
path("payroll/", include("payroll.urls.urls")),
|
||||
path("helpdesk/", include("helpdesk.urls")),
|
||||
path("offboarding/", include("offboarding.urls")),
|
||||
path("horilla-widget/", include("horilla_widgets.urls")),
|
||||
re_path(
|
||||
"^inbox/notifications/", include(notifications.urls, namespace="notifications")
|
||||
|
||||
Reference in New Issue
Block a user