diff --git a/biometric/templates/biometric/add_biometric_device.html b/biometric/templates/biometric/add_biometric_device.html index 889522e34..518e5d7b4 100644 --- a/biometric/templates/biometric/add_biometric_device.html +++ b/biometric/templates/biometric/add_biometric_device.html @@ -1,133 +1,111 @@ -{% load static %} {% load i18n %} {% if messages %} -
- {% for message in messages %} -
-
- {{ message }} +{% load static %} {% load i18n %} +{% if messages %} +
+ {% for message in messages %} +
+
+ {{ message }} +
+
+ {% endfor %} +
-
- {% endfor %} - -
{% endif %}
-

- {% trans "Add Biometric Device" %} -

- +

+ {% trans "Add Biometric Device" %} +

+
-
- {% csrf_token %} -
-
- - {{biometric_form.name}} -
-
- - {{biometric_form.machine_type}} -
- - - - - - - - -
- -
+
+ {% csrf_token %} +
+
+ + {{biometric_form.name}} +
+
+ + {{biometric_form.machine_type}} +
+ + + + + + + + +
+ +
diff --git a/biometric/templates/biometric/add_biometric_user.html b/biometric/templates/biometric/add_biometric_user.html index e1a56fa9d..37adbdeae 100644 --- a/biometric/templates/biometric/add_biometric_user.html +++ b/biometric/templates/biometric/add_biometric_user.html @@ -1,36 +1,32 @@ {% load i18n %}
- - {% trans "Add Employee" %} - - + + {% trans "Add Employee" %} + +
-
- {% csrf_token %} -
-
- - {{form.employee_ids}} -
-
- -
+
+ {% csrf_token %} +
+
+ + {{form.employee_ids}} +
+
+ +
diff --git a/biometric/templates/biometric/biometric_device_filter.html b/biometric/templates/biometric/biometric_device_filter.html index ec976daad..5eddb642b 100644 --- a/biometric/templates/biometric/biometric_device_filter.html +++ b/biometric/templates/biometric/biometric_device_filter.html @@ -6,21 +6,21 @@
- + {{f.form.machine_type}}
- + {{f.form.is_scheduler}}
- + {{f.form.is_active}}
- + {{f.form.is_live}}
diff --git a/biometric/templates/biometric/card_biometric_devices.html b/biometric/templates/biometric/card_biometric_devices.html index 8a7a29836..f098138f8 100644 --- a/biometric/templates/biometric/card_biometric_devices.html +++ b/biometric/templates/biometric/card_biometric_devices.html @@ -1,277 +1,199 @@ -{% load static %} {% load i18n %} {% load basefilters %} {% if messages %} -
- {% for message in messages %} -
-
- {{ message }} -
-
- {% endfor %} -
-{% endif %} {% include 'filter_tags.html' %} -{% if devices %} -
- {% for device in devices %} -
-
- {{device.name}} - {{device.get_machine_type_display}} - {% if device.machine_type == "zk" or device.machine_type == "cosec" %} - {{device.machine_ip}} - {% if device.machine_type == "zk" %} - {{device.port}} - {% endif %} {% else %} - {{device.api_url}} - {% endif %} - - - {% if device.machine_type == "zk" %} - - - {% endif %} - -
- {% trans "Activate live capture mode" %} - -
- -
-
-
-
-
- -
-
    -
  • - {% trans "Edit" %} -
  • - {% if perms.biometric.change_biometricdevices %} - {% if device.is_active %} -
  • - {% trans "Archive" %} -
  • - {% else %} -
  • - {% trans "Un-Archive" %} -
  • - {% endif %} - {% endif %} - {% if perms.biometric.delete_biometricdevices %} -
  • -
    - {% csrf_token %} - -
    -
  • - {% endif %} -
-
+{% load static %} +{% load i18n %} +{% load basefilters %} +{% include 'filter_tags.html' %} + +{% if messages %} +
+ {% for message in messages %} +
+
+ {{ message }} +
-
-
- {% trans "Test" %} - - {% if device.is_scheduler %} - {% trans "Unschedule" %} - - {% else %} - {% trans "Schedule" %} - {% endif %} - {% if device.machine_type == "zk" or device.machine_type == "cosec" %} - {% trans "Employee" %} - {% endif %} + {% endfor %} +
+{% endif %} + +{% if devices %} +
+ {% for device in devices %} +
+
+ {{device.name}} + {{device.get_machine_type_display}} + {% if device.machine_type == "zk" or device.machine_type == "cosec" %} + {{device.machine_ip}} + {% endif %} + {% if device.machine_type == "zk" %} + {{device.port}} + {% else %} + {{device.api_url}} + {% endif %} + + + {% if device.machine_type == "zk" %} + + + {% endif %} + +
+ {% trans "Activate live capture mode" %} + +
+ +
+
+
+
+
+ +
+
    +
  • + {% trans "Edit" %} +
  • + {% if perms.biometric.change_biometricdevices %} + {% if device.is_active %} +
  • + {% trans "Archive" %} +
  • + {% else %} +
  • + {% trans "Un-Archive" %} +
  • + {% endif %} + {% endif %} + {% if perms.biometric.delete_biometricdevices %} +
  • +
    + {% csrf_token %} + +
    +
  • + {% endif %} +
+
+
+
+
+ {% trans "Test" %} + + {% if device.is_scheduler %} + {% trans "Unschedule" %} + + {% else %} + {% trans "Schedule" %} + {% endif %} + {% if device.machine_type == "zk" or device.machine_type == "cosec" %} + {% trans "Employee" %} + {% endif %} +
+
+ {% endfor %} +
+
+ + {% trans "Page" %} {{ devices.number }} {% trans "of" %} {{ devices.paginator.num_pages }}. + + +
+ + +{% else %} +
+
+
+
+ Page not found. 404. +

+ {% trans "No biometric devices found." %} +

+
+
+
-
- {% endfor %} -
-
- - {% trans "Page" %} {{ devices.number }} {% trans "of" %} {{ devices.paginator.num_pages }}. - - -
- - -{% else %} -
-
-
-
- Page not found. 404. -

- {% trans "No biometric devices found." %} -

-
-
-
-
{% endif %} diff --git a/biometric/templates/biometric/edit_biometric_device.html b/biometric/templates/biometric/edit_biometric_device.html index c8925902b..a553e1403 100644 --- a/biometric/templates/biometric/edit_biometric_device.html +++ b/biometric/templates/biometric/edit_biometric_device.html @@ -1,133 +1,112 @@ -{% load i18n %} {% if messages %} -
- {% for message in messages %} -
-
- {{ message }} +{% load i18n %} +{% if messages %} +
+ {% for message in messages %} +
+
+ {{ message }} +
+
+ {% endfor %} +
-
- {% endfor %} - -
{% endif %}
-

- {% trans "Edit Biometric Devices" %} -

- +

+ {% trans "Edit Biometric Devices" %} +

+
-
- {% csrf_token %} {{form.errors}} {{biometric_form.non_field_errors}} -
-
- - {{biometric_form.name}} -
-
- - {{biometric_form.machine_type}} -
- - - - - - - - -
- -
+
+ {% csrf_token %} {{form.errors}} {{biometric_form.non_field_errors}} +
+
+ + {{biometric_form.name}} +
+
+ + {{biometric_form.machine_type}} +
+ + + + + + + + +
+ +
diff --git a/biometric/templates/biometric/edit_cosec_user.html b/biometric/templates/biometric/edit_cosec_user.html index 4f1f564ec..f20b74908 100644 --- a/biometric/templates/biometric/edit_cosec_user.html +++ b/biometric/templates/biometric/edit_cosec_user.html @@ -1,75 +1,62 @@ {% load i18n %}
- - {% trans "Edit COSEC User" %} - - -
-
-
- {% csrf_token %} {% if form.errors %} - - {% for error in form.non_field_errors %} -
    -
  • {{ error }}
  • -
- {% endfor %} - {% endif %} -
-
-
-
- - {{form.name}} -
-
-
- -
{{form.user_active}}
-
-
-
-
- -
{{form.by_pass_finger}}
-
-
- -
{{form.vip}}
-
-
-
-
- -
{{form.validity_enable}}
-
-
- -
{{form.validity_end_date}}
-
-
-
-
- -
-
+ + {% trans "Edit COSEC User" %} + +
-{% comment %} - -{% endcomment %} +
+
+ {% csrf_token %} + {% if form.errors %} + {% for error in form.non_field_errors %} +
    +
  • {{ error }}
  • +
