
    si                        d dl mZ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 dlmZ d d	lmZ d d
lmZmZmZ d dlmZmZmZmZmZmZmZ d dlm Z m!Z! d dl"m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z)m*Z* d dl+m,Z, ddl-m.Z.m/Z/ ddl0m1Z1 ddl2m3Z3m4Z4 ddl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@ d ZAd ZBd ZC G d de      ZD G d de      ZE G d de      ZF G d  d!e      ZG G d" d#e      ZH G d$ d%e      ZI G d& d'e      ZJ G d( d)e      ZK G d* d+e      ZL G d, d-e      ZM G d. d/e      ZN G d0 d1e      ZO G d2 d3e      ZP G d4 d5e      ZQ G d6 d7e      ZR G d8 d9e      ZS G d: d;e      ZT G d< d=e      ZU G d> d?e      ZVy@)A    )ProtectedErrorQ)Http404)method_decorator)DjangoFilterBackendstatus)PageNumberPagination)IsAuthenticated)Response)APIView)DisciplinaryActionFilterDocumentRequestFilterEmployeeFilter)
ActiontypeDisciplinaryActionEmployeeEmployeeBankDetailsEmployeeTypeEmployeeWorkInformationPolicy)work_info_exportwork_info_import)owner_can_enter)permission_required)get_next_badge_id)DocumentDocumentRequest)notify   )$manager_or_owner_permission_requiredmanager_permission_required)or_condition)groupby_querysetpermission_based_queryset)ActiontypeSerializerDisciplinaryActionSerializerDocumentRequestSerializerDocumentSerializerEmployeeBankDetailsSerializerEmployeeListSerializerEmployeeSelectorSerializerEmployeeSerializerEmployeeTypeSerializer!EmployeeWorkInformationSerializerPolicySerializerc                 8    | j                   j                  |      S N)userhas_perm)requestperms     H/var/www/python-projects/worksol/horilla_api/api_views/employee/views.pypermission_checkr8   5   s    <<  &&    c                 j    	 | j                   j                  |      }|S # | j                  $ r Y y w xY w)Nid)objectsgetDoesNotExist)clspkobjs      r7   object_checkrC   9   s8    kkooo$
 s     22c                     	 | j                   j                  |      j                          y# t        $ r}dt	        |      idfcY d }~S d }~ww xY w)Nr;   )    error  )r=   r>   delete	Exceptionstr)r@   rA   es      r7   object_deleterM   A   sI    &2%%' &Q #%%&s   *- 	AA
A
Ac                       e Zd ZdZegZddZy)EmployeeTypeAPIViewz
    Retrieves employee types.

    Methods:
        get(request, pk=None): Returns a single employee type if pk is provided, otherwise returns all employee types.
    Nc                    |rBt         j                  j                  |      }t        |      }t	        |j
                  d      S t         j                  j                         }t        |d      }t	        |j
                  d      S )Nr;   rF   r   Tmany)r   r=   r>   r.   r   dataall)selfr5   rA   employee_type
serializers        r7   r>   zEmployeeTypeAPIView.getS   sj    (00444;M/>JJOOC88$,,002+ME

44r9   r2   __name__
__module____qualname____doc__r   permission_classesr>    r9   r7   rO   rO   I   s     **5r9   rO   c                   |    e Zd ZdZegZeZegZ	d Z
 e ed            d        Zd Z e ed            d        Zy)	EmployeeAPIViewz0
    Handles CRUD operations for employees.
    c                    |j                   }	 t        j                  j                  ddd      j	                  |      }|j                  d      r t        |      }t        |j                        S |j                  j                         }|j                  |      j                         r t        |      }t        |j                        S |j                   |j                  j"                  k(  r t        |      }t        |j                        S t        dd	it        j$                        S # t        j
                  $ r  t        ddit        j                        cY S w xY w)
Nr<   employee_first_nameemployee_last_namerA   rG   Employee does not existr   employee.view_employeezPermission denied)r3   r   r=   onlyr>   r?   r   r	   HTTP_404_NOT_FOUNDr4   r-   rS   employee_getget_subordinate_employeesfilterexistsrA   r<   HTTP_403_FORBIDDEN)rU   r5   rA   r3   employeerW   subordinatess          r7   r>   zEmployeeAPIView.getf   s6   ||		'',,%$ cRcj	  ==12+H5JJOO,, ((BBD"%,,.+H5JJOO,, ;;$++...+H5JJOO,,)*63L3L
 	
+ $$ 	34V=V=V 	s   1D* *0EEzemployee.add_employeec                    t        |j                        }|j                         r5|j                          t	        |j                  t
        j                        S t	        |j                  t
        j                        S NrS   r   )	r-   rS   is_validsaver   r	   HTTP_201_CREATEDerrorsHTTP_400_BAD_REQUESTrU   r5   rW   s      r7   postzEmployeeAPIView.post   sV    'W\\:
 OOJOOF4K4KLL
))&2M2MNNr9   c                    |j                   }t        j                  j                  |      }||j                  |j                   j                  j                         fv s|j                  d      rrt        ||j                  d      }|j                         r%|j                          t        |j                        S t        |j                  t        j                        S t        ddid      S )	Nrd   employee.change_employeeTrS   partialr   rG   zYou don't have permissionrH   )r3   r   r=   r>   ri   get_reporting_managerr4   r-   rS   rs   rt   r   rv   r	   rw   )rU   r5   rA   r3   rn   rW   s         r7   putzEmployeeAPIView.put   s    ||##''2'.!!7<<#<#<#R#R#TUV]]56+H7<<QUVJ""$!
00J--f6Q6QRR"=>sKKr9   employee.delete_employeec                 r   	 t         j                  j                  |      }|j                          t        t        j                        S # t         j                  $ r  t        ddit        j                        cY S t        $ r0}t        dt        |      it        j                        cY d }~S d }~ww xY w)Nrd   rG   re   r   )r   r=   r>   rI   r?   r   r	   rh   r   rK   HTTP_204_NO_CONTENT)rU   r5   rA   rn   rL   s        r7   rI   zEmployeeAPIView.delete   s    	R''++r+2HOO v99:: $$ 	34V=V=V   	RWc!f-f6P6PQQ	Rs#   0A 0B6>B6%B1+B61B6N)rY   rZ   r[   r\   r   filter_backendsr   filterset_classr   r]   r>   r   r   ry   r   rI   r^   r9   r7   r`   r`   ]   so     ++O$O)*
d )*ABCO DOL )*DEF
; G
;r9   r`   c                       e Zd ZdZegZd Zy)EmployeeListAPIViewzU
    Retrieves a paginated list of employees with optional search functionality.
    c                 Z   |j                   }|j                  j                  d      }t        j                  j                  ddd      }|j                  d      rnd|j                  j                         }|j                         r|j                  ddd      }n&|j                  |j                  j                        }|r(|j                  t        |      t        |      z        }t               }|j                  ||      }t        |d	
      }|j!                  |j"                        S )Nsearchr<   rb   rc   rf   r;   )employee_first_name__icontains)employee_last_name__icontainsTrQ   )r3   query_paramsr>   r   r=   rg   r4   ri   rj   rl   rk   r<   r   r
   paginate_querysetr+   get_paginated_responserS   )	rU   r5   r3   r   employees_querysetsubordinate_qs	paginatorpagerW   s	            r7   r>   zEmployeeListAPIView.get   s   ||%%))(3 &--22')=

 ==12!..HHJN$$&%3%8%8/1E&" &8%>%>$BSBSBVBV%>%W" !3!:!:8&9:" )*	**+=wG+Dt<
//
@@r9   NrX   r^   r9   r7   r   r      s     **!Ar9   r   c                   |    e Zd ZdZegZd Zd
dZ ee	d      d        Z
 ee	d      d        Z ed      d	        Zy)EmployeeBankDetailsAPIViewa?  
    Manage employee bank details with CRUD operations.

    Methods:
        get(request, pk=None):
            - Retrieves bank details for a specific employee if `pk` is provided.
            - Returns a paginated list of all employee bank details if `pk` is not provided.

        post(request):
            - Creates a new bank detail entry for an employee.

        put(request, pk):
            - Updates existing bank details for an employee identified by `pk`.

        delete(request, pk):
            - Deletes bank details for an employee identified by `pk`.
    c                     t         j                  j                         }| j                  j                  }d}t        |||      }|S )Nzbase.view_employeebankdetails)r   r=   rT   r5   r3   r%   )rU   querysetr3   r6   s       r7   get_querysetz'EmployeeBankDetailsAPIView.get_queryset   s=    &..224||  .,T4Br9   Nc                 N   t         j                  j                  |      }|j                  j                  |j
                  |j
                  j                         fv s|j                  j                  d      r t        |      }t        |j                        S t        ddid      S )Nrd   z!employee.view_employeebankdetailsmessageNo permissionrH   r   )r   r=   r>   r3   ri   employee_idr~   r4   r*   r   rS   rU   r5   rA   bank_detailrW   s        r7   r>   zEmployeeBankDetailsAPIView.get  s    )11555<LL%%''''==?
 \\""#FG6{CJJOO,,O4SAAr9   z employee.add_employeebankdetailsc                    t        |j                        }|j                         r5|j                          t	        |j                  t
        j                        S t	        |j                  t
        j                        S rq   )	r*   rS   rs   rt   r   r	   ru   rv   rw   rx   s      r7   ry   zEmployeeBankDetailsAPIView.post  sX     3E
 OOJOOF4K4KLL
))&2M2MNNr9   c                    	 t         j                  j                  |      }t        ||j                        }|j                         r%|j                          t	        |j                        S t	        |j                  t
        j                        S # t         j                  $ r  t	        ddit
        j                        cY S w xY w)Nrd   rG   Bank details do not existr   rr   )r   r=   r>   r?   r   r	   rh   r*   rS   rs   rt   rv   rw   r   s        r7   r   zEmployeeBankDetailsAPIView.put  s    	-5599R9@K 3;W\\R
 OOJOO,,
))&2M2MNN #// 	56v?X?X 	s    B 0CCz#employee.change_employeebankdetailsc                 V   	 t         j                  j                  |      }|j                          t        t        j                        S # t         j                  $ r  t        ddit        j                        cY S t        $ r"}t        dt        |      id      cY d }~S d }~ww xY w)Nrd   rG   r   r   rH   )r   r=   r>   rI   r?   r   r	   rh   rJ   rK   r   )rU   r5   rA   r   Es        r7   rI   z!EmployeeBankDetailsAPIView.delete-  s    	;-5599R9@K  v99:: #// 	56v?X?X   	;Wc!f-c::	;s#   0A 0B(>B(B#B(#B(r2   )rY   rZ   r[   r\   r   r]   r   r>   r!   r   ry   r   r"   rI   r^   r9   r7   r   r      sz    $ **B *?OO *?OO !!FG; H;r9   r   c                       e Zd ZdZegZd Z ed      d        Z ed      d        Z	 e
 ed      d	      d
        Zy)EmployeeWorkInformationAPIViewa  
    Manage employee work information with CRUD operations.

    Methods:
        get(request, pk):
            - Retrieves work information for a specific employee identified by `pk`.

        post(request):
            - Creates a new work information entry for an employee.

        put(request, pk):
            - Updates existing work information for an employee identified by `pk`.

        delete(request, pk):
            - Deletes work information for an employee identified by `pk`.
    c                 6   t         j                  j                  |      }|j                  j                  |j
                  |j                  fv s|j                  j                  d      r"t        |      }t        |j                  d      S t        ddid      S )Nrd   z%employee.view_employeeworkinformationrF   r   r   r   rH   )r   r=   r>   r3   ri   r   reporting_manager_idr4   r/   r   rS   rU   r5   rA   	work_inforW   s        r7   r>   z"EmployeeWorkInformationAPIView.getP  s    +337727>	LL%%%%y'E'EFG\\""#JK:9EJJOOC88O4SAAr9   $employee.add_employeeworkinformationc                    t        |j                        }|j                         r5|j                          t	        |j                  t
        j                        S t	        |j                  t
        j                        S rq   )	r/   rS   rs   rt   r   r	   ru   rv   rw   rx   s      r7   ry   z#EmployeeWorkInformationAPIView.postZ  sV    6GLLI
 OOJOOF4K4KLL
))&2M2MNNr9   'employee.change_employeeworkinformationc                    t         j                  j                  |      }|j                  j                  |j
                  k(  s|j                  j                  d      rrt        ||j                  d      }|j                         r%|j                          t        |j                        S t        |j                  t        j                        S t        ddid      S )	Nrd   r   Tr|   r   r   r   rH   )r   r=   r>   r3   ri   r   r4   r/   rS   rs   rt   r   rv   r	   rw   r   s        r7   r   z"EmployeeWorkInformationAPIView.putb  s    +337727>	LL%%)G)GG||$$%NO:dJ ""$!
00J--f6Q6QRRO4SAAr9   z'employee.delete_employeeworkinformationdispatchnamec                     	 t         j                  j                  |      }|j                          t        t        j                        S # t         j                  $ r t        w xY w)Nrd   r   )	r   r=   r>   r?   r   rI   r   r	   r   )rU   r5   rA   r   s       r7   rI   z%EmployeeWorkInformationAPIView.deleter  s[    	/77;;r;BI 	v99:: '33 	M	s    A A&N)rY   rZ   r[   r\   r   r]   r>   r"   ry   r   r   r   rI   r^   r9   r7   r   r   <  sv    " **B !!GHO IO !!JKB LB EFZ;;r9   r   c                   2    e Zd ZdZegZ ed      d        Zy)EmployeeWorkInfoExportViewz
    Endpoint for exporting employee work information.

    Methods:
        get(request):
            - Exports work information data based on user permissions.
    r   c                     t        |      S r2   )r   rU   r5   s     r7   r>   zEmployeeWorkInfoExportView.get      ((r9   NrY   rZ   r[   r\   r   r]   r"   r>   r^   r9   r7   r   r   ~  +     ** !GH) I)r9   r   c                   2    e Zd ZdZegZ ed      d        Zy)EmployeeWorkInfoImportViewz
    Endpoint for importing employee work information.

    Methods:
        get(request):
            - Handles the importing of work information data based on user permissions.
    r   c                     t        |      S r2   )r   r   s     r7   r>   zEmployeeWorkInfoImportView.get  r   r9   Nr   r^   r9   r7   r   r     r   r9   r   c                   B    e Zd ZdZegZ e ed      d      d        Zy)EmployeeBulkUpdateViewa  
    Endpoint for bulk updating employee and work information.

    Permissions:
        - Requires authentication and "change_employee" permission.

    Methods:
        put(request):
            - Updates multiple employees and their work information.
    r{   r   r   c                 L   |j                   j                  dg       }t        j                  j	                  |      }t
        j                  j	                  |      }|j                   j                  di       }|j                   j                  di       }g d}|D ]&  }|j                  |d        |j                  |d        ( 	  |j                  di |  |j                  di | t        d
did	      S # t        $ r"}	t        dt        |	      id	      cY d }	~	S d }	~	ww xY w)Nidsid__inemployee_id__inemployee_dataemployee_work_info)badge_idrb   rc   	is_activeemailphone%employee_bank_details__account_numberrG   rH   r   r	   successrF   r^   )rS   r>   r   r=   rk   r   popupdaterJ   r   rK   )
rU   r5   employee_ids	employeesr   r   work_info_datafields_to_removefieldrL   s
             r7   r   zEmployeeBulkUpdateView.put  s!   ||''r2$$++<+@	4<<CC% D 
  (("= ))*>C
 & 	,EeT*ud+	,	;I-}-%%%77 9-c::  	;Wc!f-c::	;s   $C8 8	D#DD#D#N)	rY   rZ   r[   r\   r   r]   r   r   r   r^   r9   r7   r   r     s3    	 **)*DEJW; X;r9   r   c                   0    e Zd ZeZegZddZd Zd Z	d Z
y)ActiontypeViewNc                 h   |rIt        t        |      }|t        ddid      S | j                  |      }t        |j                  d      S t        j
                  j                         }t               }|j                  ||      }| j                  |d      }|j                  |j                        S )NrG   Actiontype not found  r   rF   TrQ   )
rC   r   r   serializer_classrS   r=   rT   r
   r   r   )rU   r5   rA   action_typerW   action_types	paginaterr   s           r7   r>   zActiontypeView.get  s    &z26K"*@ A#NN..{;JJOOC88!))--/(*	**<A**4d*;
//
@@r9   c                    t        |d      du rt        ddid      S | j                  |j                        }|j	                         r'|j                          t        |j                  d      S t        |j                  d	      S )
Nzemployee.add_actiontypeFrG   r     r   rr      rH   )r8   r   r   rS   rs   rt   rv   rx   s      r7   ry   zActiontypeView.post  su    G%>?5HWo6sCC***=
 OOJOOC88
))#66r9   c                 T   t        |d      du rt        ddid      S t        t        |      }|t        ddid      S | j	                  ||j
                  	      }|j                         r'|j                          t        |j
                  d
      S t        |j                  d      S )Nzemployee.change_actiontypeFrG   r   r   r   r   r   rr   rF   rH   )	r8   r   rC   r   r   rS   rs   rt   rv   )rU   r5   rA   r   rW   s        r7   r   zActiontypeView.put  s    G%ABeKWo6sCC":r2W&<=cJJ**;W\\*J
 OOJOOC88
))#66r9   c                     t        |d      du rt        ddid      S t        t        |      }|t        ddid      S t	        t        |      \  }}t        ||      S )	Nzemployee.delete_actiontypeFrG   r   r   r   r   r   )r8   r   rC   r   rM   )rU   r5   rA   r   responsestatus_codes         r7   rI   zActiontypeView.delete  sg    G%ABeKWo6sCC":r2W&<=cJJ -j" =+55r9   r2   )rY   rZ   r[   r&   r   r   r]   r>   ry   r   rI   r^   r9   r7   r   r     s&    +)*A7
76r9   r   c                   :    e Zd ZdZeZegZd ZddZ	d Z
d Zd Zy)	DisciplinaryActionAPIViewa  
    Endpoint for managing disciplinary actions.

    Permissions:
        - Requires authentication.

    Methods:
        get(request, pk=None):
            - Retrieves a specific disciplinary action by `pk` or lists all disciplinary actions with optional filtering.

        post(request):
            - Creates a new disciplinary action.

        put(request, pk):
            - Updates an existing disciplinary action by `pk`.

        delete(request, pk):
            - Deletes a specific disciplinary action by `pk`.
    c                 ~    	 t         j                  j                  |      S # t         j                  $ r t        w xY wNrd   )r   r=   r>   r?   r   rU   rA   s     r7   
get_objectz$DisciplinaryActionAPIView.get_object  s;    	%--11R188!.. 	M	   " <Nc                 2   |r|j                   j                  }| j                  |      }|j                         |j                  j                         z  rdnd}||j                  k(  s|s|j                   j                  d      r"t        |      }t        |j                  d      S t        ddid      S |j                   j                  }t        j                  j                  |	      j                         }|j                         }|j                   j                  d      rt        j                  j                         }nh|rFt        j                  j                  |
      }	t        j                  j                  |      }
|	|
z  }n t        j                  j                  |      }t               }|}| j!                  |j"                  |      j$                  }|j'                  ||      }t        |d      }|j)                  |j                        S )NTFz employee.view_disciplinaryactionrF   r   rG   r   rH   r   r   )r   r   rQ   )r3   ri   r   rj   r   rT   r4   r'   r   rS   r   r=   rk   rl   r   r
   r   GETqsr   r   )rU   r5   rA   rn   disciplinary_action
is_managerrW   ro   r   queryset_subordinatesqueryset_employeer   disciplinary_actions#disciplinary_action_filter_querysetr   s                  r7   r>   zDisciplinaryActionAPIView.get  s   ||00H"&//""5 557%115578  	  0<<<<<(()KL9:MN

<<Wo6sCC||00H088??%- @ fh  $==?L||$$%GH-5599;(:(B(B(I(I$0 )J )% %7$>$>$E$E ( %F %! 13DD-55<<<R,.I#+ 262F2F&: 3G 3b 0 ..3WD 6dFJ33JOODDr9   c                 <   t        |d      du rt        ddid      S t        |j                        }|j	                         r5|j                          t        |j                  t        j                        S t        |j                  t        j                        S Nemployee.add_disciplinaryactionFrG   r   r   r   rr   )
r8   r   r'   rS   rs   rt   r	   ru   rv   rw   rx   s      r7   ry   zDisciplinaryActionAPIView.postI  sx    G%FG5PWo6sCC1w||D
 OOJOOF4K4KLL
))&2M2MNNr9   c                 @   t        |d      du rt        ddid      S | j                  |      }t        ||j                        }|j                         r%|j                          t        |j                        S t        |j                  t        j                        S r   )
r8   r   r   r'   rS   rs   rt   rv   r	   rw   )rU   r5   rA   r   rW   s        r7   r   zDisciplinaryActionAPIView.putR  s    G%FG5PWo6sCC"oob11gll

  OOJOO,,
))&2M2MNNr9   c                     t        |d      du rt        ddid      S | j                  |      }|j                          t        t        j
                        S )Nr   FrG   r   r   r   )r8   r   r   rI   r	   r   )rU   r5   rA   r   s       r7   rI   z DisciplinaryActionAPIView.delete^  sP    G%FG5PWo6sCC"oob1""$v99::r9   r2   )rY   rZ   r[   r\   r   r   r   r]   r   r>   ry   r   rI   r^   r9   r7   r   r     s4    ( /O)*/EbO
O;r9   r   c                   6    e Zd ZdZegZd ZddZd Zd Z	d Z
y)	PolicyAPIViewa  
    Endpoint for managing policies.

    Permissions:
        - Requires authentication.

    Methods:
        get(request, pk=None):
            - Retrieves a specific policy by `pk` or lists all policies with optional search functionality.

        post(request):
            - Creates a new policy.

        put(request, pk):
            - Updates an existing policy by `pk`.

        delete(request, pk):
            - Deletes a specific policy by `pk`.
    c                 ~    	 t         j                  j                  |      S # t         j                  $ r t        w xY wr   )r   r=   r>   r?   r   r   s     r7   r   zPolicyAPIView.get_object}  s9    	>>%%%,,"" 	M	r   Nc                    |r1| j                  |      }t        |      }t        |j                        S |j                  j                  dd       }|r!t        j                  j                  |      }nt        j                  j                         }t        |d      }t               }|j                  ||      }t        |d      }|j                  |j                        S )Nr   )title__icontainsTrQ   )r   r0   r   rS   r   r>   r   r=   rk   rT   r
   r   r   )	rU   r5   rA   policyrW   r   policiesr   r   s	            r7   r>   zPolicyAPIView.get  s    __R(F)&1JJOO,,[[__Xt4F!>>00&0I!>>--/)(>J,.I..xAD)$T:J33JOODDr9   c                    t        |d      du rt        ddid      S t        |j                        }|j	                         r'|j                          t        |j                  d      S t        |j                  d	      S )
Nzemployee.add_policyFrG   r   r   r   rr   r   rH   )r8   r   r0   rS   rs   rt   rv   rx   s      r7   ry   zPolicyAPIView.post  sl    G%:;uDWo6sCC%7<<8
 OOJOOC88
))#66r9   c                 $   t        |d      du rt        ddid      S | j                  |      }t        ||j                        }|j                         r%|j                          t        |j                        S t        |j                  d      S )	Nzemployee.change_policyFrG   r   r   r   rr   rH   )r8   r   r   r0   rS   rs   rt   rv   )rU   r5   rA   r   rW   s        r7   r   zPolicyAPIView.put  sz    G%=>%GWo6sCC$%f7<<@
 OOJOO,,
))#66r9   c                     t        |d      du rt        ddid      S | j                  |      }|j                          t        d      S )Nzemployee.delete_policyFrG   r   r   r      )r8   r   r   rI   )rU   r5   rA   r   s       r7   rI   zPolicyAPIView.delete  sF    G%=>%GWo6sCC$s##r9   r2   )rY   rZ   r[   r\   r   r]   r   r>   ry   r   rI   r^   r9   r7   r   r   f  s,    ( **E"77$r9   r   c                       e Zd ZdZegZd ZddZ ed      d        Z	 ed      d        Z
 e ed	            d
        Zy)DocumentRequestAPIViewaT  
    Endpoint for managing document requests.

    Permissions:
        - Requires authentication.
        - Specific actions require manager-level permissions.

    Methods:
        get(request, pk=None):
            - Retrieves a specific document request by `pk` or lists all document requests with pagination.

        post(request):
            - Creates a new document request and notifies relevant employees.

        put(request, pk):
            - Updates an existing document request by `pk`.

        delete(request, pk):
            - Deletes a specific document request by `pk`.
    c                 ~    	 t         j                  j                  |      S # t         j                  $ r t        w xY wr   )r   r=   r>   r?   r   r   s     r7   r   z!DocumentRequestAPIView.get_object  s;    	"**..".55++ 	M	r   Nc                 ,   |r1| j                  |      }t        |      }t        |j                        S t        j
                  j                         }t               }|j                  ||      }t        |d      }|j                  |j                        S )NTrQ   )
r   r(   r   rS   r   r=   rT   r
   r   r   )rU   r5   rA   document_requestrW   document_requests
paginationr   s           r7   r>   zDocumentRequestAPIView.get  s    #r223CDJJOO,, / 7 7 ; ; =-/J//0A7KD24dCJ44Z__EEr9   z&horilla_documents.add_documentrequestsc                    t        |j                        }|j                         r|j                         }	 |j                  j                         D cg c]  }|j                   }}t        j                  |j                  j                  ||j                  j                   dd|j                  j                   d|j                  j                   d|j                  j                   d|j                  j                   ddd	d
|j                   
       t        |j                  t        j                        S t        |j                  t        j                         S c c}w #  Y SxY w)Nrr   z requested a document.u   طلب u    مستنداً.z hat ein Dokument angefordert.u    solicitó un documento.u    a demandé un document.z/employee/employee-profilechatbox-ellipsesz/api/employee/document-request/		recipientverbverb_arverb_deverb_esverb_frredirecticonapi_redirectr   )r(   rS   rs   rt   r   rT   employee_user_idr   sendr3   ri   r<   r   r	   ru   rv   rw   )rU   r5   rW   rB   r3   r   s         r7   ry   zDocumentRequestAPIView.post  s5   .GLLA
 //#C?B?R?R?TUtT22U	ULL--'#LL5566LM%gll&?&?%@@PQ&||8899WX&||8899QR&||8899QR9+#B366(!K JOOF4K4KLL
))&2M2MNN# Vs   E- E((B6E- (E- -E1z)horilla_documents.change_documentrequestsc                    | j                  |      }t        ||j                        }|j                         r%|j	                          t        |j                        S t        |j                  t        j                        S rq   )	r   r(   rS   rs   rt   r   rv   r	   rw   )rU   r5   rA   r  rW   s        r7   r   zDocumentRequestAPIView.put  s`    ??2../?gllS
 OOJOO,,
))&2M2MNNr9   r   c                 x    | j                  |      }|j                          t        t        j                        S Nr   r   rI   r   r	   r   )rU   r5   rA   r  s       r7   rI   zDocumentRequestAPIView.delete  s.    ??2.!v99::r9   r2   )rY   rZ   r[   r\   r   r]   r   r>   r"   ry   r   r   r   rI   r^   r9   r7   r  r    sx    * **
F !!IJO KO0 !!LMO NO )*DEF; G;r9   r  c                       e Zd ZeZegZd Zd
dZ e	e
d      d        Z e ede            d        Z e ede            d	        Zy)DocumentAPIViewc                 ~    	 t         j                  j                  |      S # t         j                  $ r t        w xY wr   )r   r=   r>   r?   r   r   s     r7   r   zDocumentAPIView.get_object  s;    	##''2'..$$ 	M	r   Nc                 z   |r1| j                  |      }t        |      }t        |j                        S t        j
                  j                         }| j                  |j                  |      j                  }t               }|j                  ||      }t        |d      }|j                  |j                        S )Nr   TrQ   )r   r)   r   rS   r   r=   rT   r   r   r   r
   r   r   )	rU   r5   rA   documentrW   	documentsdocument_requests_filteredr   r   s	            r7   r>   zDocumentAPIView.get  s    r*H+H5JJOO,, ((,,.I)-)=)=i *> *b ' -.I../I7SD+Dt<J33JOODDr9   horilla_documents.add_documentc                    t        |j                        }|j                         r+|j                          	 t	        j
                  |j                  j                  |j                  j                  j                         j                  |j                  j                   dd|j                  j                   d|j                  j                   d|j                  j                   d|j                  j                   dd|j                  j                  j                   d	d
d
       t        |j                  t        j                        S t        |j                  t        j                        S #  Y NxY w)Nrr   z uploaded a documentu   قام u    بتحميل مستندz hat ein Dokument hochgeladenu    subió un documentou    a téléchargé un documentz/employee/employee-view//r  z/api/employee/documents/r  r   )r)   rS   rs   rt   r   r  r3   ri   r~   r  r<   r   r	   ru   rv   rw   rx   s      r7   ry   zDocumentAPIView.post  s2    (W\\:
 OOLL--%ll77MMO``#LL5566JK%gll&?&?%@@XY&||8899VW&||8899MN&||8899UV78Q8Q8T8T7UUVW+#; JOOF4K4KLL
))&2M2MNNs   C5E8 8E<z!horilla_documents.change_documentc                    | j                  |      }t        ||j                        }|j                         r%|j	                          t        |j                        S t        |j                  t        j                        S rq   )	r   r)   rS   rs   rt   r   rv   r	   rw   )rU   r5   rA   r   rW   s        r7   r   zDocumentAPIView.put5  s^    ??2&'w||D
 OOJOO,,
))&2M2MNNr9   z!horilla_documents.delete_documentc                 x    | j                  |      }|j                          t        t        j                        S r  r  )rU   r5   rA   r   s       r7   rI   zDocumentAPIView.delete>  s+    ??2&v99::r9   r2   )rY   rZ   r[   r   r   r   r]   r   r>   r!   r   ry   r   r   r   r   rI   r^   r9   r7   r  r    s    +O)*E *9OO, o&I8TUO VO o&I8TU; V;r9   r  c                   .    e Zd ZegZ ed      d        Zy) DocumentRequestApproveRejectViewr#  c                     t         j                  j                  |      j                         }||_        |j                          t        ddid      S )Nr;   r	   r   rF   r   )r   r=   rk   firstr	   rt   r   )rU   r5   r<   r	   r   s        r7   ry   z%DocumentRequestApproveRejectView.postH  sF    ##**b*1779 9-c::r9   N)rY   rZ   r[   r   r]   r"   ry   r^   r9   r7   r)  r)  E  s$    )* !AB; C;r9   r)  c                   .    e Zd ZegZ ed      d        Zy) DocumentBulkApproveRejectAPIViewr#  c                    |j                   j                  dd       }|j                   j                  dd       }d}|rt        j                  j	                  |      }g }|D ]d  }|j
                  s!d}|j                  |j                  dd       0|j                  |j                  dd	       ||_        |j                          f t        |
      S )Nr   r	   rF   r   rH   zNo documents)r<   rG   r   )r<   r	   r   )rS   r>   r   r=   rk   r   appendr<   r	   rt   r   )rU   r5   r   r	   r   r!  r   r   s           r7   r   z$DocumentBulkApproveRejectAPIView.putS  s    llud+!!(D1 ((//s/;IH%  (("%KOO8;;$PQx{{i HI"(  55r9   N)rY   rZ   r[   r   r]   r"   r   r^   r9   r7   r-  r-  P  s$    )* !AB6 C6r9   r-  c                   :    e Zd ZegZ e ed            d        Zy)EmployeeBulkArchiveViewr   c                 R   |j                   j                  d      }g }|D ]y  }t        j                  j                  |      }||_        ||j
                  _        |j                         du r|j                          |j                  t        |      dd       { t        |d      S )Nr   r;   Fz'Related model found for this employee. rn   rG   rF   r   )rS   r>   r   r=   r   r  get_archive_conditionrt   r/  rK   r   )rU   r5   r   r   rG   r   rn   s          r7   ry   zEmployeeBulkArchiveView.postj  s    llu% 	K''++{+;H!*H2;H%%/--/58LL #HF	 c**r9   NrY   rZ   r[   r   r]   r   r   ry   r^   r9   r7   r1  r1  g  s*    )*)*DEF+ G+r9   r1  c                   :    e Zd ZegZ e ed            d        Zy)EmployeeArchiveViewr   c                    t         j                  j                  |      }||_        ||j                  _        d }|j                         du r|j                          nt        |      |j                         d}t        |d      S )Nr;   Fr3  rF   r   )	r   r=   r>   r   r  r4  rt   rK   r   )rU   r5   r<   r   rn   r   s         r7   ry   zEmployeeArchiveView.post  s{    ##''2'.&.7!!+))+u4MMO  M!779H --r9   Nr5  r^   r9   r7   r7  r7  }  s*    )*)*DEF. G.r9   r7  c                       e Zd ZegZd Zy)EmployeeSelectorViewc                 \   |j                   j                  }t        j                  j	                  |j                         }t
        j                  j	                  |      j                         }|r@t        j                  j	                  t        |j                        t        |      z        }|j                   j                  d      rt        j                  j                         }t               }|j                  ||      }t        |d      }|j                  |j                        S )N)r  r   rd   (employee_work_info__reporting_manager_idrf   TrQ   )r3   ri   r   r=   rk   r   rl   r   rA   r4   rT   r
   r   r,   r   rS   )rU   r5   rn   r   r   r   r   rW   s           r7   r>   zEmployeeSelectorView.get  s    <<,,$$++W\\+J	,44;;!) < 

