
    siZ                        d Z ddl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mZ ddlmZmZmZmZmZmZmZmZmZmZmZ  G d d	e      Zd
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                        Z  G d d      Z! G d de	      Z" G d de      Z# G d de      Z$ G d d e	      Z%y)!zJ
filters.py

This page is used to register filter for recruitment models

    N)forms)gettext_lazy)	FilterSet)HorillaFilterSetfilter_by_name)	CandidateInterviewScheduleLinkedInAccountRecruitmentRecruitmentSurveyRejectReasonSkill	SkillZoneSkillZoneCandidateStageSurveyTemplatec                   <    e Zd ZdZ ej
                  dd      Z ej
                  dd      Z ej
                  dd      Z ej                  e
j                  j                         d      Z ej
                  d	d      Z ej                  d
 ej"                  ddi            Z ej                  d ej"                  ddi            Z ej                  dd ej"                  ddi            Z ej                  d ej"                  ddi            Z ej                  dd ej"                  ddi            Z ej                  dd ej"                  ddi            Z ej                  d ej"                  ddi            Z ej                  d ej"                  ddi            Z ej                  d ej"                  ddi            Z ej                  dd ej"                  ddi            Z ej
                  dd      Z ej:                  ddej<                  j?                               Z  ej:                  ddej<                  j?                               Z!d Z"d Z# G d d       Z$ fd!Z%d" Z&d# Z'd$ Z( xZ)S )%CandidateFilter}
    Filter set class for Candidate model

    Args:
        FilterSet (class): custom filter set class to apply styling
    name	icontains
field_namelookup_exprsearch_by_name)methodr   start_onboard_method)querysetr   pipeline_searchrecruitment_id__start_datetypedateattrsr   widgetrecruitment_id__end_date#candidate_interview__interview_dategter   r   r&   probation_endlteschedule_date
hired_daterecruitment_id__titleonboarding_portalfilter_mail_sent)r   r   r&   joining_datefilter_joining_setc                     |j                  |      |j                  |      z  |j                  |      z  j                         }|S )zc
        This method is used to include the candidates when they in the recruitment/stages
        name__icontainsstage_id__stage__icontains*stage_id__recruitment_id__title__icontainsfilterdistinctselfr   _values       7/var/www/python-projects/worksol/recruitment/filters.pyr   zCandidateFilter.pipeline_searchs   sO    
 OOEO2ooo?@oooOP (*	 	
     c                     |j                  |      |j                  |      z  |j                  |      z  }|j                         S )z'
        search by name method
        r5   r7   r9   r;   r>   s       rB   r   zCandidateFilter.search_by_name~   sP    
 OOEO2ooo?@oooOP 	
   ""rC   c                       e Zd ZdZeZg dZy)CandidateFilter.Meta7
        Meta class to add the additional info
        )"recruitmentrecruitment_idstage_idr-   r(   emailmobilecountrystatecityzipgenderstart_onboardhired	convertedcanceled	is_activerecruitment_id__company_idjob_position_idrecruitment_id__closedrecruitment_id__is_activejob_position_id__department_id$recruitment_id__recruitment_managersstage_id__stage_managersstage_id__stage_typer2   %skillzonecandidate_set__skill_zone_id$skillzonecandidate_set__candidate_idportal_sentjoining_set$rejected_candidate__reject_reason_idoffer_letter_statuscandidate_rating__rating candidate_interview__employee_idN)__name__
__module____qualname____doc__r   modelfields rC   rB   MetarF      s    	 #
rC   rn   c                    t        |   |i | | j                  j                  }d|d   _        |D ]9  }t        t        j                               ||   j                  j                  d<   ; | j                  |       y )NTrV   id)super__init__formrl   initialstruuiduuid4r&   r$   _update_field_labels)r?   argskwargsform_fieldsfield	__class__s        rB   rr   zCandidateFilter.__init__   sx    $)&)ii&&+/K (  	FE47

4EK%%++D1	F 	!!+.rC   c                    t               t               t               d}|d   j                  j	                  d      j
                  }|| d| dt        d      t        d      t        d      t        d	      |d
   j                  j	                  d      j
                  |d   j                  j	                  d      j
                  |d   j                  j	                  d      j
                  |d   j                  j	                  d      j
                  |d   j                  j	                  d      j
                  |d   j                  j	                  d      j
                  d}|j                         D ]  \  }}||v s|||   _         y)z=Helper method to update field labels from model verbose names)rH   	interview
