
    sip2                        d 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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 ddlmZ ddlmZ ddlmZmZmZm Z 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,  eed       G d de"             Z- eed       G d de             Z. eed       G d de!             Z/ eed       G d de.             Z0 eed       G d de.             Z1 eed       G d  d!e              Z2 eed       G d" d#e             Z3 eed       G d$ d%e3             Z4 eed       G d& d'e             Z5 ejl                  d( e$jn                         d)d*g+       y),z
Leave allocation request page
    N)Any)messages)HttpResponse)render)reversereverse_lazy)method_decorator)gettext_lazy)choosesubordinatesfiltersubordinatesis_reportingmanager)EmployeeProfileView)Employee)login_required)HorillaDetailedViewHorillaFormViewHorillaListViewHorillaNavViewHorillaTabViewTemplateView)IndividualLeaveTab)LeaveAllocationRequestFilter)LeaveAllocationRequestForm)LeaveAllocationRequest)notifydispatch)namec                       e Zd ZdZdZy)LeaveAllocationRequestViewz1
    for leave allocation  request page view
    z:cbv/leave_allocation_request/leave_allocation_request.htmlN)__name__
__module____qualname____doc__template_name     F/var/www/python-projects/worksol/leave/cbv/leave_allocation_request.pyr   r   "   s     QMr&   r   c            	           e Zd ZdZeZeZdeddf fdZ	 e
d      ddf e
d	      d
f e
d      df e
d      df e
d      df e
d      df e
d      dfgZdddZg dZdZd e
d      dfd e
d      dfd e
d       d!fgZd"Z xZS )#LeaveAllocationRequestListz
    List view of the page
    kwargsreturnNc                 R    t        |   di | t        d      | _        d| _        y )Nleave-allocation-request-filterzview-containerr%   super__init__r   
search_urlview_idselfr*   	__class__s     r'   r0   z#LeaveAllocationRequestList.__init__4   s'    "6"!"CD'r&   r   employee_idemployee_id__get_avatar
Leave Typeleave_type_idRequested Daysrequested_days
Created Bycreated_by__employee_getStatus
get_statusDescriptiondescriptionCommentcommentzI
                    style="width:180px !important;"
                    )actionrA   ))r   employee_id__get_full_name)r8   leave_type_id__name)r:   r;   )r<   created_by__get_full_name)r>   r?   
action_colzrejected--dotRejectedz
            onclick="
            $('#applyFilter').closest('form').find('[name=status]').val('rejected');
            $('#applyFilter').click();
            "

            zrequested--dot	Requestedz
            onclick="
            $('#applyFilter').closest('form').find('[name=status]').val('requested');
            $('#applyFilter').click();
            "

            zapproved--dotApprovedz
            onclick="
            $('#applyFilter').closest('form').find('[name=status]').val('approved');
            $('#applyFilter').click();
            "

            zstatus-{status})r    r!   r"   r#   r   modelr   filter_classr   r0   _columnsheader_attrssortby_mappingoption_methodrow_status_indicationsrow_status_class__classcell__r5   s   @r'   r)   r)   +   s     #E/L( ( ( 
