
    vg)                         d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z ddlmZ ddlmZ dd	lmZ d
 Z G d de      Z G d dej(                        Z G d dej(                        Zy)zm
This module contains Django models for managing biometric devices
and employee attendance within a company.
    N)ValidationError)MaxValueValidator)models)gettext_lazy)Company)Employee)HorillaModelc                    t        |       dkD  rt        t        d            	 | j                  d      \  }}t	        |      }t	        |      }t        t        |            dkD  s|t        d      vrt        t        d            |dk(  r|dk(  rt        t        d            y	y	# t        $ r}t        t        d            |d	}~ww xY w)
zM
    this method is used to validate the format of duration like fields.
       z)Invalid format, it should be HH:MM format:   <   zInvalid timer   z#Both hour and minute cannot be zeroN)lenr   _splitintstrrange
ValueError)valuehourminuteerrors       $/var/www/horilla/biometric/models.pyvalidate_schedule_time_formatr      s     5zA~a KLMM	Y{{3'f4yVs4y>AuRy!8!!N"344191!!$I"JKK %9 Ya KLMSXXYs   B B& &	C	/CC	c                       e Zd ZdZd ed      fd ed      fd ed      fgZ ej                  ej                  dd	
      Z
 ej                  d      Z ej                  ded      Z ej                  dddd      Z ej                  dd      Z ej                  dddd      Z ej                  dddd      Z ej                  ddd      Z ej                  ddd      Z ej                  ddd      Z ej                  ddd      Z ej                  ddd      Z ej                  ddd      Z ej                  ddd      Z ej4                  d	      Z ej4                  d	      Z ej                  dddeg      Z ej>                  dd      Z  ejB                  dd      Z" ejF                  e$dd	ejJ                        Z& ejN                         Z(d Z) fdZ* G d d      Z+ xZ,S ) BiometricDevicesai  
    Model: BiometricDevices

    Represents a biometric device used for attendance tracking within a
    company. Each device can be of different types such as ZKTeco Biometric,
    Anviz Biometric, or Matrix COSEC Biometric.The model includes fields for
    device details, authentication credentials, scheduling information, and
    company association.
    zkzZKTeco BiometricanvizzAnviz BiometriccoseczMatrix COSEC BiometricTFdefaultprimary_keyeditabled   
max_length   )r'   choicesnull    )r'   r*   blankr"   r*   r-   0)r'   r*   r-      i  )r"   z00:00
   )r*   r"   r'   
validators)r*   r$   	on_deletec                 8    | j                    d| j                   S Nz - )namemachine_typeselfs    r   __str__zBiometricDevices.__str__W   s    ))C 1 1233    c                    t        
|   |i | | j                  dv rD| j                  st	        dt        d      i      | j                  st	        dt        d      i      | j                  dk(  r8| j                  st	        dt        d      i      	 t        | j                         | j                  d
k(  rD| j                  st	        dt        d      i      | j                  st	        dt        d      i      | j                  dk(  rz| j                  st	        dt        d      i      | j                  st	        dt        d      i      | j                  st	        dt        d      i      | j                  st	        dt        d      i      | j                  r| j                  r| j                  rddd| j                  dd| j                  | j                  dd}ddd d!d!d"d}	 t!        j"                  | j                  |d#$      }|j$                  d%k7  rt	        d&|j$                   h      |j'                         }||k(  rt	        dt        d'      i      |d(   }|d   }|d)   }|| _        || _        y y y y y # t        $ r t	        dt        d	      i      w xY w# t,        $ r}	t	        dt        d*      i      |	d }	~	ww xY w)+N)r   r    
machine_ipzcThe Machine IP is required for ZKTeco Biometric                            & Matrix COSEC Biometricportz,The Port No is required for ZKTeco Biometricr   zk_passwordz4The password is required for ZKTeco Biometric DevicezKThe password must be an integer (numeric) value for ZKTeco Biometric Devicer    cosec_usernamez3The username is required for Matrix COSEC Biometricz3The password is required for Matrix COSEC Biometricr   anviz_request_idz7The Request ID required for the Anviz Biometric Device.api_urlz/The API Url required for Anviz Biometric Deviceapi_keyz/The API Key required for Anviz Biometric Device
api_secretz5The API Secret is required for Anviz Biometric Devicezauthorize.tokentokenz1.0z2022-10-21T07:39:07+00:00)	nameSpace
nameActionversion	requestId	timestamp)rC   rD   )headerpayloadSystem	Exception)rF   r6   
AUTH_ERROR)typemessager1   )jsontimeoutr0   z!API call failed with status code zmAuthentication failed. Please check your API Url                                    , API Key and API Secret.rL   expiresziAuthentication failed. Please check your API Url , API Key                                and API Secret.)supercleanr7   r=   r   r   r>   r?   r   r   r@   cosec_passwordrA   rB   rC   rD   requestspoststatus_coderR   	api_tokenapi_expiresrN   )r9   argskwargsrL   r   responseapi_responser[   r\   exc	__class__s             r   rV   zBiometricDevices.cleanZ   sW   t&v&/??%$a6'  99%QMNO  $##%%qR( 	D$$% '&&%(!Q+  &&%(!Q+  '((%*AU-  <<%"S TU  <<%"S TU  ??%$aS'  $$$// &7&-#(%)%:%:%@ ,0<<tW	 -5kJ(4N#'}}$ " H
  ++s2-@AUAU@VWX  $,==?L#u,- )1%?,"  +95G ' 0I"))"4K%.DN'2D$S ;J$3 (5  %%qi( z ! )%q!1( s%   J 1BJ+  J(+	K4KKc                   0    e Zd ZdZ ed      Z ed      Zy)BiometricDevices.Meta6
        Meta class to add additional options
        zBiometric DevicezBiometric DevicesN__name__
__module____qualname____doc__r   verbose_nameverbose_name_plural r;   r   Metard      s     	 +, 34r;   rn   )-rg   rh   ri   rj   r   BIO_DEVICE_TYPEr   	UUIDFielduuiduuid4id	CharFieldr6   r7   r=   IntegerFieldr>   r?   r@   rW   rA   rB   rC   rD   r[   r\   BooleanFieldis_liveis_schedulerr   scheduler_duration	DateFieldlast_fetch_date	TimeFieldlast_fetch_time
ForeignKeyr   PROTECT
company_idManagerobjectsr:   rV   rn   __classcell__)rb   s   @r   r   r   %   s5    
q#$%	!%&'	!,-.O
 
		$**$	OB6s+D#6##L
 "!!Rd$PRSJ6D5D"&""cDRUVK%V%%4tUWXN%V%%4tLN'v''3TNf#DEGf#DEG!!!St4HJ   Cd$GI"&""cDIK!f!!%0G&6&&u5L)))12	 'f&&D=O&f&&D=O"""dUfnnJ fnnG4@D5 5r;   r   c                      e Zd ZdZ ej
                  ej                  dd      Z ej                  dd      Z
 ej                  dd ed      g      Z ej                  d	      Z ej                  eej"                  
      Z ej                  eej"                  dd      Z ej*                         Zd Z G d d      Zy)BiometricEmployeesz
    Model: BiometricEmployees

    Description:
    Represents the association between employees and biometric devices for
    attendance tracking within a company.Each entry in this model maps an
    employee to a specific biometric device.
    TFr!   r.   i)r*   r-   r2   r%   r&   )r3   r3   r*   r-   c                 8    | j                    d| j                   S r5   )employee_iduser_idr8   s    r   r:   zBiometricEmployees.__str__   s    ""#3t||n55r;   c                   0    e Zd ZdZ ed      Z ed      Zy)BiometricEmployees.Metare   zEmployee in Biometric DevicezEmployees in Biometric DeviceNrf   rm   r;   r   rn   r      s     	 78 ?@r;   rn   N)rg   rh   ri   rj   r   rp   rq   rr   rs   ru   uidr   ref_user_idrt   r   r~   r   CASCADEr   r   	device_idr   r   r:   rn   rm   r;   r   r   r      s     
		$**$	OB
&

4t
4C%&%%+<X+F*GK f#.G#&##HGK!!!FNNTI fnnG6A Ar;   r   c                      e Zd ZdZ ej
                  ej                  dd      Z ej                  dd      Z
 ej                  dd      Z ej                  eej                  dd      Z ej                          Zd Zy	)
COSECAttendanceArgumentsa  
    Model: COSECAttendanceArguments

    Description:
    Represents arguments related to attendance fetching for COSEC biometric
    devices within a company.This model stores information such as the last
    fetched roll-over count and sequence number for COSEC devices.
    TFr!   r%   )r'   r*   r   c                 R    | j                    d| j                   d| j                   S r5   )r   last_fetch_roll_ovr_countlast_fetch_seq_numberr8   s    r   r:   z COSECAttendanceArguments.__str__  s,    ..!T%C%C$DCHbHbGcddr;   N)rg   rh   ri   rj   r   rp   rq   rr   rs   rt   r   r   r~   r   r   r   r   r   r:   rm   r;   r   r   r     s     
		$**$	OB 0 0 0Cd K,F,,$G!!!FNNTI fnnGer;   r   )rj   rq   rX   django.core.exceptionsr   django.core.validatorsr   	django.dbr   django.utils.translationr   r   base.modelsr   employee.modelsr   horilla.modelsr	   r   r   Modelr   r   rm   r;   r   <module>r      sa   
   2 4  6  $ 'Y$}5| }5@A ADev|| er;   