2024-09-10 13:50:54 +05:30
|
|
|
"""
|
|
|
|
|
This module defines the configuration for the 'attendance' app within the Horilla HRMS project.
|
|
|
|
|
"""
|
|
|
|
|
|
2023-05-10 15:06:57 +05:30
|
|
|
from django.apps import AppConfig
|
|
|
|
|
|
2024-09-30 14:31:06 +05:30
|
|
|
from horilla.horilla_settings import APP_URLS
|
|
|
|
|
|
2023-05-10 15:06:57 +05:30
|
|
|
|
|
|
|
|
class AttendanceConfig(AppConfig):
|
2024-09-10 13:50:54 +05:30
|
|
|
"""
|
|
|
|
|
Configures the 'attendance' app and performs additional setup during the app's
|
|
|
|
|
initialization. This includes appending the 'attendance' URL patterns to the
|
|
|
|
|
project's main urlpatterns and dynamically adding the 'AttendanceMiddleware'
|
|
|
|
|
to the middleware stack if it's not already present.
|
|
|
|
|
"""
|
|
|
|
|
|
2024-03-10 19:37:46 +05:30
|
|
|
default_auto_field = "django.db.models.BigAutoField"
|
|
|
|
|
name = "attendance"
|
2024-08-05 14:22:44 +05:30
|
|
|
|
|
|
|
|
def ready(self):
|
|
|
|
|
from django.urls import include, path
|
|
|
|
|
|
2024-08-16 10:20:58 +05:30
|
|
|
from horilla.settings import MIDDLEWARE
|
2024-08-05 14:22:44 +05:30
|
|
|
from horilla.urls import urlpatterns
|
|
|
|
|
|
|
|
|
|
urlpatterns.append(
|
|
|
|
|
path("attendance/", include("attendance.urls")),
|
|
|
|
|
)
|
2024-08-16 10:20:58 +05:30
|
|
|
middleware_path = "attendance.middleware.AttendanceMiddleware"
|
|
|
|
|
if middleware_path not in MIDDLEWARE:
|
|
|
|
|
MIDDLEWARE.append(middleware_path)
|
|
|
|
|
|
2024-09-30 14:31:06 +05:30
|
|
|
APP_URLS.append("attendance.urls") # Used to remove Dynamically Added Urls
|
2025-01-01 14:35:06 +05:30
|
|
|
try:
|
|
|
|
|
self.create_enable_disable_check_in()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
2024-08-05 14:22:44 +05:30
|
|
|
super().ready()
|
2024-12-31 18:58:12 +05:30
|
|
|
|
|
|
|
|
def create_enable_disable_check_in(self):
|
|
|
|
|
"""
|
|
|
|
|
Checks if an AttendanceGeneralSetting object exists for each company.
|
|
|
|
|
If it doesn't exist, creates one.
|
|
|
|
|
"""
|
|
|
|
|
from attendance.models import AttendanceGeneralSetting
|
|
|
|
|
from base.models import Company
|
|
|
|
|
|
|
|
|
|
companies = Company.objects.all()
|
|
|
|
|
for company in companies:
|
|
|
|
|
if not AttendanceGeneralSetting.objects.filter(company_id=company).exists():
|
|
|
|
|
try:
|
|
|
|
|
AttendanceGeneralSetting.objects.create(company_id=company)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
2025-01-16 16:51:15 +05:30
|
|
|
AttendanceGeneralSetting.objects.get_or_create(company_id=None)
|