:'@A	
</*	
	./	
<45	
8l#	
=	=)	
9y!G	LN !M jM
	
 kN
	
 jM
	
/"H )r&   r)   c                   ,     e Zd ZdZdeddf fdZ xZS )LeaveAllocationRequestTabz
    Tab View
    r*   r+   Nc                 F   t        |   di | d| _        t        d      t	        d       dg| _        | j                  j                  j                  d      st        | j                        r2| j
                  j                  t        d      t	        d       d       y y )	Nzleave-allocationzMy Leave allocation requestzmy-leave-allocation-request-tab)titleurl!leave.view_leaveallocationrequestzLeave allocation requests"leave-allocation-requests-tab-viewr%   )r/   r0   r2   rN   r   tabsrequestuserhas_permr   appendr3   s     r'   r0   z"LeaveAllocationRequestTab.__init__   s    "6") 89!"CDE
	 <<%%/
 .II:;%&JKL /r&   )r    r!   r"   r#   r   r0   rU   rV   s   @r'   rX   rX   }   s        r&   rX   c                   B     e Zd ZdZdeddf fdZ fdZdZdZdZ	 xZ
S )	MyLeaveAllocationRequestz
    My leave allocations
    r*   r+   Nc                 R    t        |   di | t        d      | _        d| _        y )Nr-   zmy-leave-containerr%   r.   r3   s     r'   r0   z!MyLeaveAllocationRequest.__init__   s'    "6"!"CD+r&   c                     t         |          }| j                  j                  j                  }|j                  |      j                  d      }|S )N)r6   z-id)r/   get_querysetr_   r`   employee_getfilterorder_by)r4   querysetemployeer5   s      r'   rg   z%MyLeaveAllocationRequest.get_queryset   sE    7')<<$$11??x?8AA%Hr&   a  
                {diff_cell}
                hx-get='{leave_request_allocation_detail_view}?instance_ids={ordered_ids}'
                hx-target="#genericModalBody"
                data-target="#genericModal"
                data-toggle="oh-modal-toggle"
                rH   )r    r!   r"   r#   r   r0   rg   	row_attrsrR   action_methodrU   rV   s   @r'   rd   rd      s3    , , ,
I M Mr&   rd   c                   >     e Zd ZdZdeddf fdZ fdZdZdZ xZ	S )	LeaveAllocationRequestsz"
    Leave allocation request
    r*   r+   Nc                 R    t        |   di | t        d      | _        d| _        y )Nr]   zall-leave-containerr%   r.   r3   s     r'   r0   z LeaveAllocationRequests.__init__   s'    "6"!"FG,r&   c                 R    t         |          }t        | j                  |d      }|S )Nr\   )r/   rg   r   r_   )r4   rk   r5   s     r'   rg   z$LeaveAllocationRequests.get_queryset   s-    7')%LL($G
 r&   confirm_cola  
                {diff_cell}
                hx-get='{detail_view_leave_request_allocation}?instance_ids={ordered_ids}'
                hx-target="#genericModalBody"
                data-target="#genericModal"
                data-toggle="oh-modal-toggle"
                )
r    r!   r"   r#   r   r0   rg   rn   rm   rU   rV   s   @r'   rp   rp      s.    - - -
 "MIr&   rp   c                        e Zd ZdZdeddf fdZ ed      Z e       Z	dZ
dZd	Zd
 ed      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fg	Z xZS )LeaveAllocationRequestNavz
    Nav bar
    r*   r+   Nc                 l    t        |   di | t        d      | _        dt	        d       d| _        y )Nr-   z
                            data-toggle="oh-modal-toggle"
                            data-target="#objectCreateModal"
                            hx-target="#objectCreateModalTarget"
                            hx-get="zleave-allocation-request-createz"
                            r%   )r/   r0   r   r1   r   create_attrsr3   s     r'   r0   z"LeaveAllocationRequestNav.__init__   sC    "6"!"CD!% &22S%T$U V	 r&   zLeave Allocation Requestsz(cbv/leave_allocation_request/filter.htmlformz#listContainerr6   r   r9   r8   statusr>   r;   r:   5employee_id__employee_work_info__reporting_manager_idzReporting Manager.employee_id__employee_work_info__department_id
Department0employee_id__employee_work_info__job_position_idzJob Position1employee_id__employee_work_info__employee_type_idzEmployment Type+employee_id__employee_work_info__company_idCompany)r    r!   r"   r#   r   r0   rN   	nav_titler   filter_instancefilter_body_templatefilter_form_context_namesearch_swap_targetgroup_by_fieldsrU   rV   s   @r'   ru   ru      s          -.I24OE%) 
*&	!L/*	1X;	1-./C!"	
 
:1\?K	;Q~=NO? 	
 
7)EOr&   ru   c                   P     e Zd ZdZdeddf fdZdZeZ e	d      Z
dd	d
dZ xZS ) LeaveAllocationRequestDetailViewz
    detail view of page
    r*   r+   Nc           
          t        |   di | t        d      dft        d      dft        d      dft        d      dft        d	      d
ft        d      ddft        d      ddft        d      ddfg| _        y )Nr:   r;   r8   r9   zCreated Daterequested_dater<   r=   r@   rA   Historyhistory_colTzReject Reason
reject_col
Attachmentattachment_colr%   )r/   r0   rN   bodyr3   s     r'   r0   z)LeaveAllocationRequestDetailView.__init__   s    "6" "23|_o.~ 01|_89}}-y\=$/t4|_.5	
	r&   detail_actionDetailsrE   (leave_request_allocation_detail_subtitler7   )rZ   subtitleavatar)r    r!   r"   r#   r   r0   rn   r   rL   rN   rZ   headerrU   rV   s   @r'   r   r      s@    
 
 
 $M"EiLE->+Fr&   r   c                       e Zd ZdZdZy)%LeaveAllocationsRequestsTabDetailViewz
    Detail view
    leave_detail_actionN)r    r!   r"   r#   rn   r%   r&   r'   r   r     s     *Mr&   r   c                   b     e Zd ZdZeZeZ ed      Z	 fdZ
dedef fdZdedef fdZ xZS )LeaveAllocationRequestFormViewz
    Form View
    zCreate Leave Allocation Requestc                    t        |   di |}| j                  j                  j                  }| j                  d|i       | j                  j                  j                  r7d| j
                  _	        | j                  | j                  j                         t        | j                  | j                  d      | _        | j                  j                  d   j                  t        j                  j                  | j                  j                        z  | j                  j                  d   _        | j                  |d<   |S )	Nr6   )initialzUpdate Request)instancez leave.add_leaveallocationrequest)employee_user_idrx   r%   )r/   get_context_datar_   r`   rh   
form_classrx   r   pkverbose_namer   fieldsrk   r   objectsri   )r4   r*   contextrl   r5   s       r'   r   z/LeaveAllocationRequestFormView.get_context_data+  s    '*4V4<<$$11 9:99  +;DOO(OOTYY%7%7O8&LL$))%G
	 48993C3C4

(X%%,,dll>O>O,P4Q		'0 ))r&   rx   r+   c                     |j                         s>|j                  j                         }t        | j                  | j
                  ||d      S t        |   |      S )N)rx   errors)is_validr   as_datar   r_   r$   r/   form_invalid)r4   rx   r   r5   s      r'   r   z+LeaveAllocationRequestFormView.form_invalid;  sS    }}[[((*Fd00462R  w#D))r&   c                 Z   |j                         rs| j                  | j                  j                         |j	                         }d|_        |j                  j                  rt        d      }t        j                  t              5  t        j                  | j                  j                  j                  |j                   j"                  j$                  j&                  d|j                    dd|j                    dd|j                    dd|j                    dd|j                    dd	t)        d
      d|j*                   z   	       d d d        nt        d      }t        j                  t              5  t        j                  | j                  j                  j                  |j                   j"                  j$                  j&                  d|j                    dd|j                    dd|j                    dd|j                    dd|j                    dd	t)        d
      d|j*                   z   	       d d d        |j	                          t-        j.                  | j                  |       | j1                         S t2        | i  |      S # 1 sw Y   XxY w# 1 sw Y   dxY w)NFz Leave allocation request updatedz%Leave allocation request updated for .u6   تم تحديث طلب تخصيص الإجازة لـ u/   Urlaubszuteilungsanforderung aktualisiert für u6   Solicitud de asignación de licencia actualizada para u1   Demande d'allocation de congé mise à jour pour zpeople-ciclezleave-allocation-request-viewz?id=)	recipientverbverb_arverb_deverb_esverb_friconredirectz$New leave allocation request createdz)New leave allocation request created for u;   تم إنشاء طلب تخصيص إجازة جديد لـ u0   Neue Anfrage zur Urlaubszuweisung erstellt für u7   Nueva solicitud de asignación de permisos creada para u5   Nouvelle demande d'allocation de congé créée pour )r   r   r_   FILESsaveskip_historyr   r   rN   
contextlibsuppress	Exceptionr   sendr`   rh   r6   employee_work_inforeporting_manager_idr   r   idr   successr   r/   
form_valid)r4   rx   r   messager5   s       r'   r   z)LeaveAllocationRequestFormView.form_validC  se   ==?OODLL../yy{H$)H!}}>?((3 KK))66"*"6"6"I"I"^"^"o"oDXEYEYDZZ[\"XYaYmYmXnno p"QRZRfRfQggh i"XYaYmYmXnno p"ST\ThThSiij k+!()H!I ."/  BC((3 KK))66"*"6"6"I"I"^"^"o"oHI]I]H^^_`"]^f^r^r]sst u"RS[SgSgRhhi j"YZbZnZnYoop q"WX`XlXlWmmn o+!()H!I ."/ MMOT\\73$$&&w!$''?  s   	CJ:CJ!J!J*)r    r!   r"   r#   r   rL   r   r   rN   new_display_titler   r   r   r   r   rU   rV   s   @r'   r   r   !  sQ     #E+J;< * * *&(9 &(l &( &(r&   r   Leavez+leave.cbv.accessibility.leave_accessibility)rZ   viewaccessibility)r^   )8r#   r   typingr   django.contribr   django.httpr   django.shortcutsr   django.urlsr   r   django.utils.decoratorsr	   django.utils.translationr
   rN   base.methodsr   r   r   employee.cbv.employee_profiler   employee.modelsr   horilla_views.cbv_methodsr   horilla_views.generic.cbv.viewsr   r   r   r   r   r   leave.cbv.leave_tabr   leave.filtersr   leave.formsr   leave.modelsr   notifications.signalsr   r   r)   rX   rd   rp   ru   r   r   r   add_tabas_viewr%   r&   r'   <module>r      s     # $ # - 4 6 T T = $ 4  3 6 2 / ( .z2Q Q 3Q .z2N) N) 3N)b .z2  34 .z2!9 ! 3!6 .z28  38 .z2% % 3%P .z2':  3: .z2*,L * 3* .z2G(_ G( 3G(T     .&..0J		

	r&   