
    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 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mZmZmZmZmZ  G d de      Z G d de      Z G d de      Z G d de      Z  G d de      Z! G d de      Z" G d de      Z#y)zQ
offboarding/forms.py

This module is used to register forms for offboarding app
    N)Any)forms)messagesrender_to_string)	ModelForm)MultipleFileField)Employee)horilla_middlewares)notify)EmployeeTaskOffboardingOffboardingEmployeeOffboardingNoteOffboardingStageOffboardingStageMultipleFileOffboardingTaskResignationLetterc                   <    e Zd ZdZdZdddddZ G d d      Zd Zy)	OffboardingFormz*
    OffboardingForm model form class
    r      )titledescriptionmanagersstatusc                       e Zd ZeZdZdgZy)OffboardingForm.Meta__all__	is_activeN)__name__
__module____qualname__r   modelfieldsexclude     5/var/www/python-projects/worksol/offboarding/forms.pyMetar   (   s    -r'   r)   c                 &    d| i}t        d|      }|S zS
        Render the form fields as HTML table rows with Bootstrap styling.
        formzcommon_form.htmlr   selfcontext
table_htmls      r(   as_pzOffboardingForm.as_p-         4.%&8'B
r'   Nr    r!   r"   __doc__verbose_namecolsr)   r1   r&   r'   r(   r   r      s+     !LbID   
r'   r   c                   :    e Zd ZdZdZddddZ G d d      Zd Zy)	OffboardingStageFormz%
    OffboardingStage model form
    Stager   )r   typer   c                       e Zd ZeZdZdgZy)OffboardingStageForm.Metar   r   N)r    r!   r"   r   r#   r$   r%   r&   r'   r(   r)   r<   ?   s     -r'   r)   c                 &    d| i}t        d|      }|S r+   r   r-   s      r(   r1   zOffboardingStageForm.as_pD   r2   r'   Nr3   r&   r'   r(   r8   r8   6   s)     L4D   
r'   r8   c                   @     e Zd ZdZdZ G d d      Zd Z fdZ xZS )OffboardingEmployeeFormz,
    OffboardingEmployeeForm model form
    zOffboarding c                   r    e Zd ZeZdZg dZ ej                  ddi       ej                  ddi      dZ	y)OffboardingEmployeeForm.Metar   )notice_periodunitr   r:   dateattrs)notice_period_startsnotice_period_endsN)
r    r!   r"   r   r#   r$   r%   r   	DateInputwidgetsr&   r'   r(   r)   rA   T   s>    #8$3EOO66:J$K"1%//8H"I
r'   r)   c                 &    d| i}t        d|      }|S r+   r   r-   s      r(   r1   zOffboardingEmployeeForm.as_p]   r2   r'   c                    t        |   |i | | j                  d   j                  j                  }d|d<   | j                  d   j                  j                  j                  |       | j                  d   j                  j                  }d|d<   | j                  d   j                  j                  j                  |       | j                  j                  r| j                  j                  r2| j                  j                  j                  d      | j                  d<   | j                  j                  r3| j                  j                  j                  d      | j                  d<   y y y )Nemployee_idzinitialNoticePeriod($(this))onchangerG   znoticePeriodUpdate($(this))z%Y-%m-%drH   )super__init__r$   widgetrF   updateinstancepkrG   strftimeinitialrH   )r.   argskwargsrF   	__class__s       r(   rP   z OffboardingEmployeeForm.__init__e   s&   $)&)M*1177:jM"))//66u=23::@@9j*+2288??F==}}11MM66??
K 34 }}//MM44==jI 12 0 r'   )	r    r!   r"   r4   r5   r)   r1   rP   __classcell__rY   s   @r(   r?   r?   M   s(     "L
 
 r'   r?   c                   <     e Zd ZdZ G d d      Zdd fd
Z xZS )StageSelectFormzB
    This form is used to register drop down for the pipeline
    c                       e Zd ZeZdgZy)StageSelectForm.Metastage_idN)r    r!   r"   r   r#   r$   r&   r'   r(   r)   r_   }   s    #
