diff --git a/attendance/scheduler.py b/attendance/scheduler.py new file mode 100644 index 000000000..103a6a608 --- /dev/null +++ b/attendance/scheduler.py @@ -0,0 +1,41 @@ +import datetime +import sys +from apscheduler.schedulers.background import BackgroundScheduler + + +today = datetime.datetime.today() + + +def create_work_record(date=today): + from attendance.models import WorkRecords + from employee.models import Employee + + work_records = WorkRecords.objects.all() + employees = Employee.objects.all() + if len(work_records.filter(date=date)) == len(employees): + return + else: + for employee in employees: + try: + shift = employee.employee_work_info.shift_id + + WorkRecords.objects.get_or_create( + employee_id=employee, + date=date, + defaults={"work_record_type": "DFT", "shift_id": shift, "message": ""}, + ) + except: + pass + + +if not any( + cmd in sys.argv + for cmd in ["makemigrations", "migrate", "compilemessages", "flush", "shell"] +): + """ + Initializes and starts background tasks using APScheduler when the server is running. + """ + scheduler = BackgroundScheduler() + scheduler.add_job(create_work_record, "interval", hours=3) + + scheduler.start() diff --git a/attendance/templates/attendance/work_record/work_record_view.html b/attendance/templates/attendance/work_record/work_record_view.html index 50ba00f7e..5a64a87eb 100644 --- a/attendance/templates/attendance/work_record/work_record_view.html +++ b/attendance/templates/attendance/work_record/work_record_view.html @@ -62,7 +62,7 @@ name="month" hx-get="{% url 'work-records-change-month' %}" hx-target="#workRecordTable" - hx-trigger="input"> + hx-trigger="keyup changed delay:0.5s">