
    vgf                         d Z ddlmZ ddl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	 Zedd       Zedd       Zedd       Zedd       Zy
)z
decorator functions for leave
    )messages)HttpResponseHttpResponseRedirect)redirectrender)gettext_lazy)LeaveGeneralSetting   )LeaveAllocationRequestc                       fdS )Nc                        fdS )Nc                      | gi S N )funcargs	decoratorkwargss    $/var/www/horilla/leave/decorators.py<lambda>z,<lambda>.<locals>.<lambda>.<locals>.<lambda>   s    9<<<     r   )r   r   r   s   ``r   r   z<lambda>.<locals>.<lambda>   s
     / r   r   )r   s   `r   r   r      s
      r   Nc                      	 d fd	}|S )Nc                 6   t         j                  j                  |      }| j                  j	                  d      sZ| j                  j
                  |j                  j                  j                  k(  s#| j                  j
                  |j                  k(  r | g|d|i|S t        j                  | t        d             | j                  j                  dd      }d| d}d	}|| j                  j                         v rt        | d
      S t        |      S )zh
        This method is used to check the employee can change a leave allocation request or not
        idz#leave.change_leaveallocationrequestreq_idYou dont have permission.HTTP_REFERER/ <script>window.location.href = "
"</script>HTTP_HX_REQUESTdecorator_404.html)r   objectsgetuserhas_permemployee_getemployee_idemployee_work_inforeporting_manager_idr   info_METAkeysr   r   	requestr   r   r   leave_allocation_requestprevious_urlscriptkeyfunctions	           r   check_permissionz<leave_allocation_change_permission.<locals>.check_permission   s     $:#A#A#E#E#E#P LL!!"GH||(('33FF[[\||((,D,P,PPGDdD6DVDDgq!<=>||''<3L>L',,##%%'#788F##r   r   r   r6   r   r   r7   s   `   r   "leave_allocation_change_permissionr9      s     $2 r   c                      	 d fd	}|S )Nc                    	 t         j                  j                  |      }| j                  j	                  d      sZ| j                  j
                  |j                  j                  j                  k(  s#| j                  j
                  |j                  k(  r | g|d|i|S t        j                  | t        d             | j                  j                  dd      }d| d}d	}|| j                  j                         v rt        | d
      S t        |      S # t         j                   t"        t$        f$ r- t        j&                  | t        d             t)        d      cY S w xY w)zh
        This method is used to check the employee can delete a leave allocation request or not
        r   #leave.delete_leaveallocationrequestr   r   r   r   r    r!   r"   r#   "Leave allocation request not found%/leave/leave-allocation-request-view/r   r$   r%   r&   r'   r(   r)   r*   r+   r   r,   r-   r.   r/   r   r   DoesNotExistOverflowError
ValueErrorerrorr   r0   s	           r   r7   z<leave_allocation_delete_permission.<locals>.check_permission5   s:   	E'='E'E'I'IV'I'T$%%&KL<<,,+77JJ__`<<,,0H0T0TTH$HvHHHMM'1%@#AB"<<++NC@L7~ZPF#Cgll''))g';<<''&33]JO 	ENN7A&J$KLCDD	Es    B"D &A*D 
D AE'&E'r   r   r8   s   `   r   "leave_allocation_delete_permissionrD   3   s     E: r   c                      	 d fd	}|S )Nc                    	 t         j                  j                  |      }| j                  j	                  d      s7| j                  j
                  |j                  j                  j                  k(  r | g|d|i|S t        j                  | t        d             | j                  j                  dd      }d| d}d	}|| j                  j                         v rt        | d
      S t        |      S # t         j                   t"        t$        f$ r- t        j&                  | t        d             t)        d      cY S w xY w)zh
        This method is used to check the employee can reject a leave allocation request or not
        r   r<   r   r   r   r   r    r!   r"   r#   r=   r>   r?   r0   s	           r   r7   z<leave_allocation_reject_permission.<locals>.check_permissionW   s#   	E'='E'E'I'IV'I'T$%%&KL<<,,+77JJ__`  H$HvHHHMM'1%@#AB"<<++NC@L7~ZPF#Cgll''))g';<<''&33]JO 	ENN7A&J$KLCDD	Es    A?C9 A*C9 .
C9 9AEEr   r   r8   s   `   r   "leave_allocation_reject_permissionrG   U   s     E8 r   c                       fd}|S )Nc                 \   t         j                  j                         rBt         j                  j                         j	                         j
                  r | g|i |S t        j                  | t        d             | j                  j                  dd      }d| d}t        |      S )zW
        This function check whether the compensatory leave feature is enabled
        z(Sorry,Compensatory leave is not enabled.r   r   r    r!   )r	   r$   existsallfirstcompensatory_leaver   r,   r-   r.   r%   r   )r1   r   r   r3   r4   r   s        r   r6   z/is_compensatory_leave_enabled.<locals>.functionx   s    
  ''..0#++//1779LL1$1&11gq!KLM||''<3L>LF##r   r   )r   r   r   r6   s   `   r   is_compensatory_leave_enabledrN   v   s    $ Or   r   )__doc__django.contribr   django.httpr   r   django.shortcutsr   r   django.utils.translationr   r-   leave.modelsr	   modelsr   decorator_with_argumentsr9   rD   rG   rN   r   r   r   <module>rW      sz    $ : - 6 , *   :  B  @  r   