
    si95                        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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 ddlmZ ddl m!Z! ddl"m#Z#m$Z$m%Z%m&Z& ddl'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. G d! d"e      Z/ G d# d$ej,                        Z0y)%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)date)Any)forms)UserCreationForm)User)	DateInputValidationErrorrender_to_string)gettext_lazy)	ModelForm)reload_queryset)EmployeeFilter)EmployeeEmployeeBankDetails)HorillaMultiSelectField)HorillaMultiSelectWidget)CandidateStageCandidateTaskOnboardingStageOnboardingTask)	Candidatec                   "     e Zd ZdZ fdZ xZS )UserCreationFormCustomz<
    Overriding user creation form to apply some styles
    c                    t        |   |i | t        | j                         | j                  j	                         D ]8  \  }}|j
                  }t        |t        j                  t        j                  t        j                  t        j                  f      r3|j
                  j                  j                  d|j                  d       t        |t        j                        r(|j
                  j                  j                  ddi       t        |t        j                  t        j                  t        j                  f      r4|j
                  j                  j                  d|j                  d       =t        |t        j                   f      r>d|j                   d|_        |j
                  j                  j                  ddi       t        |t        j$                        r6|j
                  j                  j                  d|j                  d	d
d       t        |t        j&                  t        j(                  f      s|j
                  j                  j                  ddi       ; y )Nz!oh-input oh-input--password w-100)classplaceholderr   z oh-input oh-calendar-input w-100zoh-input w-100z
---Choose z---z/oh-select oh-select-2 select2-hidden-accessible   (   )r   r   rowscolszoh-switch__checkbox)super__init__r   fieldsitemswidget
isinstancer   NumberInput
EmailInput	TextInputPasswordInputattrsupdatelabel	DateFieldSelectempty_labelTextareaCheckboxInputCheckboxSelectMultiple)selfargskwargs_fieldr&   	__class__s         4/var/www/python-projects/worksol/onboarding/forms.pyr#   zUserCreationFormCustom.__init__7   s   $)&)$))+ .	LHAu\\F%%$$OO''	 ""))!D',{{ FU__6""))74V*WX**E,<,<eooN "")).u{{K FU\\O4&0S$A!""))OP FU^^5""))!1',{{ ! "	 ''00 ""))74I*JK].	L    )__name__
__module____qualname____doc__r#   __classcell__r:   s   @r;   r   r   2   s    1L 1Lr<   r   c                   $    e Zd ZdZ G d d      Zy)OnboardingCandidateFormz"
    Form for Candidate model
    c                   f    e Zd ZdZeZdZdZd eddi      iZ	 e
d       e
d	       e
d
      dZy)OnboardingCandidateForm.Meta8
        Meta class for some additional options
        __all__)stage_idassigned_managerconfirmationhiredreferral	portfoliocanceled	is_activeresumeschedule_datejob_position_idjoining_datetyper   r,   z	Full NameEmailMobile)nameemailmobileN)r=   r>   r?   r@   r   modelr$   excluder   widgetsr8   labels r<   r;   MetarF   p   sP    	 
 IVV,<=
 kNwZk