skill_zoner   interview_date From TillReject Reason
Departmentz
Stage TypezStage Managersr   skill_zone_idrH   
start_dateend_date
company_idclosedrecruitment_managers)r   scheduled_fromscheduled_tillrc   r[   r^   r]   r_   r   r   rW   rY   r\   N)	r   r	   r   _meta	get_fieldverbose_namer@   itemslabel)r?   r{   modelsinterview_date_labelfield_label_mapr   r   s          rB   rx   z$CandidateFilter._update_field_labels   s_    '=*,,.
 ;%%//0@ANN 	
 3!5 6e<!5 6e<45o4F./o$%lO()*:(;5;L5IU99_-\ /U99\*\}-33==jIVV*0*?U99\*\&,]&;U99X&\4:=4IU9934\/
4 "1!6!6!8 	6J[(05J'-	6rC   c                 (    |j                  |       S )N)onboarding_portal__isnullr<   r?   r   r   rA   s       rB   r1   z CandidateFilter.filter_mail_sent   s    e)EErC   c                 (    |j                  |       S )N)joining_date__isnullr   r   s       rB   r3   z"CandidateFilter.filter_joining_set   s    Y@@rC   )*rg   rh   ri   rj   django_filters
CharFilterr   searchrR   ModelMultipleChoiceFilterr   objectsall	candidatecandidate_name
DateFilterr   	DateInputr   r   r   r+   probation_end_tillprobation_end_fromr-   r.   r   r   rH   BooleanFilterwidgetsBooleanWidgetra   rb   r   r   rn   rr   rx   r1   r3   __classcell__r}   s   @rB   r   r   !   s    %>$$KPD&^&&.>KXF-N--%;M 988""&&(I
 /^.. kN +**/uff%56J )~((-uff%56H /^..8uff%56N
 .N--"uff%56M 322"uff%56
 322"uff%56
 .N--"uff%56M +**uff%56J /^..8uff%56N /^..8uff%56N
 ,.++*K /...&!%%335K
 /...!#%%335K		#)
 )
V	/)6VFArC   r   )) r   )falseFalse)trueTruec                   J    e Zd ZdZ ej
                  dd      Z ej
                  dd      Z ej
                  d      Z ej                  d e
j                  d	d
i            Z ej                  d e
j                  d	d
i            Z ej                  dd e
j                  d	d
i            Z ej                  dd e
j                  d	d
i            Z ej
                  d      Z ej"                  ddg      Z G d d      Z fdZd Zd Zd Z xZS )RecruitmentFilterz
    Filter set class for Recruitment model

    Args:
        FilterSet (class): custom filter set class to apply styling
    titler   r   r   onboarding_searchr   )r   r   r!   r"   r#   r%   r   r)   r*   r,   r   r   )TYes)FNo)choicesc                       e Zd ZdZeZg dZy)RecruitmentFilter.MetarG   )r   r   r   is_event_basedr   r   r   rV   is_publishedrX   open_positionsN)rg   rh   ri   rj   r   rk   rl   rm   rC   rB   rn   r     s    	 
rC   rn   c                    t        |   |i | | j                  j                  j                  j                  d      j                  }| j                  j                  j                  j                  d      j                  }| d| j                  j                  d   _	        | d| j                  j                  d   _	        y )Nr   r   r   
start_fromr   end_till)
rq   rr   rn   rk   r   r   r   rs   rl   r   )r?   ry   rz   start_date_verboseend_date_verboser}   s        rB   rr   zRecruitmentFilter.__init__3  s    $)&)!YY__22<<\JWW99??00:::FSS2D1EU/K		&,0@/A-G		$*rC   c                    |j                         }|d   }t        |      dkD  rdj                  |dd       nd}|j                  |      |j                  |      z  |j                  |      z  |j                  |	      z  }|r|r|j                  ||
      }n)|r|j                  |      }n|r|j                  |      }||z  }|j	                         S )=
        Filter queryset by first name or last name.
        r       Nr   )'open_positions__job_position__icontainstitle__icontainsstage_set__stage__icontains)%stage_set__candidate__name__icontains)4recruitment_managers__employee_first_name__icontains3recruitment_managers__employee_last_name__icontains)r   )r   splitlenjoinr<   r=   )r?   r   r@   rA   parts