+ {% endfor %} + {% endif %} +
+
+
+
+ + {{form.name}} +
+
+
+ +
{{form.user_active}}
+
+
+
+
+ +
{{form.by_pass_finger}}
+
+
+ +
{{form.vip}}
+
+
+
+
+ +
{{form.validity_enable}}
+
+
+ +
{{form.validity_end_date}}
+
+
+
+
+ +
+
+
diff --git a/biometric/templates/biometric/empty_view_biometric.html b/biometric/templates/biometric/empty_view_biometric.html index ea9f077a2..1abc684e1 100644 --- a/biometric/templates/biometric/empty_view_biometric.html +++ b/biometric/templates/biometric/empty_view_biometric.html @@ -1,14 +1,12 @@ {% load static %}{% load i18n %} -
-
- -
-
- Page not found. 404. -

{% trans "No biometric devices for attendance have been added yet." %}

-
-
-
+
+
+
+
+ Page not found. 404. +

{% trans "No biometric devices for attendance have been added yet." %}

+
+
+
diff --git a/biometric/templates/biometric/install_biometric_attendance.html b/biometric/templates/biometric/install_biometric_attendance.html index feeb98f3a..0d0e1bf10 100644 --- a/biometric/templates/biometric/install_biometric_attendance.html +++ b/biometric/templates/biometric/install_biometric_attendance.html @@ -1,33 +1,37 @@ -{% extends 'settings.html' %} {% load i18n %} {% block settings %} - +{% extends 'settings.html' %} +{% load i18n %} +{% block settings %}
-
+

{% trans "Biometric Attendance" %}

-
{% trans "Activate Biometric Attendance" %}    :      + +
{% trans "Activate Biometric Attendance" %}    : +      + {% if biometric.is_installed %} checked title="{% trans 'Activated' %}" {% else %} + title="{% trans 'Activate' %}" {% endif %} id="is_installed">
+ {% endblock settings %} diff --git a/biometric/templates/biometric/list_biometric_devices.html b/biometric/templates/biometric/list_biometric_devices.html index 75c66502c..6f83ef2fd 100644 --- a/biometric/templates/biometric/list_biometric_devices.html +++ b/biometric/templates/biometric/list_biometric_devices.html @@ -1,185 +1,155 @@ {% load i18n %}
-
-
-
-
-
- -
-
-
{% trans "Device" %}
-
{% trans "Machine IP" %}
-
{% trans "Port No." %}
-
- {% trans "Actions" %} -
-
-
- {% for device in devices %} -
-
-
-
- -
-
-
{{device.name}}
-
{{device.machine_ip}}
-
{{device.port}}
-
- {% comment %}
{% endcomment %} - {% comment %}
{% endcomment %} -
- -
-
+ {% for device in devices %} +
+
+
+
+ +
+
+
{{device.name}}
+
{{device.machine_ip}}
+
{{device.port}}
+
+ {% comment %}
{% endcomment %} + {% comment %}
{% endcomment %} +
+ + +
+ {% comment %} +
{% endcomment %} + {% comment %}
{% endcomment %} +
+
+
+ {% endfor %}
- {% endfor %} -
-{% comment %} +
- - {% trans "Page" %} {{ employees.number }} {% trans "of" %} {{ - employees.paginator.num_pages }}. - - -
{% endcomment %} + + {% trans "Page" %} {{ employees.number }} {% trans "of" %} {{ employees.paginator.num_pages }}. + + +
diff --git a/biometric/templates/biometric/nav_biometric_devices.html b/biometric/templates/biometric/nav_biometric_devices.html index c0703ac89..d802c74e7 100644 --- a/biometric/templates/biometric/nav_biometric_devices.html +++ b/biometric/templates/biometric/nav_biometric_devices.html @@ -1,168 +1,56 @@ {% load i18n %}{% load static %}
-
-
- {% trans "Biometric Devices" %} +
+
+ {% trans "Biometric Devices" %} +
+
- -
-
-
-
- - -
- {% comment %} - - {% endcomment %} -
-
- - -
- {% comment %} -
-
- - - {% endcomment %} -
-
- {% if perms.recruitment.add_candidate %} - - {% endif %} -
-
-
-
- +
-
+
diff --git a/biometric/templates/biometric/scheduler_device_form.html b/biometric/templates/biometric/scheduler_device_form.html index 10329d30a..b9931d5dc 100644 --- a/biometric/templates/biometric/scheduler_device_form.html +++ b/biometric/templates/biometric/scheduler_device_form.html @@ -1,36 +1,32 @@ {% load i18n %}
-

- {% trans "Schedule Biometric Device" %} -

- +

+ {% trans "Schedule Biometric Device" %} +