r'   r)   N)offboardingc                   t        |   |i | | j                  d   j                  j                  }d|d<   d|d<   | j                  d   j                  j                  j                  |       d | j                  d   _        t        j                  j                  |      | j                  d   _
        d| j                  d   _        y )Nr`   zoffboardingUpdateStage($(this))rN   zw-100 oh-custom-selectclass)offboarding_id )rO   rP   r$   rQ   rF   rR   empty_labelr   objectsfilterquerysetlabel)r.   ra   rW   rX   rF   rY   s        r(   rP   zStageSelectForm.__init__   s    $)&)J'..44=j1gJ&&,,33E:.2J++;+C+C+J+J& ,K ,
J( )+J%r'   )r    r!   r"   r4   r)   rP   rZ   r[   s   @r(   r]   r]   x   s!    
 
 +/ 
+ 
+r'   r]   c                   V     e Zd ZdZdZ G d d      Z fdZd Zd
dede	f fd	Z
 xZS )NoteFormz%
    Offboarding note model form
    zAdd Notec                       e Zd ZeZdZdgZy)NoteForm.Metar   r   N)r    r!   r"   r   r#   r$   r%   r&   r'   r(   r)   rn      s    -r'   r)   c                 ~    t        |   |i | t        d      | j                  d<   d| j                  d   _        y )NAttachements)rj   
attachmentF)rO   rP   r	   r$   required)r.   rW   rX   rY   s      r(   rP   zNoteForm.__init__   s9    $)&)$5N$KL!-2L!*r'   c                 &    d| i}t        d|      }|S r+   r   r-   s      r(   r1   zNoteForm.as_p   r2   r'   commitreturnc                    g }d }| j                   j                  d      rt| j                   j                  d      }|d   | j                  _        g }|D ]>  }t	               }||_        |j                          |j                  |j                         @ t        |   |      }|r |j                  j                  |  ||fS )Nrq   r   )filesgetlistrS   rq   r   saveappendrT   rO   attachmentsadd)r.   rt   multiple_attachment_idsr{   rq   file_instancerS   rY   s          r(   ry   zNoteForm.save   s    "$::l+**,,\:K'21~DMM$&(#) A
 < >+5(""$'..}/?/?@	A
 7<'$H  $$&=>$$r'   .)r    r!   r"   r4   r5   r)   rP   r1   boolr   ry   rZ   r[   s   @r(   rl   rl      s;     L   
3
%4 %# % %r'   rl   c                        e Zd ZdZdZ ej                  ej                  j                         d      Z
dddddZ G d d      Z fd	Zd
 Zddedef fdZ xZS )TaskFormz
    TaskForm model form
    zOffboarding TaskF)ri   rr   r   )r   r   r`   tasks_toc                       e Zd ZeZdZddgZy)TaskForm.Metar   r   r   N)r    r!   r"   r   r#   r$   r%   r&   r'   r(   r)   r      s    [)r'   r)   c                    t        |   |i | d| j                  d   _        d | j                  d   _        | j                  j
                  st        j                  j                  t        j                  j                  | j                  j                  d            j                         j                        }|| j                  d   _        y y )NzAll Stages in Offboardingr`   r   id)stage_id__offboarding_idr   )rO   rP   r$   rf   rS   rT   r   rg   rh   r   rV   getfirstrd   ri   )r.   rW   rX   ri   rY   s       r(   rP   zTaskForm.__init__   s    $)&).IJ+.2J+}}*2299)9)A)A)H)H||''
3 *I *  : H 08DKK
#,  r'   c                 &    d| i}t        d|      }|S r+   r   r-   s      r(   r1   zTaskForm.as_p   r2   r'   rt   ru   c                     t         |   |       |rB| j                  d   }|D ]-  }t        j                  j                  || j                        }/ y y )Nr   )rM   task_id)rO   ry   cleaned_datar   rg   get_or_createrS   )r.   rt   	employeesemployeeassigned_taskrY   s        r(   ry   zTaskForm.save   s\    V))*5I%  , 4 4 B B ( MM !C ! r'   r   )r    r!   r"   r4   r5   r   ModelMultipleChoiceFieldr   rg   allr   r6   r)   rP   r1   r   r   ry   rZ   r[   s   @r(   r   r      sr     &L-u--$,,002H RRRHD* *
84 #  r'   r   c                        e Zd ZdZddddddZ ej                   ej                  ddd      d	      Zd
Z	 G d d      Z
d Z fdZddedef fdZ xZS )ResignationLetterFormz
    Resignation Letter
    r   )rM   r   r   planned_to_leave_onr   re   zdisplay:none;)zdata-summernotestylerE   Description)rQ   rj   zResignation Letterc                       e Zd ZeZdZdgZy)ResignationLetterForm.Metar   r   N)r    r!   r"   r   r#   r$   r%   r&   r'   r(   r)   r      s    !-r'   r)   c                 &    d| i}t        d|      }|S r+   r   r-   s      r(   r1   zResignationLetterForm.as_p  r2   r'   c                 n   t        |   |i | t        j                  ddd      | j                  d   _        g }| j                  j                  r=|j                  d       | j                  j                  j                         dz   | _        t        t        j                  dd       }|rG|j                  j!                  d	      s,|dd
gz   }|j                  j"                  | j                  _	        |r|j                  j!                  d	      r||j$                  j'                  d      ra|j$                  j'                  d      }t(        j*                  j-                  |      | j                  d   _        || j                  d   _        t3        t5        |            }|D ]  }| j                  |=  y )NrD   zoh-input w-100)r:   rc   rE   r   rM   z's Resignation Letterrequest#offboarding.add_offboardingemployeer   emp_idr   )rO   rP   r   rI   r$   rQ   rS   rT   rz   rM   get_full_namer5   getattrr   _thread_localsuserhas_permemployee_getGETr   r
   rg   rh   ri   rV   listset)r.   rW   rX   r%   r   r   fieldrY   s          r(   rP   zResignationLetterForm.__init__  sm   $)&)49OO!,<=5
)*1 ==NN=)))779<SS  -<<iN7<<001VW! G )0(A(ADMM%w||,,-RS{{x( 26>6F6F6M6MQW6M6XM*35;M*2s7|$ 	#EE"	#r'   rt   ru   c                    t        t        j                  dd       }| j                  }|j                  j                  d      s|j                  dk(  s|j                  j                  d      rt        | !  |      }nt        j                  |d       |j                  dk(  r|r|j                  j                  d      st        j                  t              5  t        j                  |j                  j                   | j                  j"                  j%                         j&                  | j                  j"                  j)                          d    dd		       d d d        |S |S # 1 sw Y   |S xY w)
Nr   r   	requestedadd_offboardingemployeez9You cannot edit a request that has been rejected/approvedz requested for resignation.#information)	recipientverbverb_arverb_deverb_esverb_frredirecticon)r   r   r   rS   r   r   r   rO   ry   r   info
contextlibsuppress	Exceptionr   sendr   rM   get_reporting_manageremployee_user_idr   )r.   rt   r   rS   rY   s       r(   ry   zResignationLetterForm.save*  s-   -<<iN==%%&KL;.\\""#<=w|F+HMMT
 OO{*LL))*OP$$Y/ LL--"mm77MMO`` MM55CCEFFab &
 x s   BE))E3r   )r    r!   r"   r4   r6   r   	CharFieldTextarear   r5   r)   r1   rP   r   r   ry   rZ   r[   s   @r(   r   r      s{    
 !D "%//u~~_$UVK (L   
#:4 #  r'   r   )$r4   r   typingr   djangor   django.contribr   django.template.loaderr   
base.formsr   employee.formsr	   employee.modelsr
   horillar   notifications.signalsr   offboarding.modelsr   r   r   r   r   r   r   r   r   r8   r?   r]   rl   r   r   r&   r'   r(   <module>r      s       # 3   , $ ' (	 	 	i .9 .(i (V+i +0(%y (%V/y /d[I [r'   