r<   ra   Nr=   r>   r?   r@   ra   r`   r<   r;   rD   rD   k   s    
 
r<   rD   c                   $    e Zd ZdZ G d d      Zy)r   z
    Form for User model
    c                       e Zd ZdZeZddgZy)UserCreationForm.Meta;
        Meta class to add some additional options
        	password1	password2N)r=   r>   r?   r@   r   r\   r$   r`   r<   r;   ra   re      s    	 {+r<   ra   Nrb   r`   r<   r;   r   r      s    , ,r<   r   c                   B    e Zd ZdZ ej
                  ej                  j                         d      Z	 ej                         Z ej                   ed            Z ej
                  ej                  j                               Z G d d      Z fd	Z fd
Z xZS )OnboardingViewTaskFormz'
    Form for OnboardingTask model
    F)querysetrequiredz
Task title)r.   )rk   c                        e Zd ZdZeZdZg dZy)OnboardingViewTaskForm.MetarG   rH   )statuscandidate_idonboarding_task_idrP   N)r=   r>   r?   r@   r   r\   r$   r]   r`   r<   r;   ra   rn      s    	 Or<   ra   c                    | j                   j                         D ]  \  }}t        |t              s| j                  j                  |d        t        | j                  j                  |            dk  rt        j                  |di      t        | 1         }| j                   |   j                  j                  | j                  j                  |            }|||<    t        | 1         }|S )N   zThif field is requiredid__in)r$   r%   r'   r   errorspoplendatagetlistr   r	   r"   cleanrk   filter)r5   
field_namefield_instancecleaned_dataemployee_datar:   s        r;   r{   zOnboardingViewTaskForm.clean   s    *.++*;*;*= 		9&J.*AB
D1tyy((459//=U0VWW$w} $J 7 @ @ G G99,,Z8 !H ! ,9Z(		9 w}r<   c                    t        |   |i | t        t        j                  j                         t        dt        ddd| j                        t        d            | j                  d<   t        | j                         y )	Nemployee-widget-filterfemployee_filters.htmlTfilter_route_namefilter_classfilter_instance_contex_namefilter_template_pathrl   instancezTask Managersrk   r&   r.   managers)r"   r#   r   r   objectsallr   r   r   r8   r$   r   )r5   r6   r7   r:   s      r;   r#   zOnboardingViewTaskForm.__init__   sp    $)&)"9%%))++":+,/%< O$#
J 	$r<   )r=   r>   r?   r@   r   ModelMultipleChoiceFieldr   r   r   
candidatesHiddenInputrI   	CharFieldr8   
task_titler   r   ra   r{   r#   rA   rB   s   @r;   rj   rj      s     0//""&&(J
 !u  "H ,9J-u--!!%%'H
P P% %r<   rj   c                   @     e Zd ZdZ G d d      Z fdZ fdZ xZS )OnboardingTaskFormz&
    Form for OnboardingTaskModel
    c                   L    e Zd ZdZeZdZdgZd ej                  ddi      iZ
y)	OnboardingTaskForm.Meta<
        Meta class for add some additional options
        rH   rP   r   r   z5oh-select oh-select-2 w-100 select2-hidden-accessiblerV   N)r=   r>   r?   r@   r   r\   r$   r]   r   SelectMultipler^   r`   r<   r;   ra   r      s=    	 -.%.. WX
r<   ra   c                    t        	|   |i | t        t        j                  j                         t        dt        ddd| j                        | j                  d   j                        | j                  d<   | j                  j                  d      }|rt        j                  j                  |	      }|j                  }|j                  j                         }|| j                  d   _        |j"                  j                         j%                  d
d      }t&        j                  j)                  |      }|| j                  d   _        y y )Nr   r   r   Tr   employee_idr   rI   )idrp   )flatrt   r   )r"   r#   r   r   r   r   r   r   r   r$   r.   initialgetr   recruitment_idonboarding_stagerk   	candidatevalues_listr   r|   )
r5   r6   r7   rI   stagerecruitmentstage_querysetcandidate_idscand_querysetr:   s
            r;   r#   zOnboardingTaskForm.__init__   s"   $)&)%<%%))++":+,/%< ++m,22&
M" <<##J/#++//8/<E..K )99==?N/=DKK
#,!OO//1==nSW=XM%--44M4JM1>DKK%. r<   c                     t        | j                  d   t              r9| j                  j	                  d      }|r| j
                  j                  dd        t        | !          y Nr   	r'   r$   r   ry   rz   rv   rw   r"   r{   r5   idsr:   s     r;   r{   zOnboardingTaskForm.clean  I    dkk-02IJ))##M2Ct4r<   )r=   r>   r?   r@   ra   r#   r{   rA   rB   s   @r;   r   r      s!    
 
?4 r<   r   c                   F     e Zd ZdZ G d d      Z fdZd Z fdZ xZS )OnboardingViewStageFormz'
    Form for OnboardingStageModel
    c                   >    e Zd ZdZeZg dZ ed       ed      dZy)OnboardingViewStageForm.Metar   )stage_titler   is_final_stager   zStage TitlezIs Final Stage)r   r   N)	r=   r>   r?   r@   r   r\   r$   r8   r_   r`   r<   r;   ra   r     s+    	  S]+ 01
r<   ra   c                    t        |   |i | t        | j                         t	        t
        j                  j                  d      t        dt        ddd| j                        | j                  d   j                        | j                  d<   | j                  j                         D ]I  \  }}t        t        j                               }|j                   j"                  j%                  d	|i       K y
)zN
        Initializes the form with custom field settings and widgets.
        T)rP   r   r   r   r   r   r   r   N)r"   r#   r   r$   r   r   r   r|   r   r   r   r.   r%   struuiduuid4r&   r,   r-   )r5   r6   r7   r}   r9   	unique_idr:   s         r;   r#   z OnboardingViewStageForm.__init__  s     	$)&)$%<%%,,t,<+":+,/%< ++m,22&
M" "&!2!2!4 	9JDJJL)I LL%%tY&78		9r<   c                 &    d| i}t        d|      }|S )zS
        Render the form fields as HTML table rows with Bootstrap styling.
        formzhorilla_form.htmlr
   )r5   r6   r7   context