&( 	  ((//X[[!Ax$XXI <<  !9: ((,,.I(*	**9g>/4@
//
@@r9   NrY   rZ   r[   r   r]   r>   r^   r9   r7   r:  r:    s    )*Ar9   r:  c                       e Zd ZegZd Zy)ReportingManagerCheckc                     t         j                  j                  |j                  j                        rt        d      S t        d      S )Nr<  rF   r   r   )r   r=   rk   r3   ri   r   r   s     r7   r>   zReportingManagerCheck.get  s@    ""5<\\5N5N # 
 3''s##r9   Nr>  r^   r9   r7   r@  r@    s    )*$r9   r@  N)Wdjango.db.modelsr   r   django.httpr   django.utils.decoratorsr   django_filters.rest_frameworkr   rest_frameworkr	   rest_framework.paginationr
   rest_framework.permissionsr   rest_framework.responser   rest_framework.viewsr   employee.filtersr   r   r   employee.modelsr   r   r   r   r   r   r   employee.viewsr   r   horilla.decoratorsr   *horilla_api.api_decorators.base.decoratorsr   (horilla_api.api_methods.employee.methodsr   horilla_documents.modelsr   r   notifications.signalsr   api_decorators.base.decoratorsr!   r"   "api_decorators.employee.decoratorsr#   api_methods.base.methodsr$   r%   $api_serializers.employee.serializersr&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r8   rC   rM   rO   r`   r   r   r   r   r   r   r   r   r   r  r  r)  r-  r1  r7  r:  r@  r^   r9   r7   <module>rW     sy   .  4 = ! : 6 , ( 
   > . J F > ( ? S   '&5' 5(\;g \;~(A' (AVR; R;j?;W ?;D) ) ) ) );W );X-6W -6`i; i;XG$G G$TP;W P;f?;g ?;D;w ;6w 6.+g +,.' .&A7 A0$G $r9   