
    si                         d Z ddlZddl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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" 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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=  ej|                  e?      Z@ G d de
j.                        Z G d de
j.                        ZA G d de
j.                        ZB G d de      ZC G d d e      ZD G d! d"e      ZE G d# d$eA      ZF G d% d&eB      ZG G d' d(e      ZH G d) d*eB      ZI G d+ d,e
j                        ZK G d- d.e
j                        ZM G d/ d0e      ZN G d1 d2e      ZO G d3 d4e      ZP G d5 d6e
j,                        ZQ G d7 d8e
j,                        ZR G d9 d:e      ZS G d; d<e      ZTg d=ZU G d> d?e
j,                        ZV G d@ dAe      ZW G dB dCe      ZX G dD dEe      ZY G dF dGe      ZZ G dH dIe      Z[ G dJ dKe      Z\ G dL dMe      Z] G dN dOe      Z^ G dP dQe      Z_ G dR dSe      Z` G dT dUe      Za G dV dWe      Zb G dX dYe
j.                        Zc G dZ d[e      Zdy)\a  
forms.py

This module contains the form classes used in the application.

Each form represents a specific functionality or data input in the
application. They are responsible for validating
and processing user input data.

Classes:
- YourForm: Represents a form for handling specific data input.

Usage:
from django import forms

class YourForm(forms.Form):
    field_name = forms.CharField()

    def clean_field_name(self):
        # Custom validation logic goes here
        pass
    N)Dict)datedatetime)Any)forms)apps)NON_FIELD_ERRORSValidationErrorrender_to_string)gettext_lazy)Form)	ModelForm)reload_queryset)CustomTextInputWidget)EmployeeFilter)Employee)horilla_middlewares)_thread_locals)HorillaMultiSelectField)HorillaMultiSelectWidget)widgets)	CandidateCandidateDocumentCandidateDocumentRequestInterviewScheduleJobPositionLinkedInAccountRecruitmentRecruitmentSurveyRejectedCandidateRejectReasonResumeSkill	SkillZoneSkillZoneCandidateStage
StageFiles	StageNoteSurveyTemplatec                   "     e Zd ZdZ fdZ xZS )r   zK
    Override of Django ModelForm to add initial styling and defaults.
    c           	         t        |   |i | t        | j                         t	        t
        j                  dd       }t        j                         }t        j                         }d}d}d}| j                  j                         D ]4  \  }	}
|
j                  }|
j                  rt        |
j                        nd}t        |t         j"                        r[||
_        d|_        d|_        dg|
_        |j,                  j/                  d|      }|j,                  j1                  | d	|d
       t        |t         j2                        r\||
_        d|_        d|_        dg|
_        |j,                  j/                  d|      }|j,                  j1                  | d	|d
       !t        |t         j4                  t         j6                  t         j8                  t         j:                  t         j<                  f      rn|j,                  j/                  d|      }|j,                  j1                  | d	|
j                  r#t        |
j                  j?                               ndd
       t        |t         j@                        rut        |
t         jB                        s t        d      j)                  |      |
_"        |j,                  j/                  d|      }|j,                  j1                  d|i       ut        |t         jF                        rA|j,                  j/                  d|      }|j,                  j1                  | d	|ddd       t        |t         jH                  t         jJ                  f      s|j,                  j/                  d|      }|j,                  j1                  d|i       7 |rt	        |jL                  dd       }|rxd| j                  v r|| j                  d   _        d| j                  v rG| j                  d   }t	        |dd       }|r(|jN                  }||v r|n|jQ                         |_        y y y y y )Nrequestoh-input w-100z/oh-select oh-select-2 select2-hidden-accessiblezoh-switch__checkbox r   z%Y-%m-%dclassz form-controlr0   placeholdertimez%H:%M---Choose {label}---label   (   r0   r2   rowscolsemployee_getemployee_id
company_idget_company))super__init__r   fieldsgetattrr   r   r   todayr   nowitemswidgetr6   _
isinstancer   	DateInputinitial
input_typeformatinput_formatsattrsgetupdate	TimeInputNumberInput
EmailInput	TextInput	FileInputURLInputtitleSelectModelMultipleChoiceFieldempty_labelTextareaCheckboxInputCheckboxSelectMultipleuserquerysetfirst)selfargskwargsr-   rD   rE   default_input_classselect_classcheckbox_class
field_namefieldrG   r6   existing_classemployeecompany_fieldcompanyr`   	__class__s                     5/var/www/python-projects/worksol/recruitment/forms.pyrA   zModelForm.__init__L   s   $)&)$-<<iN

lln.H.!%!2!2!4 M	?J\\F&+kkAekkNrE &%//2 %$*! *'1l#!'!1!1';N!O##$2#3=!A', FEOO4 #$*! ''.i#!'!1!1';N!O##$2#3=!A', %%$$OOOONN	 "(!1!1';N!O##$2#3=!AAFq):):)<'=RT FELL1!%)G)GH()*@(A(H(Hu(H(UE%!'!1!1'<!H##Wn$=> FENN3!'!1!1';N!O##$2#3=!A', ! "	 ,,e.J.JK "(!1!1'>!J##Wn$=>[M	?` w||^TBH DKK/9ADKK.64;;.$(KK$=M%htDG#0#9#9'.(':G@P &-  /	      __name__
__module____qualname____doc__rA   __classcell__rn   s   @ro   r   r   G   s    k krp   r   c                   "     e Zd ZdZ fdZ xZS )RegistrationFormC
    Overriding django default model form to apply some styles
    c                    t        |   |i | t        | j                         | j                  j	                         D ]I  \  }}|j
                  }t        |t        j                  f      rd}|j                  t        |j                        }t        d      j                  |      |_        | j                  |   j
                  j                  j                  t        j                   dd       t        |t        j"                        r(|j
                  j                  j                  ddi       t        |t        j$                  t        j&                  f      s#|j
                  j                  j                  ddi       L y )	Nr/   r4   r5   zoh-select-2 oh-select--sm w-100)idr0   r0   r.   oh-switch__checkbox )r@   rA   r   rB   rF   rG   rI   r   rY   r6   rH   rM   r[   rO   rQ   uuiduuid4rU   r]   r^   rb   rc   rd   rh   ri   rG   r6   rn   s          ro   rA   zRegistrationForm.__init__   s<   $)&)$!%!2!2!4 	MJ\\F&5<</2;;*ekkNE$%&<$=$D$D5$D$Q!J'..44;;::0QR FU__6""))!1
 ''00 ""))74J*KL/	Mrp   rq   rw   s   @ro   ry   ry      s    M Mrp   ry   c                   "     e Zd ZdZ fdZ xZS )DropDownFormrz   c           	      2   t        |   |i | t        | j                         | j                  j	                         D ]  \  }}|j
                  }t        |t        j                  t        j                  t        j                  t        j                  t        j                  f      rK|j                  wt        |j                        }|j
                  j                  j!                  d|d       t        |t        j"                  f      rI| j                  |   j
                  j                  j!                  dt%        j&                         d       t        |t        j(                        rO|j                  At        |j                        }|j
                  j                  j!                  d|ddd       t        |t        j*                  t        j,                  f      s|j
                  j                  j!                  d	d
i        y )Nz<oh-input oh-input--small oh-table__add-new-row d-block w-100r1   z!oh-select-2 oh-select--xs-forced )r0   r|   z+oh-input oh-input--small oh-input--textarea   r8   r9   r0   r}   )r@   rA   r   rB   rF   rG   rI   r   rS   rT   rU   rV   rW   r6   rH   rO   rQ   rY   r~   r   r\   r]   r^   r   s          ro   rA   zDropDownForm.__init__   s   $)&)$!%!2!2!4 -	MJ\\F%%$$OOOONN	 ;;*ekkNELL&&--%c+0 FU\\O4J'..44;;!D"jjl FU^^5;;*ekkNELL&&--%R+0$%$&	 ''00 ""))74J*KL[-	Mrp   rq   rw   s   @ro   r   r      s    0M 0Mrp   r   c                   R     e Zd ZdZddddZ G d d      Zd Z fdZ fdZ xZ	S )	RecruitmentCreationForm$
    Form for Recruitment model
       )is_publishedoptional_profile_imageoptional_resumec                       e Zd ZdZeZdZddgZ ej                  ddi       ej                  ddi       ej                  dd	i      d
Zy)RecruitmentCreationForm.Meta7
        Meta class to add the additional info
        __all__	is_activelinkedin_post_idtyper   rO   data-summernoter/   
start_dateend_datedescriptionN)rr   rs   rt   ru   r   modelrB   excluder   rJ   r\   r    rp   ro   Metar     s_    	  23)%//0@A'vv.>?)5>>1BB0GH
rp   r   c                 &    d| i}t        d|      }|S S
        Render the form fields as HTML table rows with Bootstrap styling.
        formzhorilla_form.htmlr   rb   rc   rd   context
table_htmls        ro   as_pzRecruitmentCreationForm.as_p-        4.%&97C
rp   c           
      Z   t        |   |i | t        | j                         | j                  j
                  st        t        j                  j                  d      t        dt        ddd      | j                  j                         j                  j                  d      j                         | j                  d<   d	t!        d
      fgt#        | j                  d   j$                  j'                  dd            z   }|| j                  d   _        | j                  d   xj(                  dt!        d      fgz  c_        t*        j                  j                  d      | j                  d   _        | j                  d   j,                  j.                  j1                  ddi       y )NTr   employee-widget-filterfemployee_filters.htmlfilter_route_namefilter_classfilter_instance_contex_namefilter_template_pathrequiredrecruitment_managersr`   rG   r6   r/   z---Choose Skills---skillsr|   rX   createzCreate new skill linkedin_account_idpublish_in_linkedinonchangeztoggleLinkedIn())r@   rA   r   rB   instancepkr   r   objectsfilterr   r   _metar   	get_fieldverbose_namerH   listr`   values_listchoicesr   rG   rO   rQ   )rb   rc   rd   skill_choicesrn   s       ro   rA   z RecruitmentCreationForm.__init__5  ss   $)&)$}}2I!))0040@/&>!/03)@! ))+11;;<RS``a
3DKK./ a 56784KK!**66tWE<
 
 )6H%H%%8Q7J5K*L)MM%6E6M6M6T6T 7U 7
)*3 	)*1177>>+,	
rp   c                    t        | j                  d   t              r9| j                  j	                  d      }|r| j
                  j                  dd        | j                  j                  d      }| j                  j                  d      }|r |st        j                  t        d            | j                  j                  d      r/| j                  d   s t        j                  dt        d      i      t        | 5          y )Nr   open_positionsr   z:Job position is required if the recruitment is publishing.r   r   z,LinkedIn account is required for publishing.)rI   rB   r   datagetlisterrorspopcleaned_datarP   r   r
   rH   r@   clean)rb   idsr   r   rn   s       ro   r   zRecruitmentCreationForm.cleanT  s    dkk"89;RS))##$:;C 6=**../?@((,,^<''NO  !!"78%%&;<'')1F,  	rp   )
rr   rs   rt   ru   r;   r   r   rA   r   rv   rw   s   @ro   r   r     s8    
 "#D
 

> rp   r   c                   @     e Zd ZdZ G d d      Z fdZ fdZ xZS )StageCreationForm
    Form for Stage model
    c                   4    e Zd ZdZeZdZddgZd ed      iZ	y)StageCreationForm.Metar   r   sequencer   stager'   N
rr   rs   rt   ru   r'   r   rB   r   rH   labelsr   rp   ro   r   r   r  -    	 {+QwZ
rp   r   c           
         t        |   |i | t        | j                         | j                  j
                  st        t        j                  j                  d      t        dt        ddd      | j                  j                         j                  j                  d      j                         | j                  d<   y y )	NTr   r   r   r   r   stage_managersr   )r@   rA   r   rB   r   r   r   r   r   r   r   r   r   r   r   r   rb   rc   rd   rn   s      ro   rA   zStageCreationForm.__init__~  s    $)&)$}},C!))0040@/&>!/03)@! ))+11;;<LMZZ[
-DKK()  rp   c                     t        | j                  d   t              r9| j                  j	                  d      }|r| j
                  j                  dd        t        | !          y )Nr   )	rI   rB   r   r   r   r   r   r@   r   )rb   r   rn   s     ro   r   zStageCreationForm.clean  sL    dkk"235LM))##$45C 0$7rp   )rr   rs   rt   ru   r   rA   r   rv   rw   s   @ro   r   r   m  s!    

 

  rp   r   c                        e Zd ZdZ ej
                  ej                  d      Z fdZ	 G d d      Z
ddef fdZd	 Z fd
Z xZS )CandidateCreationForm"
    Form for Candidate model
    FrG   r   c                    t        |   |i | d| j                  d   _        d| j                  d   j                  j
                  d<   d| j                  d   _        d| j                  d   j                  j
                  d<   d| j                  d   _        | j                  j                  \| j                  Pt        j                  | j                  j                  j                  j                         d	
      | j                  d<   ddi| j                  d   j                  _        ddi| j                  d   j                  _        y )Nsoftwaresource.jpg, .jpeg, .pngprofileacceptF.pdfresumezJob Positionr`   r6   job_position_iddata-widgetajax-widgetrecruitment_id)r@   rA   rB   rK   rG   rO   r   r   r   r   ModelChoiceFieldr   allr   s      ro   rA   zCandidateCreationForm.__init__  s   $)&)(2H%8KI%%++H5*/I'7=H$$**84).H&==''3}}(161G1G!]]99HHLLN(2-. 7D]5S$%,,27Dm6T%&--3rp   c                   r    e Zd ZdZeZg dZ ej                  ddi       ej                  ddi      dZ	y)CandidateCreationForm.Metar   )r   name	portfolioemailmobiler   r   dobgenderaddressr   countrystatezipr   referralcanceledr   r   r   r   )scheduled_dater   N)
rr   rs   rt   ru   r   r   rB   r   rJ   r   r   rp   ro   r   r     sD    	 
, .eooVV4DE"5??&&)9:
rp   r   commitc                    | j                   }|j                  }|j                  }d|_        d|_        |+|j
                  dk(  r|j                  du rd|_        d|_        ||_        ||_        | j                  j                  d      }|r1t        j                  j                  |      }|| j                   _        t        | 5  |      S )NFhiredTr   r|   )r   r   stage_idr   start_onboard
stage_typer   r   rP   r   r   r   r@   save)rb   r   	candidaterecruitmentr   job_idjob_positionrn   s          ro   r  zCandidateCreationForm.save  s    MM	..""	"'	7*y/A/AU/J"&	*.	'#.	 "	01&..22f2=L,8DMM)w|F##rp   c                 &    d| i}t        d|      }|S )r   r   z)candidate/candidate_create_form_as_p.htmlr   r   s        ro   r   zCandidateCreationForm.as_p  s$     4.%7

 rp   c                    i }| j                   d   }| j                   d   }| j                   d   }|s|j                  st        d      |d<   |s|j                  st        d      |d<   | j                  j
                  | j                  j                  dd        | j                  j                  | j                  j                  d      dk(  rt        d      |d<   | j                  j                  | j                  j                  j                  j                         vrt        d      |d<   |rt        |      t        | A         S )Nr   r   r   This field is requiredr   r/   zChoose valid choice)r   r   rH   r   r   r   r   r   r   r   rP   r   r   r   r
   r@   r   )rb   r   r   r   r  rn   s        ro   r   zCandidateCreationForm.clean  s%   ##I.""8,#'#4#45E#Fk99 !9:F8{AA !": ;F9==)KKOO-t4--599==!23r9,-.F,G()--}}33BBFFHI -..C,D()!&))w}rp   .)rr   rs   rt   ru   r   	CharFieldr   RecruitmentAjaxWidgetloadrA   r   boolr  r   r   rv   rw   s   @ro   r   r     sN     5??'"?"?%PDU 
 
@$4 $$ rp   r   c                        e Zd ZdZ ej
                  ej                  d      Ze	j                  j                  ddd      Z ej                  e      Z G d d      Z fd	Z fd
Z xZS )ApplicationFormz#
    Form for create Candidate
    Fr   T)r   closedr   )r`   c                   n    e Zd ZdZeZdZ ej                  ddi       ej                  ddi      dZ
y)	ApplicationForm.Metar   )r   schedule_dater   r  r   r   r   joining_dater   offerletter_statusr   r   r   r   r   )r   r   N)rr   rs   rt   ru   r   r   r   r   rU   rJ   r   r   rp   ro   r   r    sP    	 
 .eoo

 #5??F
rp   r   c                    t        |   |i | t        t        dd       }d| j                  d   j
                  j                  d<   d| j                  d   _        d| j                  d   j
                  j                  d<   d| j                  d   _        dd	i| j                  d
   j
                  _        dd	i| j                  d   j
                  _        |r1|j                  j                  d      rd| j                  d   _        y y y )Nr-   r   r   r   Fr   r   r   r   r   r   recruitment.add_candidate)
r@   rA   rC   r   rB   rG   rO   r   r_   has_perm)rb   rc   rd   r-   rn   s       ro   rA   zApplicationForm.__init__.  s    $)&).)T:8KI%%++H5*/I'7=H$$**84).H&6C]5S$%,,27Dm6T%&--3w||,,-HI.3DKK	"+ J7rp   c                 *   | j                   j                  d      }t        t        dd       }i }| j                   j                  d      }| j                   j                  d      }| j                   j                  d      }|r8|s|j                  st        d      |d<   |s|j                  st        d      |d<   |rt        |      |s1|r/|j                  j                  d      rd| }	|	| j                   d<   t        
| -          | j                   S )	Nr   r-   r   r   r   r
  r  z!https://ui-avatars.com/api/?name=)r   rP   rC   r   r   rH   r   r
   r_   r  r@   r   )rb   rc   rd   r   r-   r   r   r   r  profile_pic_urlrn   s             ro   r   zApplicationForm.clean;  s     $$V,.)T:##''	2""&&x0#'#4#4#8#89I#J+"="=#$%=#>x ;#E#E$%&>$?y!!&)) %%&AB A$HO+:Di(   rp   )rr   rs   rt   ru   r   r  r   r  r  r   r   r   active_recruitmentr   r   r   rA   r   rv   rw   s   @ro   r  r    st     5??'"?"?%PD$,,33u4 4  ,U++5GHN
 
@4! !rp   r  c                   6     e Zd ZdZ G d d      Z fdZ xZS )RecruitmentDropDownFormr   c                       e Zd ZdZdZeZ ej                  ddi       ej                  ddi       ej                  ddi      dZ
 ed	       ed
      dZy)RecruitmentDropDownForm.Metar   r   r   r   r   r   r/   r   DescriptionVacancy)r   vacancyN)rr   rs   rt   ru   rB   r   r   r   rJ   r\   r   rH   r   r   rp   ro   r   r!  ^  si    	 )%//0@A'vv.>?)5>>1BB0GH

 "#=!1a	lKrp   r   c                 t   t        |   |i | | j                  d   j                  j                  j                  dt        j                  i       | j                  d   j                  j                  j                  dt        j                  i       | j                  d   }|j                         |_        y )Nr   r|   r   r   )	r@   rA   rB   rG   rO   rQ   r~   r   hidden_widgetrb   rc   rd   ri   rn   s       ro   rA   z RecruitmentDropDownForm.__init__l  s    $)&)%&--33::D$**;MN*+2288??tzz@RSK(**,rp   rr   rs   rt   ru   r   rA   rv   rw   s   @ro   r  r  Y  s    L L- -rp   r  c                   @     e Zd ZdZdZ G d d      Z fdZd Z xZS )AddCandidateFormr   zAdd Candidatec                       e Zd ZdZeZg dZy)AddCandidateForm.Metar   )r   r   r   r   r   r   r   r   Nrr   rs   rt   ru   r   r   rB   r   rp   ro   r   r,  {  s    	 	
rp   r   c                    t        |   |i | |d   j                  d      }|rt        j                  j                  |      j
                  }|| j                  _        | j                  d   j                  j                  |      | j                  d   _        |j                  | j                  d   _        d| j                  d   j                  j                  d<   d	| j                  d
   j                  j                  d<   j                  rd| j                  d   _        |j                  rd| j                  d
   _        d | j                  d   _        d | j                  d   _        d | j                  d   _        y )NrK   r   r   )r   r   r   r   r   r   r   Fr   )r@   rA   rP   r'   r   r   r   rB   r`   r   r   rG   rO   r   r   r   r[   )rb   rc   rd   rK   r  rn   s        ro   rA   zAddCandidateForm.__init__  sK   $)&)#''
3--++w+7FFK+6DMM(/3{{:/F/O/O/V/V* 0W 0DKK
#, 7B6P6PDKK)*38KI%%++H57=H$$**84--.3DKK	"+&&-2DKK!*,0H)59%&2.2J+rp   c                 &    d| i}t        d|      }|S r   r   zcommon_form.htmlr   r   s        ro   r   zAddCandidateForm.as_p        4.%&8'B
rp   )	rr   rs   rt   ru   r   r   rA   r   rv   rw   s   @ro   r*  r*  t  s#     #L
 
"3(rp   r*  c                   6     e Zd ZdZ G d d      Z fdZ xZS )StageDropDownFormr   c                   4    e Zd ZdZeZdZddgZd ed      iZ	y)StageDropDownForm.Metar   r   r   r   r   r'   Nr   r   rp   ro   r   r5    r   rp   r   c                     t        |   |i | t        j                  j	                         }|+|j
                  |j
                  dz   | j                  _        y d| j                  _        y )Nr   )r@   rA   r'   r   lastr   r   )rb   rc   rd   r   rn   s       ro   rA   zStageDropDownForm.__init__  sW    $)&)""$!;%*^^a%7DMM"%&DMM"rp   r(  rw   s   @ro   r3  r3    s    

 

' 'rp   r3  c                       e Zd ZdZy)MultipleFileInputTN)rr   rs   rt   allow_multiple_selectedr   rp   ro   r9  r9    s    "rp   r9  c                   *     e Zd Z fdZd fd	Z xZS )MultipleFileFieldc                 X    |j                  dt                      t        |   |i | y )NrG   )
setdefaultr9  r@   rA   r   s      ro   rA   zMultipleFileField.__init__  s)    ($5$78$)&)rp   c                     t         |   }t        |t        t        f      r|D cg c]  } |||       }}n
 |||      g}|r|d   S g S c c}w )Nr   )r@   r   rI   r   tuple)rb   r   rK   single_file_cleandresultrn   s         ro   r   zMultipleFileField.clean  sb    !GMdT5M*=AB'73BFB "$0F #vay** Cs   AN)rr   rs   rt   rA   r   rv   rw   s   @ro   r<  r<    s    *+ +rp   r<  c                   L     e Zd ZdZ G d d      Z fdZddedef fdZ xZ	S )	StageNoteFormz"
    Form for StageNote model
    c                        e Zd ZdZeZdgZdgZy)StageNoteForm.Metar   r   r   N)rr   rs   rt   ru   r)   r   rB   r   r   rp   ro   r   rH    s    	 
  -rp   r   c                 ~    t        |   |i | t        d      | j                  d<   d| j                  d   _        y )Nfilesr5   stage_filesF)r@   rA   r<  rB   r   r   s      ro   rA   zStageNoteForm.__init__  s;    $)&) &7W%EM".3M"+rp   r   returnc                    g }g }d }| j                   j                  d      rt| j                   j                  d      }|d   | j                  _        g }|D ]>  }t	               }||_         |j                          |j                  |j                         @ t        |   |      }|r |j                  j                  |  ||fS )NrK  r   )rJ  r   r   attachementr(   r  appendr   r@   rK  add)rb   r   
attachmentmultiple_attachment_idsattachmentsfile_instancer   rn   s          ro   r  zStageNoteForm.save  s    
"$::m,**,,];K(3ADMM%&(#) A
 *&0#""$'..}/?/?@	A
 7<'$H  $$&=>000rp   r  )
rr   rs   rt   ru   r   rA   r  r   r  rv   rw   s   @ro   rF  rF    s/       414 1# 1 1rp   rF  c                   2     e Zd Z G d d      Z fdZ xZS )StageNoteUpdateFormc                        e Zd ZdZeZg dZdZy)StageNoteUpdateForm.Metar   )
updated_byr   rK  r   r   N)rr   rs   rt   ru   r)   r   r   rB   r   rp   ro   r   rX    s    	 Hrp   r   c                 l    t        |   |i | | j                  d   }|j                         |_        y )Ncandidate_id)r@   rA   rB   r&  rG   r'  s       ro   rA   zStageNoteUpdateForm.__init__  s3    $)&)N+**,rp   rr   rs   rt   r   rA   rv   rw   s   @ro   rV  rV    s     - -rp   rV  c                       e Zd ZdZddddZdZ ej                  ej                  j                  d      d ed      	      Z ej                  ej                   ed
      d      Z G d d      Zd Z fdZd fd	Z fdZ xZS )QuestionFormz
    QuestionForm
       )optionstemplate_idquestionzSurvey QuestionsTr   Fr   )r`   r   r6   Options)rG   r6   r   c                   l    e Zd ZdZeZdZg dZ ed       ed       ed       ed       ed      d	Z	y
)QuestionForm.Meta3
        Class Meta for additional options
        r   )recruitment_idsjob_position_idsr   r`  QuestionSequenceTyperc  zIs Mandatory)rb  r   r   r`  is_mandatoryN)
rr   rs   rt   ru   r    r   rB   r   rH   r   r   rp   ro   r   re  &  sC    	 "Q**fI|n-
rp   r   c                 &    d| i}t        d|      }|S )r   r   z,survey/question_template_organized_form.htmlr   r   s        ro   r   zQuestionForm.as_p6  s$     4.%:G

 rp   c                     t         |          }| j                  d   }| j                  d   }| j                  j                  d      }|j	                         st        dt        d      i      || _        |dv r||dk(  rt        ddi      |S )Nr  r   r`  z-Choose any recruitment to apply this questionr`  multipler/   zOptions field is required)r@   r   r   rP   existsr
   rH   r  )rb   r   r  question_typer`  rn   s        ro   r   zQuestionForm.clean@  s    w}''6))&1##''	2!!#!"Q RS  '33Ow"}!9.I"JKKrp   c                 Z   t         |   d      }|j                  dv rg }| j                  j	                         D ]+  \  }}|j                  d      s|s|j                  |       - dj                  |      |_        |r |j                          | j                          |S d|_        |S )NF)r   ro  r`  , r/   )
r@   r  r   r   rF   
startswithrO  joinr`  save_m2m)rb   r   r   additional_optionskeyvaluern   s         ro   r  zQuestionForm.saveP  s    7<u<-==33!#"//557 5
U>>),&--e45  $yy);<H   "Hrp   c                 x    t           |i | |j                  dd       }d _        d fd	}d fd	}|r^|j                  j                  d      }t        |      D ]5  \  }}|dk(  r
 |d|        xj                  dz  c_         |d| |       7 |r,|j                  j                          j                  d   _
         j                  d	   j                  j                  j                  d
dd        j                  j                         D ]6  \  }	}
|	j!                  d      s xj                  dz  c_         ||	|
       8 t#         j                  j%                               }|j'                  d       |j)                  dd       |D ci c]  }| j                  |    c} _	        y c c}w )Nr   r   c                     t        j                  t        j                  | d|  dd      t        d      d|      j                  | <   y )Nid_r.   r   r|   r0   r   rc  F)rG   r6   r   rK   )r   r  rU   rH   rB   
option_keyrK   rb   s     ro   create_options_fieldz3QuestionForm.__init__.<locals>.create_options_fielde  sJ    &+oo * #J<0!1 	l'DKK
#rp   c           	      p    t        j                  t        d| |  dd      d|      j                  | <   y )Nzadd-remove-options-fieldr.   r~  )
delete_urlrO   F)rG   r   rK   )r   r  r   rB   r  s     ro   create_options_field_morez8QuestionForm.__init__.<locals>.create_options_field_mores  s=    &+oo,9 *!+!1 'DKK
#rp   ,r   r`  r  r   z w-100z'border:solid 1px #6c757d52;height:50px;)r0   style)rK   r7   rD  )r@   rA   rP   option_countr`  split	enumeraterg  r   rB   rK   rG   rO   rQ   r   rF   ru  r   keysremoveinsert)rb   rc   rd   r   r  r  split_optionsioptionry  rz  fields_orderri   rn   s   `            ro   rA   zQuestionForm.__init__`  s   $)&)::j$/		 $,,2237M&}5 E	66(F;%%*%-smVDE 191I1I1M1M1ODKK&.F""((//)RS	
 ))//+ 	9JC~~i(!!Q&!$S%8	9 DKK,,./M*A}->JKUudkk%00KKs   F7T)rr   rs   rt   ru   r;   r   r   rZ   r   r   r   rH   r  r  rU   r`  r   r   r   r  rA   rv   rw   s   @ro   r^  r^    s     ""=D%L0%00$$++d+;K
 eooa	lUG
 
   6L 6Lrp   r^  c                   $     e Zd ZdZd fdZ xZS )
SurveyForm
    SurveyTemplateForm
    c                 j   t        	|   |g|i | |j                  j                         }t        j
                  j                         |z  }|j                  j                         D ]!  }|j                  j                         }||z  }# | |j                         d}t        d|      }|| _
        y )Nr   	questionszsurvey_form.html)r@   rA   recruitmentsurvey_setr   r    r   nonesurvey_templatesdistinctr   r   )
rb   r  rc   rd   r  all_questionstemplater   r   rn   s
            ro   rA   zSurveyForm.__init__  s    6t6v65599;	)116689D#4488: 	6H 66::<I)I5M	6  m.D.D.FG 2G<	rp   rL  Nrq   rw   s   @ro   r  r    s    
 
rp   r  c                   $     e Zd ZdZd fdZ xZS )SurveyPreviewFormr  c                     t        |   |g|i | t        j                  j	                  |g      }| |j                         d}t        d|      }|| _        y )N)template_id__inr  zsurvey_preview_form.html)r@   rA   r    r   r   r  r   r   )rb   r  rc   rd   r  r   r   rn   s          ro   rA   zSurveyPreviewForm.__init__  s_    3D3F3)1188(8Tm.D.D.FG :GD	rp   r  rq   rw   s   @ro   r  r    s     rp   r  c                   :    e Zd ZdZddddZdZ G d d      Zd Zy)	TemplateFormz
    TemplateForm
    r_  rX   r   r>   Templatec                       e Zd ZeZdZdgZy)TemplateForm.Metar   r   N)rr   rs   rt   r*   r   rB   r   r   rp   ro   r   r    s    -rp   r   c                 &    d| i}t        d|      }|S r0  r   r   s        ro   r   zTemplateForm.as_p  r1  rp   Nrr   rs   rt   ru   r;   r   r   r   r   rp   ro   r  r    s)     "=DL   
rp   r  c                       e Zd ZdZdZ ej                  ej                  j                         d      Z
 ej                  ej                  j                         d      Zd Zd Zy)	AddQuestionFormz
    AddQuestionForm
    zAdd Question	Questionsr   	Templatesc                 x    | j                   d   D ](  } |j                  j                  | j                  d     * y)zB
        Manual save/adding of questions to the templates
        question_idstemplate_idsN)r   ra  rP  r   )rb   rb  s     ro   r  zAddQuestionForm.save  s?     )).9 	AH$H  $$dii&?@	Arp   c                 &    d| i}t        d|      }|S r0  r   r   s        ro   r   zAddQuestionForm.as_p  r1  rp   N)rr   rs   rt   ru   r   r   rZ   r    r   r   r  r*   r  r  r   r   rp   ro   r  r    sg     "L1511"**..0L 2511''++-[LArp   r  )r|   r   r   r   r   r  
created_at
created_bymodified_byr   last_updatedhorilla_historyc            
       N   e Zd Zej                  j                         ZeD  cg c]F  }t        |d      r8|j                  t        vr&|j                  |j                  j                         fH c}}}} Zedgz   Z ej                  eej                  g d      Zyc c}}}} w )CandidateExportFormr   )rejected_candidate__descriptionzRejected Description)r   r   r   r   r   r   r   r  )r   rG   rK   N)rr   rs   rt   r   r   
get_fieldsmodel_fieldshasattrr   exclude_fieldsr   
capitalizefield_choicesr   MultipleChoiceFieldr^   selected_fields).0ri   r  r  s   0000ro   r  r    s    ??--/L " 5.)ejj.N 
U''2245M
 "C% M 0e//++	
Os   AB
r  c                   ,    e Zd ZddddZ G d d      Zy)SkillZoneCreateFormr_  r  c                       e Zd ZdZeZdZdgZy)SkillZoneCreateForm.Metarf  r   r   N)rr   rs   rt   ru   r%   r   rB   r   r   rp   ro   r   r    s    	 -rp   r   Nrr   rs   rt   r;   r   r   rp   ro   r  r    s    "=D   rp   r  c                        e Zd ZddddZdZ ej                  ej                  j                         ej                   ed            Z G d d      Zd Zd	 Zd fdZdded
ef fdZ xZS )SkillZoneCandidateFormr_  )skill_zone_idr[  reasonzSkill Zone Candidater   r   c                        e Zd ZdZeZdZddgZy)SkillZoneCandidateForm.Metarf  r   added_onr   N)rr   rs   rt   ru   r&   r   rB   r   r   rp   ro   r   r  3  s     	 #
rp   r   c                 &    d| i}t        d|      }|S r0  r   r   s        ro   r   zSkillZoneCandidateForm.as_p?  r1  rp   c                     | j                   d   }|D ]'  }t        |t              rt        j                  d       |j                         S )Nr[  zInvalid candidate selected.)r   rI   r   r   r
   ra   )rb   selected_candidatesr  s      ro   clean_candidate_idz)SkillZoneCandidateForm.clean_candidate_idG  sS    "//? - 	KIi3++,IJJ	K #((**rp   rL  c                    t        |   |i | d | j                  d   _        | j                  j
                  r| j                  j                  j                  dz   | j                  j                  j                  z   | _
        t        j                  t        j                  j                         t        j                   ddi      t#        d            | j                  d<   y y )Nr[  z / r0   zoh-select oh-select2 w-100r   r   r   )r@   rA   rB   r[   r   r   r[  r   r  rX   r   r   r   r   r   r   rY   rH   r   s      ro   rA   zSkillZoneCandidateForm.__init__Q  s    $)&)26N#/==**//----334 
 +0*@*@"**..0||74P*QRn+DKK' rp   r   c                    | j                   j                  st        j                  j	                  t        | j                  j                  d                  }| j                  d   }| j                  d   }|D ]1  }t               }||_
        ||_        ||_        |j                          3 | j                   S t        | 5         }| j                   S )Nr[  )id__inr  r  )r   r   r   r   r   r   r   r   r   r&   r  r[  r  r  r@   )	rb   r   