+
-
- {% csrf_token %} -
- {{scheduler_form.scheduler_duration.errors}} - -
{{scheduler_form.scheduler_duration}}
-
- -
+
+ {% csrf_token %} +
+ {{scheduler_form.scheduler_duration.errors}} + +
{{scheduler_form.scheduler_duration}}
+
+ +
diff --git a/biometric/templates/biometric/view_biometric_devices.html b/biometric/templates/biometric/view_biometric_devices.html index 0cc1ca8ed..6d8b209f3 100644 --- a/biometric/templates/biometric/view_biometric_devices.html +++ b/biometric/templates/biometric/view_biometric_devices.html @@ -1,116 +1,83 @@ {% extends 'index.html' %} {% block content %} {% load static %} {% load i18n %}
- {% include 'biometric/nav_biometric_devices.html' %} - + {% include 'biometric/nav_biometric_devices.html' %} + -
- - - {% trans "Not-Connected" %} - - - - {% trans "Scheduled" %} - - - - {% trans "Live Capture" %} - -
-
- {% if devices %} - {% comment %} {% if view_type == 'list' %} - {% include 'attendance/biometric/list_biometric_devices.html' %} - {% else %} {% endcomment %} - {% include 'biometric/card_biometric_devices.html' %} - {% comment %} {% endif %} {% endcomment %} - {% else %} - {% include 'biometric/empty_view_biometric.html' %} - {% endif %} -
- +
+ + + {% trans "Not-Connected" %} + + + + {% trans "Scheduled" %} + + + + {% trans "Live Capture" %} + +
+
+ {% if devices %} + {% include 'biometric/card_biometric_devices.html' %} + {% else %} + {% include 'biometric/empty_view_biometric.html' %} + {% endif %} +
+
{% endblock %} diff --git a/biometric/templates/biometric/view_cosec_employees.html b/biometric/templates/biometric/view_cosec_employees.html index 3ed452938..7916ca30f 100644 --- a/biometric/templates/biometric/view_cosec_employees.html +++ b/biometric/templates/biometric/view_cosec_employees.html @@ -1,27 +1,23 @@ -{% extends 'index.html' %} {% block content %} {% load static %} {% load i18n %} +{% extends 'index.html' %} +{% block content %} +{% load static %} +{% load i18n %} +
- {% include 'biometric/nav_employees_cosec_biometric.html' %} -
- {% include 'biometric/list_employees_cosec_biometric.html' %} -
- - {% endblock %} diff --git a/biometric/templates/biometric/view_employees_biometric.html b/biometric/templates/biometric/view_employees_biometric.html index aa276b175..d27587976 100644 --- a/biometric/templates/biometric/view_employees_biometric.html +++ b/biometric/templates/biometric/view_employees_biometric.html @@ -1,27 +1,22 @@ -{% extends 'index.html' %} {% block content %} {% load static %} {% load i18n %} +{% extends 'index.html' %} +{% block content %} +{% load static %} +{% load i18n %}
- {% include 'biometric/nav_employees_biometric.html' %} -
- {% include 'biometric/list_employees_biometric.html' %} -
- - {% endblock %} diff --git a/biometric/views.py b/biometric/views.py index 045ac6371..2976fc960 100644 --- a/biometric/views.py +++ b/biometric/views.py @@ -17,10 +17,12 @@ from apscheduler.schedulers.background import BackgroundScheduler from django.contrib import messages from django.http import HttpResponse, JsonResponse from django.shortcuts import redirect, render +from django.utils import timezone as django_timezone from django.utils.translation import gettext as __ from django.utils.translation import gettext_lazy as _ from zk import ZK +from attendance.methods.utils import Request from attendance.views.clock_in_out import clock_in, clock_out from base.methods import get_key_instances, get_pagination from employee.models import Employee, EmployeeWorkInformation @@ -104,50 +106,6 @@ def biometric_set_time(conn): conn.set_time(new_time) -class META: - """ - Provides access to HTTP metadata keys. - """ - - @classmethod - def keys(cls): - """ - Retrieve the list of available HTTP metadata keys. - - Returns: - list: A list of HTTP metadata keys. - """ - return ["HTTP_HX_REQUEST"] - - -class Request: - """ - Represents a request for clock-in or clock-out. - - Attributes: - - user: The user associated with the request. - - date: The date of the request. - - time: The time of the request. - - path: The path associated with the request (default: "/"). - - session: The session data associated with the request (default: {"title": None}). - """ - - def __init__( - self, - user, - date, - time, - datetime, - ) -> None: - self.user = user - self.path = "/" - self.session = {"title": None} - self.date = date - self.time = time - self.datetime = datetime - self.META = META() - - class ZKBioAttendance(Thread): """ Represents a thread for capturing live attendance data from a ZKTeco biometric device. @@ -193,7 +151,10 @@ class ZKBioAttendance(Thread): if attendance: user_id = attendance.user_id punch_code = attendance.punch - date_time = attendance.timestamp + date_time = django_timezone.make_aware( + attendance.timestamp + ) + # date_time = attendance.timestamp date = date_time.date() time = date_time.time() device.last_fetch_date = date @@ -1043,42 +1004,40 @@ def biometric_device_employees(request, device_id, **kwargs): previous_data = request.GET.urlencode() device = BiometricDevices.find(device_id) if device: - try: - if device.machine_type == "zk": - employee_add_form = EmployeeBiometricAddForm() - employees = zk_employees_fetch(device) - employees = paginator_qry(employees, request.GET.get("page")) - context = { - "employees": employees, - "device_id": device_id, - "form": employee_add_form, - "pd": previous_data, - } - return render( - request, "biometric/view_employees_biometric.html", context - ) - if device.machine_type == "cosec": - employee_add_form = CosecUserAddForm() - employees = cosec_employee_fetch(device_id) - employees = biometric_paginator_qry( - employees, int(request.GET.get("page", 1)) - ) - context = { - "employees": employees, - "device_id": device.id, - "form": employee_add_form, - "pd": previous_data, - } - return render(request, "biometric/view_cosec_employees.html", context) - except Exception as error: - print(f"An error occurred: {error}") - messages.info( - request, - _( - "Failed to establish a connection. Please verify the accuracy of the IP\ - Address and Port No. of the device." - ), + # try: + if device.machine_type == "zk": + employee_add_form = EmployeeBiometricAddForm() + employees = zk_employees_fetch(device) + employees = paginator_qry(employees, request.GET.get("page")) + context = { + "employees": employees, + "device_id": device_id, + "form": employee_add_form, + "pd": previous_data, + } + return render(request, "biometric/view_employees_biometric.html", context) + if device.machine_type == "cosec": + employee_add_form = CosecUserAddForm() + employees = cosec_employee_fetch(device_id) + employees = biometric_paginator_qry( + employees, int(request.GET.get("page", 1)) ) + context = { + "employees": employees, + "device_id": device.id, + "form": employee_add_form, + "pd": previous_data, + } + return render(request, "biometric/view_cosec_employees.html", context) + # except Exception as error: + # print(f"An error occurred: {error}") + # messages.info( + # request, + # _( + # "Failed to establish a connection. Please verify the accuracy of the IP\ + # Address and Port No. of the device." + # ), + # ) else: messages.error(request, _("Biometric device not found")) return redirect(biometric_devices_view) @@ -1732,7 +1691,7 @@ def zk_biometric_device_attendance(device_id): for attendance in filtered_attendances: user_id = attendance.user_id punch_code = attendance.punch - date_time = attendance.timestamp + date_time = django_timezone.make_aware(attendance.timestamp) date = date_time.date() time = date_time.time() bio_id = BiometricEmployees.objects.filter(user_id=user_id).first() @@ -1776,7 +1735,7 @@ def anviz_biometric_device_attendance(device_id): date_time_obj = datetime.strptime( attendance["checktime"], "%Y-%m-%dT%H:%M:%S%z" ) - target_timezone = pytz.timezone(settings.TIME_ZONE) + target_timezone = pytz.django_timezone(settings.TIME_ZONE) date_time_obj = date_time_obj.astimezone(target_timezone) employee = Employee.objects.filter(badge_id=badge_id).first() if employee: @@ -1784,7 +1743,7 @@ def anviz_biometric_device_attendance(device_id): user=employee.employee_user_id, date=date_time_obj.date(), time=date_time_obj.time(), - datetime=date_time_obj, + datetime=django_timezone.make_aware(date_time_obj), ) if punch_code in {0, 128}: try: @@ -1853,7 +1812,7 @@ def cosec_biometric_device_attendance(device_id): user=employee.employee_id.employee_user_id, date=attendance_date, time=attendance_time, - datetime=attendance_datetime, + datetime=django_timezone.make_aware(attendance_datetime), ) try: