
    vg	                     B    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 Z
y)z*Module for handling attendance error data.    N)HttpResponse)DYNAMIC_URL_PATTERNSremove_dynamic_urlc           
        
 g }i dg dg dg dg dg dg dg dg d	g d
g dg dg dg dg dg dg dg g g g g g g g g d}| D ]D  }|j                         D ]/  \  }}||v r|j                  ||          |j                  d       1 F |j                         D cg c]  \  }}t        d |D              s| }}}|D ]  }||=  t        j                  ||j                               }t        d      dd<   |j                  d       
fd}ddlm	}m
}	 dt        j                          
|	j                   |
|
              t        j                  
       d!
 

S c c}}w )"a  
    Reorganize a list of error dictionaries into a structured error data dictionary
    and remove keys with all None values.

    Parameters:
        error_list (list of dict): A list of dictionaries containing error details.

    Returns:
        dict: A structured dictionary where keys represent error types and values are lists
              of error details for each type.
    zBadge IDShiftz	Work typezAttendance datezCheck-in datezCheck-inzCheck-out datez	Check-outzWorked hourzMinimum hourzBadge ID ErrorzShift ErrorzWork Type ErrorzCheck-in Validation ErrorzCheck-out Validation ErrorzAttendance Errorz Attendance Date Validation Error)zCheck-in ErrorzCheck-out ErrorzWorked Hours ErrorzMinimum Hour ErrorzAttendance Date ErrorCheck-out Date Errorr	   zOther ErrorsNc              3   $   K   | ]  }|d u  
 y wN ).0vs     =/var/www/horilla/attendance/views/handle_attendance_errors.py	<genexpr>z+handle_attendance_errors.<locals>.<genexpr><   s     7QaT	7Qs   )columnszapplication/ms-excel)content_typez'attachment; filename="ImportError.xlsx"zContent-DispositionF)indexc                     t               S r   r   )request	path_inforesponses    r   get_error_sheetz1handle_attendance_errors.<locals>.get_error_sheetF   s    9%    r   )pathurlpatternszerror-sheet-)namezattendance/)itemsappendallpd	DataFramekeysr   to_excelattendance.urlsr   r   uuiduuid4r   )
error_listkeys_to_remove
error_dataitemkeyvalue
data_framer   r   r   r   r   s             @@r   handle_attendance_errorsr.      s0    NB 	R 	2	
 	 	B 	" 	R 	r 	 	" 	r 	2 	$R 	%b  	B!" 	+B#$   !# " "3J6  #$**, 	#JCd{T#Y'T"		## )..0UC7Q57Q4QN   sOj*//2CDJ)?@H&OH"#. 2 tzz|n-ItIYGH	*i[)I-s   !E1<E1)__doc__r%   pandasr    django.httpr   horilla.horilla_settingsr   horilla.methodsr   r.   r   r   r   <module>r4      s    0   $ 9 .Er   