From 71ba49b6c56fd2b7698d98bb66b11841c6a32dd6 Mon Sep 17 00:00:00 2001 From: Horilla Date: Thu, 17 Jul 2025 15:19:44 +0530 Subject: [PATCH] CBV code updates: 17th July --- attendance/forms.py | 23 +- .../attendance_request.html | 4 +- attendance/views/requests.py | 4 +- employee/templates/documents/requests.html | 277 ++++++++---------- .../templates/generic/horilla_section.html | 4 + pg_backup/apps.py | 5 +- pg_backup/scheduler.py | 64 ++-- 7 files changed, 188 insertions(+), 193 deletions(-) diff --git a/attendance/forms.py b/attendance/forms.py index edf124a71..26ec57a57 100644 --- a/attendance/forms.py +++ b/attendance/forms.py @@ -34,7 +34,7 @@ from django import forms from django.apps import apps from django.core.exceptions import ValidationError from django.db.models.query import QuerySet -from django.forms import DateTimeInput +from django.forms import DateInput, DateTimeInput, TimeInput from django.template.loader import render_to_string from django.utils.html import format_html from django.utils.text import capfirst @@ -661,6 +661,14 @@ class AttendanceRequestForm(BaseModelForm): "batch_attendance_id", ] + widgets = { + "attendance_clock_in": TimeInput(attrs={"type": "time"}), + "attendance_clock_out": TimeInput(attrs={"type": "time"}), + "attendance_clock_out_date": DateInput(attrs={"type": "date"}), + "attendance_date": DateInput(attrs={"type": "date"}), + "attendance_clock_in_date": DateInput(attrs={"type": "date"}), + } + def as_p(self, *args, **kwargs): """ Render the form fields as HTML table rows with Bootstrap styling. @@ -1076,12 +1084,16 @@ class BulkAttendanceRequestForm(BaseModelForm): from_date = forms.DateField( required=False, label=_("From Date"), - widget=forms.DateInput(attrs={"type": "date", "class": "form-control"}), + widget=forms.DateInput( + attrs={"type": "date", "class": "form-control oh-input w-100"} + ), ) to_date = forms.DateField( required=False, label=_("To Date"), - widget=forms.DateInput(attrs={"type": "date", "class": "form-control"}), + widget=forms.DateInput( + attrs={"type": "date", "class": "form-control oh-input w-100"} + ), ) batch_attendance_id = forms.ModelChoiceField( queryset=BatchAttendance.objects.all(), @@ -1110,6 +1122,11 @@ class BulkAttendanceRequestForm(BaseModelForm): "request_description", ) + widgets = { + "attendance_clock_in": TimeInput(attrs={"type": "time"}), + "attendance_clock_out": TimeInput(attrs={"type": "time"}), + } + def update_worked_hour_hx_fields(self, field_name): """Update the widget attributes for worked hour fields.""" self.fields[field_name].widget.attrs.update( diff --git a/attendance/templates/cbv/attendance_request/attendance_request.html b/attendance/templates/cbv/attendance_request/attendance_request.html index 1e72836cf..2ee982fe9 100644 --- a/attendance/templates/cbv/attendance_request/attendance_request.html +++ b/attendance/templates/cbv/attendance_request/attendance_request.html @@ -103,7 +103,7 @@ role="dialog" aria-labelledby="validateAttendanceRequest" aria-hidden="true" - style="z-index: 35;" + style="z-index: 1025;" >
@@ -127,7 +127,7 @@ role="dialog" aria-labelledby="genericModalEdit" aria-hidden="true" - style="z-index: 45;" + style="z-index: 1025;" >
diff --git a/attendance/views/requests.py b/attendance/views/requests.py index b9a5a9ac9..3f62a3d77 100644 --- a/attendance/views/requests.py +++ b/attendance/views/requests.py @@ -433,11 +433,11 @@ def validate_attendance_request(request, attendance_id): first_dict = empty_data else: other_dict = json.loads(attendance.requested_data) - requests_ids_json = request.GET.get("requests_ids") + requests_ids_json = request.session.get("ordered_ids_attendance", []) previous_instance_id = next_instance_id = attendance.pk if requests_ids_json: previous_instance_id, next_instance_id = closest_numbers( - json.loads(requests_ids_json), attendance_id + requests_ids_json, attendance_id ) return render( request, diff --git a/employee/templates/documents/requests.html b/employee/templates/documents/requests.html index 257472e2b..0638f6492 100644 --- a/employee/templates/documents/requests.html +++ b/employee/templates/documents/requests.html @@ -78,173 +78,140 @@
-
-
- - -
-
{% for document in document_list.list %} -
-
- -
- {% if document.document %} - {% if document.status == "approved" %} - - - {% elif document.status == 'rejected' %} - - - +
+
+ +
+ {% if document.document %} + {% if document.status == "approved" %} + + + {% elif document.status == 'rejected' %} + + + + {% else %} + + + + {% endif %} {% else %} - - - + + + {% endif %} - {% else %} +
+
+ {{document.title}} -- {{document.employee_id.get_full_name}} + + class="oh-user_permission_list-text oh-text--light" + title="{{document.document_request_id.description}}" + > + {{document.document_request_id.description|truncatechars:20}} + +
+
+
+ {% if perms.horilla_document.change_documentrequest %} + {% if document.status == "approved" or not document.document %} + + + + {% else %} + + + + {% endif %} + {% if document.status == 'rejected' or not document.document %} + + + + {% else %} + + + + {% endif %} + {% endif %} +
+ {% csrf_token %} +
-
- {{document.title}} -- {{document.employee_id.get_full_name}} - - - {{document.document_request_id.description|truncatechars:20}} - + aria-label="trash outline" + > + +
-
- {% if perms.horilla_document.change_documentrequest %} - {% if document.status == "approved" or not document.document %} - - - - {% else %} - - - - {% endif %} - {% if document.status == 'rejected' or not document.document %} - - - - {% else %} - - - - {% endif %} - {% endif %} -
- {% csrf_token %} - -
-
-
+ {% endfor %}
{% trans "Page" %} {{ document_list.list.number }} diff --git a/horilla_views/templates/generic/horilla_section.html b/horilla_views/templates/generic/horilla_section.html index a7b231fcd..c4a5054f1 100644 --- a/horilla_views/templates/generic/horilla_section.html +++ b/horilla_views/templates/generic/horilla_section.html @@ -21,6 +21,7 @@ >
+{% if nav_url %}
+{% endif %} +{% if view_url %}
+{% endif %} {% endblock content %} diff --git a/pg_backup/apps.py b/pg_backup/apps.py index a269d8a00..3edfde110 100644 --- a/pg_backup/apps.py +++ b/pg_backup/apps.py @@ -2,9 +2,10 @@ from django.apps import AppConfig class PgGitBackupConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'pg_backup' + default_auto_field = "django.db.models.BigAutoField" + name = "pg_backup" def ready(self): from pg_backup import scheduler + return super().ready() diff --git a/pg_backup/scheduler.py b/pg_backup/scheduler.py index f63968c47..13d87225d 100644 --- a/pg_backup/scheduler.py +++ b/pg_backup/scheduler.py @@ -37,44 +37,43 @@ Backups can also be triggered manually by calling `backup_postgres()`. """ -import os -import environ import datetime -import subprocess -import shutil import logging import logging.config +import os +import shutil +import subprocess from pathlib import Path + +import environ from apscheduler.schedulers.background import BackgroundScheduler from django.conf import settings # === Logging Configuration === LOGGING_CONFIG = { - 'version': 1, - 'disable_existing_loggers': False, - 'formatters': { - 'standard': { - 'format': '[%(asctime)s] [%(levelname)s] %(name)s: %(message)s' + "version": 1, + "disable_existing_loggers": False, + "formatters": { + "standard": {"format": "[%(asctime)s] [%(levelname)s] %(name)s: %(message)s"}, + }, + "handlers": { + "console": { + "class": "logging.StreamHandler", + "formatter": "standard", }, }, - 'handlers': { - 'console': { - 'class': 'logging.StreamHandler', - 'formatter': 'standard', + "loggers": { + "pg_backup": { + "handlers": ["console"], + "level": "INFO", + "propagate": False, }, }, - 'loggers': { - 'pg_backup': { - 'handlers': ['console'], - 'level': 'INFO', - 'propagate': False, - }, - } } logging.config.dictConfig(LOGGING_CONFIG) -logger = logging.getLogger('pg_backup') +logger = logging.getLogger("pg_backup") # === Configuration === @@ -90,7 +89,9 @@ db = settings.DATABASES["default"] DB_ENGINE = db["ENGINE"] if "postgresql" not in DB_ENGINE: - logger.warning("Skipping backup scheduler: not a PostgreSQL database (engine: %s)", DB_ENGINE) + logger.warning( + "Skipping backup scheduler: not a PostgreSQL database (engine: %s)", DB_ENGINE + ) else: DB_NAME = db["NAME"] DB_USER = db["USER"] @@ -110,13 +111,18 @@ else: command = [ shutil.which("pg_dump"), - "-h", DB_HOST, - "-p", DB_PORT, - "-U", DB_USER, - "-F", "c", + "-h", + DB_HOST, + "-p", + DB_PORT, + "-U", + DB_USER, + "-F", + "c", "-b", "-v", - "-f", str(backup_file), + "-f", + str(backup_file), DB_NAME, ] @@ -145,11 +151,11 @@ else: hour, minute = map(int, time_str.split(":")) scheduler.add_job( backup_postgres, - 'cron', + "cron", hour=hour, minute=minute, id=f"backup_{hour}_{minute}", - replace_existing=True + replace_existing=True, ) logger.info("Backup scheduled at %02d:%02d", hour, minute) except ValueError: