diff --git a/biometric/context_processors.py b/biometric/context_processors.py index 7c651b1e1..92b4658d9 100644 --- a/biometric/context_processors.py +++ b/biometric/context_processors.py @@ -11,7 +11,7 @@ Functions: from base.models import BiometricAttendance -def biometric_is_installed(request): +def biometric_is_installed(_request): """ Check if the biometric system is installed. diff --git a/biometric/templates/biometric/add_biometric_device.html b/biometric/templates/biometric/add_biometric_device.html index 518e5d7b4..93b5975f9 100644 --- a/biometric/templates/biometric/add_biometric_device.html +++ b/biometric/templates/biometric/add_biometric_device.html @@ -2,25 +2,21 @@ {% if messages %}
{% for message in messages %} -
-
- {{ message }} +
+
+ {{ message }} +
-
{% endfor %} - +
{% endif %}

{% trans "Add Biometric Device" %}

-
@@ -57,9 +53,11 @@ {{biometric_form.cosec_password.errors}} {{biometric_form.cosec_password}} -
{% endfor %} - + {% endif %}

{% trans "Edit Biometric Devices" %}

-
diff --git a/biometric/views.py b/biometric/views.py index 78aac6c3b..5eead8420 100644 --- a/biometric/views.py +++ b/biometric/views.py @@ -12,13 +12,11 @@ from datetime import datetime from threading import Event, Thread from urllib.parse import parse_qs, unquote -import pytz import requests 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 from django.utils import timezone as django_timezone from django.utils.translation import gettext as __ from django.utils.translation import gettext_lazy as _ @@ -180,8 +178,9 @@ class ZKBioAttendance(Thread): ) except Exception as error: logger.error( - f"Got an error in clock_in {error}" + "Got an error in clock_in %s", error ) + continue else: try: @@ -195,7 +194,7 @@ class ZKBioAttendance(Thread): ) except Exception as error: logger.error( - f"Got an error in clock_out {error}" + "Got an error in clock_out", error ) continue else: @@ -204,10 +203,28 @@ class ZKBioAttendance(Thread): ZKBioAttendance(self.machine_ip, self.port_no).start() def stop(self): + """To stop the ZK live capture mode""" self.conn.end_live_capture = True class COSECBioAttendanceThread(Thread): + """ + A thread class that handles the real-time retrieval and processing of + biometric attendance data from a COSEC biometric device. + + Attributes: + device_id (int): The ID of the biometric device to interact with. + _stop_event (threading.Event): An event to signal when to stop the thread. + + Methods: + run(): + Continuously fetches attendance data from the COSEC device, processes + it, and updates the last fetched sequence and rollover count. + + stop(): + Signals the thread to stop by setting the _stop_event. + """ + def __init__(self, device_id): super().__init__() self.device_id = device_id @@ -273,7 +290,7 @@ class COSECBioAttendanceThread(Thread): elif punch_code in ["2", "4", "6", "8", "10"]: clock_out(request_data) except Exception as error: - logger.error(f"Error processing attendance: {error}") + logger.error("Error processing attendance: ", error) if attendances: last_attendance = attendances[-1] @@ -293,7 +310,7 @@ class COSECBioAttendanceThread(Thread): device = BiometricDevices.objects.get(id=self.device_id) device.is_live = False device.save() - logger.error(f"Error in COSECBioAttendanceThread: {error}") + logger.error("Error in COSECBioAttendanceThread: ", error) def stop(self): """Set the stop event to signal the thread to stop gracefully.""" @@ -513,7 +530,7 @@ def biometric_device_schedule(request, device_id): scheduler.start() return HttpResponse("") except Exception as error: - logger.error(f"An error comes in biometric_device_schedule {error}") + logger.error("An error comes in biometric_device_schedule ", error) script = """ """ except Exception as error: - logger.error(f"An error comes in biometric_device_test {error}") + logger.error("An error comes in biometric_device_test ", error) script = """ """ except Exception as error: + logger.error( + "Got an error in test connection of Anviz Biometric Device", error + ) pass elif device.machine_type == "cosec": cosec = COSECBiometric( @@ -1138,7 +1158,7 @@ def biometric_device_employees(request, device_id, **kwargs): } return render(request, "biometric/view_cosec_employees.html", context) except Exception as error: - logger.error(f"An error occurred: {error}") + logger.error("An error occurred: ", error) messages.info( request, _( @@ -1249,10 +1269,8 @@ def delete_biometric_user(request, uid, device_id): employee_bio.delete() messages.success( request, - _( - "{} successfully removed from the biometric device.".format( - employee_bio.employee_id - ), + _("{} successfully removed from the biometric device.").format( + employee_bio.employee_id ), ) redirect_url = f"/biometric/biometric-device-employees/{device_id}/" @@ -1424,10 +1442,8 @@ def delete_horilla_cosec_user(request, user_id, device_id): employee_bio.delete() messages.success( request, - _( - "{} successfully removed from the biometric device.".format( - employee_bio.employee_id - ), + _("{} successfully removed from the biometric device.").format( + employee_bio.employee_id ), ) else: @@ -1479,14 +1495,12 @@ def bio_users_bulk_delete(request): conn.refresh_data() messages.success( request, - _( - "{} successfully removed from the biometric device.".format( - employee_bio.employee_id - ), + _("{} successfully removed from the biometric device.").format( + employee_bio.employee_id ), ) except Exception as error: - logger.error(f"An error occurred: {error}") + logger.error("An error occurred: ", error) return JsonResponse({"messages": "Success"}) @@ -1528,7 +1542,7 @@ def cosec_users_bulk_delete(request): ) except Exception as error: - logger.error(f"An error occurred: {error}") + logger.error("An error occurred: ", error) return JsonResponse({"messages": "Success"}) @@ -1597,7 +1611,8 @@ def add_biometric_user(request, device_id): user_id=str(user_id), card=0, ) - # The ZK Biometric user ID must be a character value that can be converted to an integer. + # The ZK Biometric user ID must be a character value + # that can be converted to an integer. BiometricEmployees.objects.create( uid=uid, user_id=str(user_id), @@ -1606,18 +1621,14 @@ def add_biometric_user(request, device_id): ) messages.success( request, - _( - "{} added to biometric device successfully".format( - employee - ), + _("{} added to biometric device successfully").format( + employee ), ) else: messages.info( request, - _( - "{} already added to biometric device".format(employee), - ), + _("{} already added to biometric device").format(employee), ) else: cosec = COSECBiometric( @@ -1662,7 +1673,7 @@ def add_biometric_user(request, device_id): except Exception as error: if device.machine_type == "zk": conn.disable_device() - logger.error(f"An error occurred: {str(error)}") + logger.error("An error occurred: ", str(error)) return HttpResponse("") return render( request, @@ -1746,7 +1757,7 @@ def biometric_device_live(request): except TimeoutError as error: device.is_live = False device.save() - logger.error(f"An error comes in biometric_device_live {error}") + logger.error("An error comes in biometric_device_live", error) script = """