first_name	last_namejob_querysets           rB   r   z RecruitmentFilter.filter_by_name:  s    
 1X
+.u:>CHHU12Y'r	 OOEOJoouo56oo%o@A ooEoJK 	 )EODM ' H EO ' H DM ' H l*  ""rC   c                     |j                  |      |j                  |      z  |j                  |      z  }|j                         S );
        This method is used to search recruitment
        r   r   candidate__name__icontainsr;   r>   s       rB   r   z!RecruitmentFilter.pipeline_searchZ  sP    
 OOUO3oo%o@Aooo?@ 	
   ""rC   c                     |j                  |      |j                  |      z  |j                  |      z  }|j                         S )r   r   )(onboarding_stage__stage_title__icontains):candidate__onboarding_stage__candidate_id__name__icontainsr;   r>   s       rB   r   z#RecruitmentFilter.onboarding_searche  sU    
 OOUO3oouoMNooKP   	   ""rC   )rg   rh   ri   rj   r   r   r   search_onboardingdescriptionr   r   r   r   r   r   r   r   ChoiceFilterrV   rn   rr   r   r   r   r   r   s   @rB   r   r      sM    /^..#4N 211#6 ,.++DK***vv>N(OJ )~((oeooVV<L&MH +**uff%56J
 )~((uff%56H
 '^&&.>?F+++
I
 
(H#@	##rC   r   c                   H    e Zd Z ej                  dd      Z G d d      Zy)SkillsFilterr   r   r   c                       e Zd ZeZdgZy)SkillsFilter.Metar   N)rg   rh   ri   r   rk   rl   rm   rC   rB   rn   r   w  s    
rC   rn   Nrg   rh   ri   r   r   r   rn   rm   rC   rB   r   r   s       &^&&'{SF
 
rC   r   c                   H    e Zd Z ej                  dd      Z G d d      Zy)RejectReasonFilterr   r   r   c                       e Zd ZeZdgZy)RejectReasonFilter.Metar   N)rg   rh   ri   r   rk   rl   rm   rC   rB   rn   r     s    
rC   rn   Nr   rm   rC   rB   r   r   ~  r   rC   r   c                   |    e Zd ZdZ ej
                  d      Z ej
                  d      Z G d d      Zd Z	d Z
y	)
StageFilterzy
    Filter set class for Stage model

    Args:
        FilterSet (class): custom filter set class to apply styling
    r   r   r   c                       e Zd ZdZeZg dZy)StageFilter.MetarG   )rI   recruitment_id__job_position_id.recruitment_id__job_position_id__department_idrW   r\   stage_managers
stage_typeN)rg   rh   ri   rj   r   rk   rl   rm   rC   rB   rn   r     s    	 
rC   rn   c                    |j                         }|d   }t        |      dkD  rdj                  |dd       nd}|j                  |      |j                  |      z  |j                  |      z  }|j                  |	      }|r|r|j                  ||
      }n)|r|j                  |      }n|r|j                  |      }||z  |z  }|j	                         S )r   r   r   r   Nr    recruitment_id__title__icontainsr   )5recruitment_id__stage_set__candidate__name__icontainsstage__icontains).stage_managers__employee_first_name__icontains-stage_managers__employee_last_name__icontains)r   )r   r   )	r?   r   r@   rA   r   r   r   recruitment_querystage_querysets	            rB   r   zStageFilter.filter_by_name  s    
 1X
+.u:>CHHU12Y'r	OOUOCooo?@ooFK   	 "%@)?I>G ' H ?I ' H >G ' H n,/@@  ""rC   c                     |j                  |      |j                  |      z  |j                  |      z  }|j                         S )r   r   r   r   r;   r>   s       rB   r   zStageFilter.pipeline_search  sP    
 OOUO3ooo?@oouoEF 	
   ""rC   N)rg   rh   ri   rj   r   r   r   r   rn   r   r   rm   rC   rB   r   r     sD     '^&&.>?F.^..6GHN
 
  #D	#rC   r   c                   x    e Zd ZdZ ej
                  ddd      Z ej
                  ddd      Z G d d	      Zy
)SurveyFilterz
    SurveyFIlter
    r   Optionsoptionsr   r   r   Questionquestionc                       e Zd ZdZeZdZdgZy)SurveyFilter.Meta3
        class Meta for additional options
        __all__sequenceN)rg   rh   ri   rj   r   rk   rl   excluderm   rC   rB   rn   r    s    	 "
rC   rn   N)	rg   rh   ri   rj   r   r   r  r  rn   rm   rC   rB   r  r    sK     (n''G )~((H	
 	
rC   r  c                   N    e Zd ZdZ ej
                  ddd      Z G d d      Zy)	SurveyTemplateFilterz
    SurveyTemplateFilter
    r   Titler   r  c                       e Zd ZeZdZy)SurveyTemplateFilter.Metar
  N)rg   rh   ri   r   rk   rl   rm   rC   rB   rn   r    s    rC   rn   N)rg   rh   ri   rj   r   r   r  rn   rm   rC   rB   r  r    s.     )~((H rC   r  c                       e Zd ZdZg dZy)CandidateReGroupz:
    Class to keep the field name for group by option
    ))r   select)rI   r   )rX   zJob Position)rS   Hired)rM   Country)rJ   r   )r2   zDate Joining)r+   zProbation End)rd   zOffer Letter Status)rc   r   )r_   z
Skill ZoneN)rg   rh   ri   rj   rl   rm   rC   rB   r  r    s    FrC   r  c                   L    e Zd ZdZ ej
                  dd      Z G d d      Zy)SkillZoneFilterz
    Skillzone Filter
    r   r   r   c                       e Zd ZdZeZg dZy)SkillZoneFilter.Metar	  )rV   r`   4skillzonecandidate_set__candidate_id__recruitment_id5skillzonecandidate_set__candidate_id__job_position_id:skillzonecandidate_set__candidate_id__stage_id__stage_typeN)rg   rh   ri   rj   r   rk   rl   rm   rC   rB   rn   r    s    	 
rC   rn   N)rg   rh   ri   rj   r   r   r   rn   rm   rC   rB   r  r    s'     '^&&'{SF
 
rC   r  c                      e Zd ZdZ ej
                  dd      Z ej                  d ej                  ddi      	      Z
 ej                  d
 ej                  ddi      	      Z ej                  dd ej                  ddi       ed            Z ej                  d ej                  ddi      	      Z ej                  dd ej                  ddi       ed            Z ej                  dd ej                  ddi       ed            Z ej                  d ej                  ddi      	      Z ej                  dd ej                  ddi       ed            Z ej
                  dd      Z ej(                  ddej*                  j-                          ed            Z ej(                  ddej*                  j-                          ed            Z G d d      Zd  Zy!)"SkillZoneCandFilterz$
    Skillzone Candidate FIlter
    candidate_id__namecand_searchr   )candidate__id__recruitment_id__start_dater!   r"   r#   r%   'candidate__id__recruitment_id__end_datecandidate__id__joining_dater)   zJoining From)r   r   r&   r   candidate__id__probation_endr,   zProbation TillzProbation Fromcandidate__id__schedule_datezJoining Till$candidate__id__recruitment_id__titler   r    candidate__id__onboarding_portalr1   zPortal Sent)r   r   r&   r   r3   zJoining Setc                   $    e Zd ZdZeZg dZddgZy)SkillZoneCandFilter.Metar	  )rV   candidate_idcandidate_id__recruitment_idcandidate_id__stage_idcandidate_id__schedule_datecandidate_id__emailcandidate_id__mobilecandidate_id__countrycandidate_id__statecandidate_id__citycandidate_id__zipcandidate_id__gendercandidate_id__start_onboardcandidate_id__hiredcandidate_id__canceledcandidate_id__is_active(candidate_id__recruitment_id__company_idcandidate_id__job_position_id$candidate_id__recruitment_id__closed'candidate_id__recruitment_id__is_active,candidate_id__job_position_id__department_id2candidate_id__recruitment_id__recruitment_managers&candidate_id__stage_id__stage_managers"candidate_id__stage_id__stage_typecandidate_id__joining_date3candidate_id__skillzonecandidate_set__skill_zone_id2candidate_id__skillzonecandidate_set__candidate_id2candidate_id__rejected_candidate__reject_reason_id!candidate_id__offer_letter_status&candidate_id__candidate_rating__ratingreasonr   N)rg   rh   ri   rj   r   rk   rl   r  rm   rC   rB   rn   r*  j  s%    	 #
B 
rC   rn   c                 h    |j                  |      |j                  |      z  j                         S )zI
        This method to include candidate when search skill zone
        )candidate_id__name__icontains)skill_zone_id__title__icontainsr;   r>   s       rB   r!  zSkillZoneCandFilter.cand_search  s2    
 OO%O@ooeoDE
(*	rC   N)rg   rh   ri   rj   r   r   r   r   r   r   r   r   r@   r   r+   r   r   r-   r   rH   r   r   r   ra   rb   rn   r!  rm   rC   rB   r  r  )  s1    '^&&'F +**>uff%56J )~((<uff%56H /^..0uff%56	N .N--1uff%56M 3221uff%56 !	 3221uff%56 !	 .N--1uff%56M /^..0uff%56	N ,.++9{K /...5!%%335	K /...0#%%335	K)
 )
VrC   r  c                        e Zd ZdZ ej
                  dd      Z ej                  dd ej                  ddi	      
      Z
 ej                  dd ej                  ddi	      
      Z G d d      Z fdZ xZS )InterviewFilterr   r   r   r   r   r)   r!   r"   r#   r*   r,   c                       e Zd ZdZeZg dZy)InterviewFilter.MetarG   )r+  employee_idr   N)rg   rh   ri   rj   r	   rk   rl   rm   rC   rB   rn   rO    s    	 "
rC   rn   c                 l   t        |   |i | | j                  j                         j                  j                  d      j                   d| j                  d   _        | j                  j                         j                  j                  d      j                   d| j                  d   _        y )Nr   r   r   r   r   )	rq   rr   rn   rk   r   r   r   rs   r   )r?   ry   rz   r}   s      rB   rr   zInterviewFilter.__init__  s    $)&)yy &&001ABOOPPUV 			"#) yy &&001ABOOPPUV 			"#)rC   )rg   rh   ri   rj   r   r   r   r   r   r   r   r   rn   rr   r   r   s   @rB   rM  rM    s     '^&&'[F /^..#uff%56N
 /^..#uff%56N

 


 
rC   rM  c                   V    e Zd ZdZ ej
                  d      Z G d d      ZdefdZ	y)	LinkedInAccountFilterzLinkedInAccount filtersearch_methodr   c                       e Zd ZeZg dZy)LinkedInAccountFilter.Meta)usernamerK   r   N)rg   rh   ri   r
   rk   rl   rm   rC   rB   rn   rV    s    4rC   rn   rA   c                     |j                  d      }|j                  j                  j                         }|D ]*  }||j	                  |      z  |j	                  |      z  }, |j                         S )z0Method is used to search through LinkedInAccountr   )username__icontains)email__icontains)r   rk   r   noner<   r=   )r?   r   r@   rA   valuesemptyr   s          rB   rT  z#LinkedInAccountFilter.search_method  st    S!&&++- 	E??u?=???E?:< 	 ~~rC   N)
rg   rh   ri   rj   r   r   r   rn   ru   rT  rm   rC   rB   rS  rS    s-     &^&&o>F5 5
  
 rC   rS  )&rj   rv   r   djangor   django.utils.translationr   r@   base.filtersr   horilla.filtersr   r   recruitment.modelsr   r	   r
   r   r   r   r   r   r   r   r   r   BOOLEAN_CHOICESr   r   r   r   r  r  r  r  r  rM  rS  rm   rC   rB   <module>rd     s       6 " <   "MA& MA`x#( x#v
9 

 
F#" F#R
# 
:>33   (
i 
,s* sl*
& *
Z I  rC   