table_htmls        r;   as_pzOnboardingViewStageForm.as_p5  s      4.%&97C
r<   c                     t        | j                  d   t              r9| j                  j	                  d      }|r| j
                  j                  dd        t        | !          y r   r   r   s     r;   r{   zOnboardingViewStageForm.clean=  r   r<   )	r=   r>   r?   r@   ra   r#   r   r{   rA   rB   s   @r;   r   r   
  s&    

 

94 r<   r   c                       e Zd ZdZ ej
                  d ed            Z ej
                  d ed            Z ej
                  d ed            Z	 ej
                  d ed            Z
 ej
                  d ed	            Z ej
                  d ed
            Z ej
                  d ed            Z ej
                  d ed            Z ej                  d ed            Z ej                  d ed            Z ej
                  d ed            Z ej
                  d ed            Z ej
                  d ed            Z G d d      Z fdZ xZS )EmployeeCreationFormz!
    Form for Employee Model
    Tz
First Namerl   r.   Fz	Last NamePhoneAddressCountryStateZipQualification
ExperienceChildrenzEmergency Contact NumberzEmergency Contact NamezEmergency Contact Relationc                   6    e Zd ZdZeZdZdZd eddi      iZ	y)	EmployeeCreationForm.Metarf   rH   )employee_user_idemployee_profilerZ   rP   additional_infois_from_onboardingis_directly_converteddobrU   r   rV   N)
r=   r>   r?   r@   r   r\   r$   r]   r   r^   r`   r<   r;   ra   r   ^  s2    	 
 9FF#34
r<   ra   c                     | j                   }|d   r|d   dk  rt        dt        d      i      |d   r|d   dk  rt        dt        d      i      t        |          S )N
experiencer   z'Experience should be a postive integierchildrenz+No of children should be a postive integier)r   r	   r8   r"   r{   )r5   r   r:   s     r;   r{   zEmployeeCreationForm.cleanr  s|    ((%,|*Dq*H!q!JKL  
#Z(@1(D!QLMN  w}r<   )r=   r>   r?   r@   r   r   r8   employee_first_nameemployee_last_namephoneaddresscountrystatezipqualificationIntegerFieldr   r   emergency_contactemergency_contact_nameemergency_contact_relationra   r{   rA   rB   s   @r;   r   r   E  sY    *%//4qO(%q~NEOOT7<Eeoot1Y<@Geoot1Y<@GEOOT7<E
%//4qx
8C#EOOT?9KLM###T<IJ!u!!4q}EH'Q9: -U__Q78 "1Q;<"
 
( r<   r   c                      e Zd ZdZ ej
                  dd      Z ej
                  dd      Z ej
                  dd      Z ej                         Z
 ej
                  dd      Z ej
                  dd      Z ej
                  dd	      Z ej
                  dd
      Z ej
                  dd      Z G d d      Zy)BankDetailsCreationFormz*
    Form for BankDetailsCreationForm
    Tz	Bank Namer   zAccount NumberBranchr   r   CityzCode #1FzCode #2c                        e Zd ZdZeZdZg dZy)BankDetailsCreationForm.Metarf   rH   )r   r   rP   N)r=   r>   r?   r@   r   r\   r$   r]   r`   r<   r;   ra   r     s    	 $Ar<   ra   N)r=   r>   r?   r@   r   r   	bank_nameaccount_numberbranchr2   r   r   r   cityany_other_code1any_other_code2ra   r`   r<   r;   r   r     s      [AI$U__d:JKNU__d(;FennGeoot9=GEOOT9E5??D7D%eoot9EO%eoouIFOB Br<   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
        onboarding_stage_idN)r=   r>   r?   r@   r   r\   r$   r`   r<   r;   ra   r     s    	 !
r<   ra   Nrb   r`   r<   r;   r   r     s    
 
r<   r   )1r@   r   datetimer   typingr   djangor   django.contrib.auth.formsr   UserFormdjango.contrib.auth.modelsr   django.formsr   r	   django.template.loaderr   django.utils.translationr   r8   
base.formsr   base.methodsr   employee.filtersr   employee.modelsr   r   2horilla_widgets.widgets.horilla_multi_select_fieldr   &horilla_widgets.widgets.select_widgetsr   onboarding.modelsr   r   r   r   recruitment.modelsr   r   rD   rj   r   r   r   r   r   r`   r<   r;   <module>r     s   .     B + 3 3 6   ( + 9 V K  )6LX 6Lr 
i  
F,- ,6%Y 6%r2 2j8i 8v89 8vBi B2
eoo 
r<   