[UPDT] BIOMETRIC: Replace timezone datetime object fetching in anviz biometric device attendance fetching

This commit is contained in:
Horilla
2024-08-14 14:11:34 +05:30
parent aacdb0335d
commit 922352a166
2 changed files with 110 additions and 111 deletions

View File

@@ -4,126 +4,122 @@
{% include 'filter_tags.html' %}
{% if messages %}
<div class="oh-wrapper">
{% for message in messages %}
<div class="oh-alert-container">
<div class="oh-alert oh-alert--animated {{message.tags}}">
{{ message }}
</div>
<div class="oh-wrapper">
{% for message in messages %}
<div class="oh-alert-container">
<div class="oh-alert oh-alert--animated {{message.tags}}">
{{ message }}
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% endif %}
{% if devices %}
<div class="oh-layout--grid-3">
{% for device in devices %}
<div class="oh-kanban-card oh-kanban-card--biometric
{% if device.is_live %}
oh-kanban-card--orange
{% elif device.is_scheduler %}
oh-kanban-card--blue
{% else %}
oh-kanban-card--red
{% endif %}"
>
<div class="oh-kanban-card__details">
<span class="oh-kanban-card__title">{{device.name}}</span>
<span class="oh-kanban-card__subtitle d-block">{{device.get_machine_type_display}}</span>
{% if device.machine_type == "zk" or device.machine_type == "cosec" %}
<span class="oh-kanban-card__subtitle d-block">{{device.machine_ip}}</span>
{% endif %}
{% if device.machine_type == "zk" %}
<span class="oh-kanban-card__subtitle d-block">{{device.port}}</span>
{% else %}
<span class="oh-kanban-card__subtitle d-block">{{device.api_url}}</span>
{% endif %}
<table>
<tr>
{% if device.machine_type == "zk" %}
<td>
<span class="oh-kanban-card__subtitle d-block">{% trans "Activate live capture mode" %}</span>
</td>
<td>
<div class="oh-switch">
<input type="checkbox"
class="style-widget oh-switch__checkbox is-live-activate"
{% if device.is_live %} checked title="{% trans 'Deactivate' %}" {% else %} title="{% trans 'Activate' %}" {% endif %}
data-toggle="oh-modal-toggle"
data-target="#BiometricDeviceTestModal" name="is_live" hx-trigger="change"
hx-get="{% url 'biometric-device-live-capture' %}?deviceId={{device.id}}&{{pd}}&page={{devices.number}}&view=card"
hx-target="#BiometricDeviceTestFormTarget" />
</div>
</td>
{% endif %}
</tr>
</table>
</div>
<div class="oh-kanban-card__dots">
<div class="oh-dropdown" x-data="{show: false}">
<button class="oh-btn oh-btn--transparent text-muted p-3" @click="show = !show">
<ion-icon name="ellipsis-vertical-sharp"></ion-icon>
</button>
<div class="oh-dropdown__menu oh-dropdown__menu--dark-border oh-dropdown__menu--right" x-show="show"
@click.outside="show = false">
<ul class="oh-dropdown__items">
<li class="oh-dropdown__item">
<a hx-get="{% url 'biometric-device-edit' device.id %}" class="oh-dropdown__link"
data-toggle="oh-modal-toggle" data-target="#BiometricDeviceModal"
hx-target="#BiometricDeviceFormTarget">{% trans "Edit" %}</a>
</li>
{% if perms.biometric.change_biometricdevices %}
{% if device.is_active %}
<div class="oh-kanban-card oh-kanban-card--biometric {% if device.is_live %} oh-kanban-card--orange {% elif device.is_scheduler %} oh-kanban-card--blue {% else %} oh-kanban-card--red {% endif %}">
<div class="oh-kanban-card__details">
<span class="oh-kanban-card__title">{{device.name}}</span>
<span class="oh-kanban-card__subtitle d-block">{{device.get_machine_type_display}}</span>
{% if device.machine_type == "zk" or device.machine_type == "cosec" %}
<span class="oh-kanban-card__subtitle d-block">{{device.machine_ip}}</span>
{% endif %}
{% if device.machine_type == "zk" %}
<span class="oh-kanban-card__subtitle d-block">{{device.port}}</span>
{% else %}
<span class="oh-kanban-card__subtitle d-block">{{device.api_url}}</span>
{% endif %}
<table>
<tr>
{% if device.machine_type == "zk" %}
<td>
<span class="oh-kanban-card__subtitle d-block">{% trans "Activate live capture mode" %}</span>
</td>
<td>
<div class="oh-switch">
<input type="checkbox" class="style-widget oh-switch__checkbox is-live-activate"
{% if device.is_live %}
checked title="{% trans 'Deactivate' %}"
{% else %}
title="{% trans 'Activate' %}"
{% endif %}
data-toggle="oh-modal-toggle"
data-target="#BiometricDeviceTestModal" name="is_live" hx-trigger="change"
hx-get="{% url 'biometric-device-live-capture' %}?deviceId={{device.id}}&{{pd}}&page={{devices.number}}&view=card"
hx-target="#BiometricDeviceTestFormTarget" />
</div>
</td>
{% endif %}
</tr>
</table>
</div>
<div class="oh-kanban-card__dots">
<div class="oh-dropdown" x-data="{show: false}">
<button class="oh-btn oh-btn--transparent text-muted p-3" @click="show = !show">
<ion-icon name="ellipsis-vertical-sharp"></ion-icon>
</button>
<div class="oh-dropdown__menu oh-dropdown__menu--dark-border oh-dropdown__menu--right" x-show="show"
@click.outside="show = false">
<ul class="oh-dropdown__items">
<li class="oh-dropdown__item">
<a hx-get="{% url 'biometric-device-edit' device.id %}" class="oh-dropdown__link"
data-toggle="oh-modal-toggle" data-target="#BiometricDeviceModal"
hx-target="#BiometricDeviceFormTarget">{% trans "Edit" %}</a>
</li>
{% if perms.biometric.change_biometricdevices %}
{% if device.is_active %}
<li class="oh-dropdown__item">
<a hx-confirm="{% trans 'Do you want to archive this device?' %}"
hx-post="{% url 'biometric-device-archive' device.id %}?{{pd}}&page={{devices.number}}&view=card"
hx-target="#biometricDeviceList" class="oh-dropdown__link">{% trans "Archive" %}</a>
</li>
{% else %}
<li class="oh-dropdown__item">
<a hx-confirm="{% trans 'Do you want to un-archive this device?' %}"
hx-post="{% url 'biometric-device-archive' device.id %}?{{pd}}&page={{devices.number}}&view=card"
hx-target="#biometricDeviceList" class="oh-dropdown__link">{% trans "Un-Archive" %}</a>
</li>
{% endif %}
{% endif %}
{% if perms.biometric.delete_biometricdevices %}
<li class="oh-dropdown__item">
<a hx-confirm="{% trans 'Do you want to archive this device?' %}"
hx-post="{% url 'biometric-device-archive' device.id %}?{{pd}}&page={{devices.number}}&view=card"
hx-target="#biometricDeviceList" class="oh-dropdown__link">{% trans "Archive" %}</a>
</li>
{% else %}
<li class="oh-dropdown__item">
<a hx-confirm="{% trans 'Do you want to un-archive this device?' %}"
hx-post="{% url 'biometric-device-archive' device.id %}?{{pd}}&page={{devices.number}}&view=card"
hx-target="#biometricDeviceList" class="oh-dropdown__link">{% trans "Un-Archive" %}</a>
<form hx-confirm="{% trans 'Do you want to delete this device?' %}"
hx-post="{% url 'biometric-device-delete' device.id %}?{{pd}}&page={{devices.number}}&view=card"
hx-target="#biometricDeviceList">
{% csrf_token %}
<button class="oh-dropdown__link oh-dropdown__link--danger">
{% trans "Delete" %}
</button>
</form>
</li>
{% endif %}
{% endif %}
{% if perms.biometric.delete_biometricdevices %}
<li class="oh-dropdown__item">
<form hx-confirm="{% trans 'Do you want to delete this device?' %}"
hx-post="{% url 'biometric-device-delete' device.id %}?{{pd}}&page={{devices.number}}&view=card"
hx-target="#biometricDeviceList">
{% csrf_token %}
<button class="oh-dropdown__link oh-dropdown__link--danger">
{% trans "Delete" %}
</button>
</form>
</li>
{% endif %}
</ul>
</ul>
</div>
</div>
</div>
<div class="d-block oh-kanban-card__biometric-actions"
{% if device.machine_type == "anviz" or device.machine_type == "cosec" %} style='margin-top:53px;' {% endif %}>
<a href="#" hx-get="{% url 'biometric-device-test' device.id %}" data-toggle="oh-modal-toggle"
data-target="#BiometricDeviceTestModal" hx-target="#BiometricDeviceTestFormTarget"
class="oh-checkpoint-badge text-success">{% trans "Test" %}
</a>
{% if device.is_scheduler %}
<a hx-confirm="{% trans 'Do you want to unschedule the device attendance fetching?' %}"
hx-post="{% url 'biometric-device-unschedule' device.id %}?{{pd}}&page={{devices.number}}&view=card"
hx-target="#biometricDeviceList" class="oh-checkpoint-badge text-info">{% trans "Unschedule" %}
</a>
{% else %}
<a href="#" class="oh-checkpoint-badge text-info" hx-get="{% url 'biometric-device-schedule' device.id %}"
data-toggle="oh-modal-toggle" data-target="#BiometricDeviceModal"
hx-target="#BiometricDeviceFormTarget">{% trans "Schedule" %}</a>
{% endif %}
{% if device.machine_type == "zk" or device.machine_type == "cosec" %}
<a href="{% url 'biometric-device-employees' device.id %}"
class="oh-checkpoint-badge text-secondary bio-user-list">{% trans "Employee" %}</a>
{% endif %}
</div>
</div>
<div class="d-block oh-kanban-card__biometric-actions" {% if device.machine_type == "anviz" or device.machine_type == "cosec" %} style='margin-top:53px;' {% endif %}>
<a href="#" hx-get="{% url 'biometric-device-test' device.id %}" data-toggle="oh-modal-toggle"
data-target="#BiometricDeviceTestModal" hx-target="#BiometricDeviceTestFormTarget"
class="oh-checkpoint-badge text-success">{% trans "Test" %}
</a>
{% if device.is_scheduler %}
<a hx-confirm="{% trans 'Do you want to unschedule the device attendance fetching?' %}"
hx-post="{% url 'biometric-device-unschedule' device.id %}?{{pd}}&page={{devices.number}}&view=card"
hx-target="#biometricDeviceList" class="oh-checkpoint-badge text-info">{% trans "Unschedule" %}
</a>
{% else %}
<a href="#" class="oh-checkpoint-badge text-info" hx-get="{% url 'biometric-device-schedule' device.id %}"
data-toggle="oh-modal-toggle" data-target="#BiometricDeviceModal"
hx-target="#BiometricDeviceFormTarget">{% trans "Schedule" %}</a>
{% endif %}
{% if device.machine_type == "zk" or device.machine_type == "cosec" %}
<a href="{% url 'biometric-device-employees' device.id %}"
class="oh-checkpoint-badge text-secondary bio-user-list">{% trans "Employee" %}</a>
{% endif %}
</div>
</div>
{% endfor %}
</div>
<div class="oh-pagination" data-pd="{{pd}}">
@@ -174,6 +170,9 @@
$(".bio-user-list").click(function () {
$("#BiometricDeviceTestModal").toggleClass("oh-modal--show");
});
$(".anviz-data-fetch").click(function (e) {
$("#BiometricDeviceTestModal").toggleClass("oh-modal--show");
});
});
</script>
<div class="oh-modal" id="BiometricDeviceTestModal" role="dialog" aria-labelledby="BiometricDeviceTestModal"

View File

@@ -17,6 +17,7 @@ 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 _
@@ -1734,18 +1735,17 @@ def anviz_biometric_device_attendance(device_id):
for attendance in attendance_records["payload"]["list"]:
badge_id = attendance["employee"]["workno"]
punch_code = attendance["checktype"]
date_time_obj = datetime.strptime(
date_time_utc = datetime.strptime(
attendance["checktime"], "%Y-%m-%dT%H:%M:%S%z"
)
target_timezone = pytz.django_timezone(settings.TIME_ZONE)
date_time_obj = date_time_obj.astimezone(target_timezone)
date_time_obj = date_time_utc.astimezone(timezone.get_current_timezone())
employee = Employee.objects.filter(badge_id=badge_id).first()
if employee:
request_data = Request(
user=employee.employee_user_id,
date=date_time_obj.date(),
time=date_time_obj.time(),
datetime=django_timezone.make_aware(date_time_obj),
datetime=date_time_obj,
)
if punch_code in {0, 128}:
try: