
    si{=                        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 ddlmZ ddlmZmZmZ ddl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&m'Z'm(Z(m)Z)m*Z* ddl+m,Z,  ee$d       e ed      d       G d de*                    Z- ee$d       G d de(             Z. ee$d       e ed      d       G d de.                    Z/ ee$d       e ed      d       G d de)                    Z0 ee$d       e ed      d       G d de&                    Z1 ee$d       e ed      d       G d  d!e*                    Z2 G d" d#e'      Z3 ee$d       e ed$      d       G d% d&e3                    Z4 ee$d       e ed'      d       G d( d)e'                    Z5 ee$d       e ed      d       G d* d+e'                    Z6y),z
Rotating shift request

    N)Any)messages)HttpResponse)render)reversereverse_lazy)method_decorator)gettext_lazy)manager_can_enter)RotatingShiftAssignFilters)RotatingShiftAssignExportFormRotatingShiftAssignFormRotatingShiftForm)choosesubordinatesfiltersubordinatesis_reportingmanager)RotatingShiftRotatingShiftAssign)Employee)login_required)HorillaDetailedViewHorillaFormViewHorillaListViewHorillaNavViewTemplateView)notifydispatch)namebase.view_rotatingshiftassignc                       e Zd ZdZdZy)RotatingShiftAssignViewz
    Shift request page
    z&cbv/rotating_shift/rotating_shift.htmlN)__name__
__module____qualname____doc__template_name     B/var/www/python-projects/worksol/base/cbv/rotating_shift_assign.pyr!   r!   %   s     =Mr(   r!   c            
            e Zd ZdZdeddf fdZeZeZ	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 ed      dfgZddiZg dZ xZS )RotatingShiftListParentz
    Parent class
    kwargsreturnNc                 .   t        |   di | t        d      | _        d| _        | j
                  j                  j                  d      s:| j
                  j                  j                  d      st        | j
                        rd| _	        y d | _	        y )Nrotating-shift-request-listzrotating-shift-containerbase.delete_rotatingshiftassignbase.change_rotatingshiftassignactionsr'   )
super__init__r   
search_urlview_idrequestuserhas_permr   action_methodselfr,   	__class__s     r)   r4   z RotatingShiftListParent.__init__5   su    "6"!"?@1LL&&'HI||  ))*KL"4<<0!*D!%Dr(   z/cbv/rotating_shift/extended_rotating_shift.htmlr   employee_idemployee_id__get_avatarRotating Shiftrotating_shift_idBased onget_based_on_displayRotaterotating_column
Start Date
start_dateCurrent Shiftcurrent_shiftNext Switchnext_change_date
Next Shift
next_shiftactionzG
                   style="width:250px !important;"
                   ))r   employee_id__get_full_namer?   )r@   rotating_shift_id__name)rB   rC   )rD   rE   )rL   next_shift__employee_shift)rF   rG   )rH   current_shift__employee_shift)rJ   rK   )r"   r#   r$   r%   r   r4   r   modelr   filter_classr&   _columnsheader_attrssortby_mapping__classcell__r=   s   @r)   r+   r+   /   s    & & &  E-LEM	
:'@A	
	12	
:./	
8'(	
<,'	
?	_-	
=	-.	
<,'	G 	 L	Nr(   r+   c                   .     e Zd ZdZddgZ fdZdZ xZS )RotatingShiftListz
    List view
    rA   rG   c                 R    t         |          }t        | j                  |d      }|S )Nr   )r3   get_querysetr   r7   )r<   querysetr=   s     r)   r^   zRotatingShiftList.get_querysetl   s-    7')%LL($C
 r(   z
                hx-get='{rotating_shift_detail}?instance_ids={ordered_ids}'
                hx-target="#genericModalBody"
                data-target="#genericModal"
                data-toggle="oh-modal-toggle"
                )r"   r#   r$   r%   bulk_update_fieldsr^   	row_attrsrY   rZ   s   @r)   r\   r\   c   s!     .|<Ir(   r\   c            	            e Zd ZdZdeddf fdZdZdZ e       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gZ xZS )RotatingShiftAssignNavz
    Nav bar
    r,   r-   Nc                 `   t        |   di | t        d      | _        | j                  j
                  j                  d      st        | j                        rdt        d       d| _	        g | _
        | j                  j
                  j                  d      st        | j                        r'| j                  j                  t        d      dd	       | j                  j
                  j                  d      st        | j                        r4| j                  j                  t        d
      dt        d       dd	       | j                  j
                  j                  d      st        | j                        rN| j                  j                  t        d      dd	       | j                  j                  t        d      dd	       | j                  j
                  j                  d      st        | j                        r(| j                  j                  t        d      dd	       y y )Nr/   base.add_rotatingshiftassignz
                hx-get="zrotating-shift-assign-addz"
                data-toggle="oh-modal-toggle"
                data-target="#genericMaodal"
                hx-target="#genericModalBody"
            r   Importa,  
                            data-toggle="oh-modal-toggle"
                            data-target="#shiftImport"
                            class="oh-dropdown__link"
                            role = "button"
                            onclick="template_download(event)"
                         )rN   attrsExportz
                        data-toggle="oh-modal-toggle"
                        data-target="#genericModal"
                        hx-get="zexport-rshiftz"
                        hx-target ="#genericModalBody"
                        style="cursor: pointer;"
                        r1   Archivez
                        onclick = "archiveRotateShift();"
                        style="cursor: pointer;"
                        z
Un-Archivez
                        onclick = "un_archiveRotateShift();"
                        style="cursor: pointer;"
                        r0   Deletea  
                            class ="shift"
                            onclick = "deleteRotatingShift();"
                            data-action ="delete"
                            style="cursor: pointer; color:red !important"
                            r'   )r3   r4   r   r5   r7   r8   r9   r   r   create_attrsr2   appendrU   r;   s     r)   r4   zRotatingShiftAssignNav.__init__   s   "6"!"?@<<%%*
 .%%&ABC D!D <<%%+
 .LLk"	 <<%%+
 .LLk"! ")!9 : ;	 <<%%-
 .LL	l LLo <<%%-
 .LLk 
 /r(   Rotating Shift Assignz-cbv/rotating_shift/rotating_shift_filter.htmlformz#listContainerr>   r   rA   r@   based_onrB   .employee_id__employee_work_info__department_id
Department0employee_id__employee_work_info__job_position_idzJob role5employee_id__employee_work_info__reporting_manager_idzReporting Manager)r"   r#   r$   r%   r   r4   	nav_titlefilter_body_templater   filter_instancefilter_form_context_namesearch_swap_targetrU   group_by_fieldsrY   rZ   s   @r)   rc   rc   {   s    O O Ob (IJ02O%) 
*&	a 012	Qz]#	91\?K	;Qz]KC!"	

Or(   rc   c            
            e Zd ZdZeZ ed      ZddddZ e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 ed      dfgZ	dZ
 fdZ xZS )RotatingShiftDetailviewz
    Detail View
    DetailsrO   rotating_subtitler?   )titlesubtitleavatarTitlerA   rB   rC   rD   rE   rF   rG   rH   rI   rL   rM   zNext Change DaterK   Statuscheck_activerotating_detail_actionsc                 D    t        |   di |}|d   }|d   |_        |S )Nobjectinstance_idsr'   )r3   get_context_dataordered_ids)r<   r,   contextinstancer=   s       r)   r   z(RotatingShiftDetailview.get_context_data  s1    '*4V48$&~6r(   )r"   r#   r$   r%   r   rS   rU   r~   headerbodyr:   r   rY   rZ   s   @r)   r{   r{      s      EiLE .'+F 
7()	
:./	
8'(	
<,'	
?	_-	
<,'	
	 23	
8n%	D .M r(   r{   c                   ,     e Zd ZdZdZdef fdZ xZS )RotatingExportViewz
    For candidate export
    z%cbv/rotating_shift/rshift_export.htmlr,   c                     t        |   di |}t        j                  j	                         }t
        }t        |      }||d<   ||d<   |S )N)r_   export_columnsexport_filterr'   )r3   r   r   objectsallr   r   )r<   r,   r   rshift_requestsr   r   r=   s         r)   r   z#RotatingExportView.get_context_data  sR    '*4V4-5599;62OL$2 !#0 r(   )r"   r#   r$   r%   r&   r   r   rY   rZ   s   @r)   r   r     s      <M  r(   r   c                   @     e Zd ZdZeZeZdZdZ	dZ
dedef fdZ xZS ) DynamicRotatingShiftTypeFormView
    form view
    zCreate Rotating ShiftT&cbv/rotating_shift/rot_shift_form.htmlrn   r-   c                     |j                         rK|j                          t        d      }t        j                  | j
                  |       | j                         S t        | !  |      S )NRotating Shift Created)	is_validsaverU   r   successr7   r   r3   
form_validr<   rn   messager=   s      r)   r   z+DynamicRotatingShiftTypeFormView.form_valid)  sS    ==?IIK01GT\\73$$&&w!$''r(   )r"   r#   r$   r%   r   rS   r   
form_classnew_display_titleis_dynamic_create_viewr&   r   r   rY   rZ   s   @r)   r   r     s>     E"J/!<M(0 (\ ( (r(   r   zbase.add_rotatingshiftc                   >     e Zd ZdZdZdZ fdZdedef fdZ	 xZ
S )RotatingShiftTypeCreateFormViewr   Fr   c                    t        |   di |}| j                         }| j                  j                  j
                  r@| j                  | j                  j                        }t        d      | j                  _        |||<   |S )Nr   zUpdate Rotating Shift Typer'   )r3   r   r   rn   r   pkrU   verbose_name)r<   r,   r   rn   r=   s       r)   r   z0RotatingShiftTypeCreateFormView.get_context_data<  sn    '*4V4 99  ??DII,>,>??D+,-I+JDOO(r(   rn   r-   c                 0   |j                         rw|j                          | j                  j                  j                  rt        d      }nt        d      }t        j                  | j                  |       | j                         S t        | -  |      S )NzRotating Shift Updatedr   )r   r   rn   r   r   rU   r   r   r7   r   r3   r   r   s      r)   r   z*RotatingShiftTypeCreateFormView.form_validE  sq    ==?IIKyy!!$$4545T\\73$$&&w!$''r(   )r"   r#   r$   r%   r   r&   r   r   r   r   rY   rZ   s   @r)   r   r   2  s3     #<M	(0 	(\ 	( 	(r(   r   re   c                   l     e Zd ZdZeZeZ ed      Z	de
fgZ fdZdedef fdZdedef fdZ xZS )	RotatingShiftFormViewz
    Create and edit form
    rm   rA   c                    t        |   di |}| j                  j                  j	                  d      r| j                  j                  j	                  d      }|| j
                  j                  d   _        t        j                  j                  |      | j
                  j                  d   _        | j
                  j                  j                  r&| j                  | j
                  j                        }t        | j                  | j
                  d      | _        | j
                  j                  j                  rt!        d      | j                  _        | j
                  |d<   |S )	Nemp_idr>   idr   re   Rotating Shift Assign Updatern   r'   )r3   r   r7   GETgetrn   fieldsinitialr   r   filterr_   r   r   r   r   rU   r   )r<   r,   r   employeern   r=   s        r)   r   z&RotatingShiftFormView.get_context_data]  s   '*4V4<<)||''++H5H6>DII]+37?7G7G7N7N 8O 8DII]+4 99  ??DII,>,>??D&LL$))%C
	 99  +,-K+LDOO())r(   rn   r-   c                 2   | j                   j                  j                  rt        d      | j                  _        |j                         s>|j                  j                         }t        | j                  | j                  ||d      S t        | 5  |      S )Nr   rn   errors)rn   r   r   rU   r   r   r   r   as_datar   r7   r&   r3   form_invalidr<   rn   r   r=   s      r)   r   z"RotatingShiftFormView.form_invalido  sx    99  +,-K+LDOO(}}[[((*Fd00462R  w#D))r(   c                    |j                         rB|j                  j                  rt        d      }nt        d      }| j                  j
                  j                  d      }t        j                  j                  |      j                  d      }|D cg c]  }|j                   }}t        j                  t              5  t        j                   | j                  j"                  j$                  |dddd	d
dt'        d      	       d d d        |j)                          t+        j,                  | j                  |       | j/                  d      S t0        | e  |      S c c}w # 1 sw Y   ^xY w)Nz*Rotating Shift Assign Updated Successfully*Rotating Shift Assign Created Successfullyr>   )id__inemployee_user_idzYou are added to rotating shiftu4   تمت إضافتك إلى وردية الدوريةu6   Sie werden der rotierenden Arbeitsschicht hinzugefügtu    Estás agregado a turno rotativou.   Vous êtes ajouté au quart de travail rotatifinfinitezemployee-profile)	recipientverbverb_arverb_deverb_esverb_friconredirect )r   r   r   rU   r7   POSTgetlistr   r   r   select_relatedr   
contextlibsuppress	Exceptionr   sendr8   employee_getr   r   r   r   r   r3   r   )r<   rn   r   employee_ids	employeesr   usersr=   s          r)   r   z RotatingShiftFormView.form_validy  s3   ==?}}HIHI#||0088G$,,33<3HWW&	 DMMx22MM((3 KK))66"'> V X B P'!();!<
 IIKT\\73$$R((w!$''! N s   E$AE))E2)r"   r#   r$   r%   r   rS   r   r   rU   r   r   dynamic_create_fieldsr   r   r   r   r   rY   rZ   s   @r)   r   r   Q  s`      E(J1213STU$* * *(6 (< ( (r(   r   c                   N     e Zd ZdZeZeZ fdZde	de
f fdZdede
fdZ xZS )RotatingShiftAssignDuplicatez
    Duplicate form view
    c                     t        |   di |}t        j                  j	                  | j
                  d         }| j                  |      }||d<   t        d      | j                  _        |S )Nr   r   r   rn   	Duplicater'   )	r3   r   r   r   r   r,   r   rU   r   )r<   r,   r   original_objectrn   r=   s        r)   r   z-RotatingShiftAssignDuplicate.get_context_data  se    '*4V4-5599T[[=N9O8'(~$r(   rn   r-   c                     t        d      | j                  _        |j                         s>|j                  j                         }t        | j                  | j                  ||d      S t        | )  |      S )Nr   r   )rU   r   r   r   r   r   r   r7   r&   r3   r   r   s      r)   r   z)RotatingShiftAssignDuplicate.form_invalid  sc    '(~$}}[[((*Fd00462R  w#D))r(   c                 X   | j                  | j                  j                        }t        d      | j                   _        |j                         rKt        d      }t        j                  | j                  |       |j                          | j                         S | j                  |      S )Nr   r   )r   r7   r   rU   r   r   r   r   r   r   r   )r<   rn   r   s      r)   r   z'RotatingShiftAssignDuplicate.form_valid  s{    t||001'(~$==?DEGT\\73IIK$$&&  &&r(   )r"   r#   r$   r%   r   rS   r   r   r   r   r   r   r   rY   rZ   s   @r)   r   r     s@      E(J* * *'6 '< 'r(   r   )7r%   r   typingr   django.contribr   django.httpr   django.shortcutsr   django.urlsr   r   django.utils.decoratorsr	   django.utils.translationr
   rU   base.decoratorsr   base.filtersr   
base.formsr   r   r   base.methodsr   r   r   base.modelsr   r   employee.modelsr   horilla_views.cbv_methodsr   horilla_views.generic.cbv.viewsr   r   r   r   r   notifications.signalsr   r!   r+   r\   rc   r{   r   r   r   r   r   r'   r(   r)   <module>r      sX  
   # $ # - 4 6 - 3 
 U T : $ 4  ) .z2#$CD:V=l = W 3= .z20o 0 30f .z2#$CD:V/  W 3, .z2#$CD:Vf^ f W 3fR .z2#$CD:V 1   W 3 F .z2#$CD:V  W 3"( (( .z2#$<=JO(&F ( P 3(: .z2#$BC*U@(O @( V 3@(F .z2#$CD:V!'? !' W 3!'r(   