candidates
skill_zoner  r  	zone_candr   rn   s	           ro   r  zSkillZoneCandidateForm.save`  s    }}"**11TYY..~>@ 2 J **?;J&&x0F' !	.0	*4	')2	&#)	  ! }} w|~H}}rp   r  r  )rr   rs   rt   r;   r   r   rZ   r   r   r   SelectMultiplerH   r[  r   r   r  rA   r  r&   r  rv   rw   s   @ro   r  r  )  sz    rBD)L1511""&&(##nL

 

+4 +=  rp   r  c                        e Zd ZdZ ej
                  ej                  j                          e	d            Z
dddZ G d d      Z fdZd	 Z xZS )
ToSkillZoneFormzAdd To Skill ZonezSkill Zonesr   r_  )r  skill_zone_idsc                   ,    e Zd ZdZeZdZg dZeddiiZ	y)ToSkillZoneForm.Metarf  r   )r  r   r[  unique_togetherz.This candidate alreay exist in this skill zoneN)
rr   rs   rt   ru   r&   r   rB   r   r	   error_messagesr   rp   ro   r   r  }  s1    	 #
 !#S
rp   r   c                 j   t         |          }|j                  d      }|j                  d      }g }|D ]C  }t        j                  j                  ||      j                         s3|j                  |       E t        |      dkD  r)dj                  d |D              }t        | d| d      |S )	Nr[  r  )r[  r  r   rt  c              3   2   K   | ]  }t        |        y wrD  )str)r  r  s     ro   	<genexpr>z(ToSkillZoneForm.clean.<locals>.<genexpr>  s      ($.J(s   z already exists in .)r@   r   rP   r&   r   r   rq  rO  lenrv  r
   )rb   r   r  skill_zonesskill_zone_listr  skill_zones_strrn   s          ro   r   zToSkillZoneForm.clean  s    w} $$^4	"&&'78% 	3J!))00&j 1 fh  &&z2	3 !#"ii (2A( O "YK/B?BSST"UVV rp   c                 &    d| i}t        d|      }|S r0  r   r   s        ro   r   zToSkillZoneForm.as_p  r1  rp   )rr   rs   rt   r   r   rZ   r%   r   r   rH   r  r;   r   r   r   rv   rw   s   @ro   r  r  t  sS    &L3U33""&&(-0@N B/D
 
$*rp   r  c                   :    e Zd ZdZddddZdZ G d d      Zd Zy)	RejectReasonFormz
    RejectReasonForm
    r_  r  zReject Reasonc                       e Zd ZeZdZdgZy)RejectReasonForm.Metar   r   N)rr   rs   rt   r"   r   rB   r   r   rp   ro   r   r    s    -rp   r   c                 &    d| i}t        d|      }|S r0  r   r   s        ro   r   zRejectReasonForm.as_p  r1  rp   Nr  r   rp   ro   r  r    s)     "=D"L   
rp   r  c                   J     e Zd ZdZdZdddZ G d d      Zd Z fdZ xZ	S )	RejectedCandidateFormz
    RejectedCandidateForm
    zRejected Candidater_  )reject_reason_idr   c                       e Zd ZeZdZdgZy)RejectedCandidateForm.Metar   r   N)rr   rs   rt   r!   r   rB   r   r   rp   ro   r   r        !-rp   r   c                 &    d| i}t        d|      }|S r0  r   r   s        ro   r   zRejectedCandidateForm.as_p  r1  rp   c                     t        |   |i | d | j                  d   _        | j                  d   j	                         | j                  d   _        y )Nr  r[  )r@   rA   rB   r[   r&  rG   r   s      ro   rA   zRejectedCandidateForm.__init__  sJ    $)&)6:&'3-1[[-H-V-V-XN#*rp   )
rr   rs   rt   ru   r   r;   r   r   rA   rv   rw   s   @ro   r  r    s4     (L "26D   
Y Yrp   r  c                   Z     e Zd ZdZddddddZdZ G d d      Z fdZ fdZd	 Z	 xZ
S )
ScheduleInterviewFormz
    ScheduleInterviewForm
    r_  )interview_dateinterview_timer[  r   r=   zSchedule Interviewc                       e Zd ZeZdZdgZy)ScheduleInterviewForm.Metar   r   N)rr   rs   rt   r   r   rB   r   r   rp   ro   r   r    r  rp   r   c                    t        |   |i | t        j                  ddd      | j                  d   _        t        j                  ddd      | j                  d   _        dd	d
dd	dd}| j                  j                  r$|dxx   d| j                  j                   z  cc<   | j                  d   j
                  j                  j                  |       y )Nr   r.   )r   r0   r   r  r3   r  z#InterviewCreateFormz#id_employee_id_parent_divz#/recruitment/get-interview-managers	innerHTMLzchange, load delay:300ms)z
hx-includez	hx-targethx-getzhx-swapz	hx-selectz
hx-triggerr  z?pk=r[  )r@   rA   r   rJ   rB   rG   rR   r   r   rO   rQ   )rb   rc   rd   candidate_attrrn   s       ro   rA   zScheduleInterviewForm.__init__  s    $)&)/4!,<=0
$%, 05!,<=0
$%, 15;"54
 ==8$$t}}/?/?.@(AA$N#**0077Grp   c                 "   | j                   }t        | 	         }|j                  d      }|j                  d      }|d   }|j                  s4|r2|t        j                         k  r| j                  dt        d             |j                  sg|ret        j                         j                         }|j                  s7|t        j                         k(  r ||k  r| j                  dt        d             t        j                  d      r$ddlm} |j                   j#                  |d	
      }ng }|D 	cg c].  }	||	j%                         v r|	j&                  j)                         0 }
}	|
r| j                  dt        |
 d             |S c c}	w )Nr  r  r=   z%Interview date cannot be in the past.z%Interview time cannot be in the past.leaver   )LeaveRequestapproved)employee_id__instatusz! have approved leave on this date)r   r@   r   rP   r   r   rD   	add_errorrH   r   rE   r3   r   is_installedleave.modelsr  r   r   requested_datesr=   get_full_name)rb   r   r   r  r  managersrE   r  leave_employeesr  	employeesrn   s              ro   r   zScheduleInterviewForm.clean
  sh   ==w}%))*:;%))*:;.{{~.4::<2ONN+Q/V-WX{{~,,.%%'CKK"djjl2"S($a(O&P W%1*2299 ( : O !O )
!6!6!88 ++-
	 
 NNqI;.O!PQ 
s   53Fc                 &    d| i}t        d|      }|S r0  r   r   s        ro   r   zScheduleInterviewForm.as_p5  r1  rp   )rr   rs   rt   ru   r;   r   r   rA   r   r   rv   rw   s   @ro   r  r    sB    
 D (L   
H,)Vrp   r  c                   (    e Zd ZddiZ G d d      Zy)
SkillsFormrX   r_  c                       e Zd ZeZdgZy)SkillsForm.MetarX   N)rr   rs   rt   r$   r   rB   r   rp   ro   r   r  C  s    rp   r   Nr  r   rp   ro   r  r  >  s    D rp   r  c                   2     e Zd Z G d d      Z fdZ xZS )
ResumeFormc                   >    e Zd ZeZddgZd ej                         iZy)ResumeForm.Metafiler   N)	rr   rs   rt   r#   r   rB   r   HiddenInputr   r   rp   ro   r   r  I  s(    *+#%6U%6%6%89rp   r   c                     t        |   |i | | j                  d   j                  j                  j                  ddi       y )Nr  r   zsubmitForm($(this)))r@   rA   rB   rG   rO   rQ   r   s      ro   rA   zResumeForm.__init__N  sC    $)&)F""((//1	
rp   r\  rw   s   @ro   r  r  H  s    : :

 
rp   r  c                        e Zd Z G d d      Zy)CandidateDocumentRequestFormc                       e Zd ZeZdZdgZy)!CandidateDocumentRequestForm.Metar   r   N)rr   rs   rt   r   r   rB   r   r   rp   ro   r   r   X  s    (-rp   r   N)rr   rs   rt   r   r   rp   ro   r  r  W  s       rp   r  c                   (    e Zd ZdZdZ G d d      Zy)CandidateDocumentUpdateFormzform to Update a Documentr   c                       e Zd ZeZdZddgZy) CandidateDocumentUpdateForm.Metar   r   document_request_idN)rr   rs   rt   r   r   rB   r   r   rp   ro   r   r$  c  s    ! 56rp   r   N)rr   rs   rt   ru   r   r   r   rp   ro   r"  r"  ^  s    #&L7 7rp   r"  c                   6     e Zd ZdZ G d d      Z fdZ xZS )CandidateDocumentRejectFormz7form to add rejection reason while rejecting a Documentc                       e Zd ZeZdgZy) CandidateDocumentRejectForm.Metareject_reasonN)rr   rs   rt   r   r   rB   r   rp   ro   r   r)  l  s    !!"rp   r   c                 p    t        |   |i | d| j                  d   j                  j                  d<   y )NTr*  r   )r@   rA   rB   rG   rO   r   s      ro   rA   z$CandidateDocumentRejectForm.__init__p  s4    $)&)@DO$++11*=rp   r(  rw   s   @ro   r'  r'  i  s    A# #E Erp   r'  c                   .    e Zd ZdZdZ G d d      Zd Zy)CandidateDocumentFormzform to create a new DocumentDocumentc                   B    e Zd ZeZdZg dZd ej                         iZ	y)CandidateDocumentForm.Metar   )r%  r  r*  r   r=   N)
rr   rs   rt   r   r   rB   r   r   r  r   r   rp   ro   r   r0  z  s)    !Q,5,,.
rp   r   c                 &    d| i}t        d|      }|S r   r   )rb   r   r   s      ro   r   zCandidateDocumentForm.as_p  r   rp   N)rr   rs   rt   ru   r   r   r   r   rp   ro   r-  r-  u  s    'L
 
rp   r-  c                   $    e Zd ZdZ G d d      Zy)StageChangeFormz
    StageChangeForm
    c                       e Zd ZdZeZdgZy)StageChangeForm.Metaz3
        Meta class for additional options
        r   Nr-  r   rp   ro   r   r5    s    	 
rp   r   Nrr   rs   rt   ru   r   r   rp   ro   r3  r3        
 
rp   r3  c                   $    e Zd ZdZ G d d      Zy)LinkedInAccountFormz
    LinkedInAccount form
    c                       e Zd ZeZg dZy)LinkedInAccountForm.Meta)usernamer   	api_tokenr   r>   N)rr   rs   rt   r   r   rB   r   rp   ro   r   r;    s    
rp   r   Nr6  r   rp   ro   r9  r9    r7  rp   r9  )eru   loggingr~   astr   r   r   typingr   djangor   django.appsr   django.core.exceptionsr	   r
   django.template.loaderr   django.utils.translationr   rH   
base.formsr   r   BaseModelFormbase.methodsr   base.widgetsr   employee.filtersr   employee.modelsr   horillar   horilla.horilla_middlewaresr   2horilla_widgets.widgets.horilla_multi_select_fieldr   &horilla_widgets.widgets.select_widgetsr   r  r   recruitment.modelsr   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   	getLoggerrr   loggerry   r   r   r   r   r  r  r*  r3  ClearableFileInputr9  	FileFieldr<  rF  rV  r^  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r"  r'  r-  r3  r9  r   rp   ro   <module>rU     sc  .    #    D 3 6  1 ( . + $ ' 6 V K     * 
		8	$p pfMu MD5M5?? 5MpVm Vr& &RjM jZS!& S!l-l -62y 2j' '4#00 #+ + *1I *1Z-) - BL9 BLJ (

  = .d : %** 4 -  HY HV6i 6ry .YI Y8[M [| 
 
 9  7) 7	E) 	EI ,
eoo 
 
- 
rp   