
    vgc                       d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	mZ ddl
mZ ddlm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!m"Z"m#Z#m$Z$m%Z% ddl&m'Z'm(Z(m)Z) ddl*m+Z+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z<m=Z=m>Z> ddl?m@Z@ ddlAmBZBmCZCmDZDmEZEmFZF ddlGmHZHmIZImJZJmKZK ddlLmMZMmNZN ddlOmPZP ddlQmZ ddlRmSZSmTZTmUZUmVZV ddlWmXZX ddlYmZZZ dd l[m\Z\ dd!l]m^Z^ dd"l_m`Z`maZambZb dd#lcmdZdmeZemfZfmgZgmhZhmiZimjZj dd$lkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z} dd%l~mZ dd&lmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ dd'lmZ dd(Zdd)Zd* ZeUeS eVd+,      d-                      ZeU eVd.,      d/               ZeU eVd0,      eSd1                      Zd2 Zi ZeU ead.,      d3               ZeUeS ead.,      d4                      ZeU ead.      d5               ZeU ead.,      dd6efd7              ZeU ead8,      d9               ZeU ead8,      d:               Zd; ZeUeS ead.,      d<                      ZeU ead8      d=               ZeU eVd.,      d>               ZeU eVd?,      d@               ZeUeS eadA,      dB                      ZeUeS ebd0,      dC                      ZeU ebd0,      dD               ZeU ebd0,      dE               ZeU ead8,      dF               ZeUeS eadG,      dH                      ZeUeS eadI,      ddJ                     ZeUeS eadI,      ddK                     ZeU eadL,      dM               ZeU eadL,      dN               ZeUeSdO               ZeUeSdP               ZeUdQ        ZeUeSdR               ZeUeS eadI,      dS                      ZeU eVd8,      dT               ZeU eadU,      dV               ZeU eVdW,      dX               ZdY ZeU eadA,      eSdZ                      ZeUeS ead[      d\                      ZeU e6d]g      eSd^                      ZeU eVd[,      d_               ZeU eVd[,      d`               ZeU eVda,      db               ZeUeSdc               ZeUdd        ZeU eade,      df               ZeUdg        ZeU eVda,      dh               ZeUeS eVda,      di                      ZeU eada,      dj               ZeU ead8,      dk               ZeU ead8,      dl               ZeU ead8,      dm               ZeU eVdn,      do               ZeUeS ead8,      ddp                     ZeUeS eadq,      dr                      ZeUeS eadq,      ds                      ZeUeS eadt,      du                      ZeUeS eade,      dv                      Zdw ZeU ead8,      dx               ZeU ead8,      dy               ZeU ebdA,      dz               ZeUd{        ZeUd|        ZeUd}        ZeU ead~,      d               ZeUeS ead,      d                      ZeUeS ead,      d                      ZeU ead,      d               ZeU ead,      d               ZeUeS ead~,      d                      ZeU ead,      d               ZeUeS ead,      d                      ZeUeS ead,      d                      ZeU ead,      d               ZeU ead,      d               ZeU ead,      d               ZeU ead,      d               ZeUeSd               ZeUd        Zd Zd ZeU eada      d               ZeUeS eVd      d                      ZeUeS eVd      d                      Zd Zd Ze`d        ZeU ead[      d               ZeUeS eVd      d                      ZeU eVd.      d               ZeU eVd      d               Zd Zd Zd Zd Zd Zd ZeUd        ZeUd        ZeU eVd      d               ZeUeS ead[      d                      ZeUeS ead[      d                      ZeUeS ead[      d                      Zd ZeUeS ead[      d                      ZeU ead[      d               ZeU eVd      d               ZeUd        Z eUd        ZeUeSd               ZeUd        ZeUeS ead      d                      Ze`eSd               Ze`eSd               ZeUeS ead      d                      ZeUeS ead      d                      Ze`d        Z	eUeSd               Z
y)a  
views.py

This module contains the view functions for handling HTTP requests and rendering
responses in your application.

Each view function corresponds to a specific URL route and performs the necessary
actions to handle the request, process data, and generate a response.

This module is part of the recruitment project and is intended to
provide the main entry points for interacting with the application's functionality.
    N)datedatetime)chain)parse_qs)template)settings)messages)User)serializers)cache)EmailMessage)	Paginator)CaseIntegerFieldProtectedErrorQWhen)HttpResponseHttpResponseRedirectJsonResponse)get_object_or_404redirectrenderreverse)timezone)gettext_lazy)require_http_methods)ConfiguredEmailBackend)check_candidate_self_tracking)country_arrs_astates)MailTemplateForm)eval_validateexport_datagenerate_pdfget_key_instancessortby)EmailLogHorillaMailTemplateJobPositionclear_messages)EmployeeEmployeeWorkInformation)get_content_type)hx_request_requiredloggerlogin_requiredpermission_required)group_by_queryset)Document)notify)CandidateAuthenticationBackend)candidate_login_requiredmanager_can_enterrecruitment_manager_can_enter)CandidateFilterCandidateReGroupInterviewFilterRecruitmentFilterSkillZoneCandFilterSkillZoneFilterStageFilter)AddCandidateFormCandidateCreationFormCandidateDocumentFormCandidateDocumentRejectFormCandidateDocumentRequestFormCandidateDocumentUpdateFormCandidateExportFormRecruitmentCreationFormRejectReasonForm
ResumeFormScheduleInterviewForm
SkillsFormSkillZoneCandidateFormSkillZoneCreateFormStageCreationFormStageNoteFormStageNoteUpdateFormToSkillZoneForm)recruitment_manages)	CandidateCandidateDocumentCandidateRatingInterviewScheduleRecruitmentRecruitmentGeneralSettingRecruitmentSurveyRejectReasonResumeSkill	SkillZoneSkillZoneCandidateStage
StageFiles	StageNote)paginator_qryc                    | j                   }|j                  }|sB|j                  j                         xs |j                  |j                  j                         fS t        j                  j                  |      }||j                  j                         v xs2 |j                  xs$ t        | |j                  j                        d   |j                  j                         fS )a  
    This method is used to identify the employee is a stage manager or
    not, if stage_id is passed through args, method will
    check the employee is manager to the corresponding stage, return
    tuple with boolean and all stages that employee is manager.
    if called this method without stage_id args it will return boolean
     with all the stage that the employee is stage manager
    Args:
        request : django http request
        stage_id : stage instance id
    idrec_idr   )useremployee_get	stage_setexistsis_superuserallrb   objectsgetstage_managersis_recruitmentmanagerrecruitment_idrh   )requeststage_idrk   employee	stage_objs        +/var/www/horilla/recruitment/views/views.pyis_stagemanagerr{   z   s     <<D  H%%'<4+<+<""$
 	
 !!X!.II,,0022 	Q	Q 1I1I1L1LMaP 	     c                    | j                   }|j                  }|sB|j                  j                         xs |j                  |j                  j                         fS t        j                  j                  |      }||j                  j                         v xs |j                  |j                  j                         fS )a  
    This method is used to identify the employee is a recruitment
    manager or not, if rec_id is passed through args, method will
    check the employee is manager to the corresponding recruitment,
    return tuple with boolean and all recruitment that employee is manager.
    if called this method without recruitment args it will return
    boolean with all the recruitment that the employee is recruitment manager
    Args:
        request : django http request
        rec_id : recruitment instance id
    rg   )
rk   rl   recruitment_setrn   ro   rp   rZ   rq   rr   recruitment_managers)rv   rj   rk   rx   recruitment_objs        rz   rt   rt      s     <<D  H$$++-B1B1B$$((*
 	
 "))---8OO88<<>>S$BSBS  $$& r|   c           	      "   g }|D ]  }t        | j                  |j                  j                               j                  j                  d      }g }|g d}|j                  d      D ]  }|j                  |g d       t        | j                  |j                  j                  d            j                  j                  d      }d|j                  z   t        |j                        z   }	t        |d| j                  j                  |	      |	      j                  }
|d	   |
z   |d	<    g }|d	   }|D ]>  }d
}|D ]  }
|
d   |k(  s|j                  |
       d} n |r,|j                  d|i       @ ||d}|j                  |        |S )Nquerysetsequence)recruitmentstages)grouperlistT	is_activepagerw   r   Fr   )rB   GETrm   rp   qsorder_byappendr<   candidate_setfilterstagestrrh   r5   rr   object_list)rv   recruitmentsgroupsrecr   all_stages_grouperdatar   stage_candidates	page_namer   ordered_datagroupersfounds                 rz   pipeline_grouperr      s   F )W[[3==3D3D3FGJJSS
  "b1__Z0 	6E%%%&DE.##**" +  
 b*%  ,s366{:I' 	*	
 k  "(^g5DN!	6$  > 	8EE# 9%. ''0 E	
 ##Y$67	8 "
 	dS)T Mr|   zrecruitment.add_recruitment)permc                 (   t               }| j                  r$t        | j                  j                               }| j                  j                  d      dk7  r| j                  j                  d      nd}| j                  dk(  rt        | j
                        }|j                         r|j                         }|j                  j                  t        j                  j                  |j                  j                  d                   |j                  j                  t         j                  j                  |j                  j                  d                   |j"                  d	   D ]<  }|j$                  j'                         D ]  }|j(                  j+                  |        > t-        j.                  | t1        d
             t3        j4                  t6              5  |j                  j9                  d      }|D cg c]  }|j:                   }}t=        j>                  | j@                  jB                  |ddddddtE        d      	       ddd       tG        d      S tI        | d||d      S c c}w # 1 sw Y   tG        d      S xY w)a$  
    This method is used to create recruitment, when create recruitment this method
    add  recruitment view,create candidate, change stage sequence and so on, some of
    the permission is checking manually instead of using django permission permission
    to the  recruitment managers
    initialdynamicNoneNPOSTr   id__inopen_positionssurvey_templateszRecruitment added.employee_user_idz,You are chosen as one of recruitment manageru6   تم اختيارك كأحد مديري التوظيفu7   Sie wurden als einer der Personalvermittler ausgewähltu<   Has sido elegido/a como uno de los gerentes de contrataciónu?   Vous êtes choisi(e) comme l'un des responsables du recrutementpeople-circlepipeline	recipientverbverb_arverb_deverb_esverb_friconr   #<script>location.reload();</script>!recruitment/recruitment_form.htmlformr   )%rJ   r   dictrr   methodr   is_validsaver   setr.   rq   r   r   getlistr   r,   cleaned_datarecruitmentsurvey_setrp   recruitment_idsaddr	   success_
contextlibsuppress	Exceptionselect_relatedr   r7   sendrk   rl   r   r   r   )	rv   r   r   r   surveysurmanagersrx   userss	            rz   r   r      s1    #$D{{&w{{/?/?/AB&-kkooi&@F&J	"PT  ~~&w||4==?"iikO0044  ''99,,-CD ( 
 **..##**$))2C2CDT2U*V ++,>? =!77;;= =C''++O<== Wa(<&=>$$Y/ *??NN& DLLx22LLLL--#GTUZ]($Z0
    EFF4tPW6X  M	    EFFs   & I>I9=I>9I>>Jrecruitment.view_recruitmentc           
         | j                   s+| j                   j                         j                  ddi       t        j                  j                  d      }t        j                  j                         rd}nd}i }| j                   j                  d      dk(  r|j                  d	      }d
g|d<   n|j                  d	      }dg|d<   t        | j                   |      }| j                   j                         }|j                         D ]
  \  }}|||<    t        | |t        |j                  | j                   j                  d            ||| j                   j                         dz   d      S )z@
    This method is used to  render all recruitment to view
    r   onTr   z!recruitment/recruitment_view.htmlz"recruitment/recruitment_empty.htmlclosedfalse)r   trueFr   z&closed=false)r   ffilter_dictpd)r   copyupdaterZ   rq   r   rp   rr   r?   itemsr   re   r   	urlencode)rv   r   r   initial_tag
filter_objr   keyvalues           rz   recruitment_viewr     sJ    ;;!!;"56""))D)9H 67K{{x G+??$?/!'H??%?0!(	H"7;;9J++""$K!'') !
U C! !*--1HI&++'')O;		
	 	r|   zrecruitment.change_recruitmentc                 J   t         j                  j                  |      }g }t        j                  j	                  |      j                         }|D ]+  }|j                  |j                  j                                - t        |      }| j                  rt        | j                        }| j                  j                  d      dk7  r| j                  j                  d      nd}| j                  dk(  rt        | j                  |      }|j                         rc|j                         }|j                  d   D ]<  }|j                   j                         D ]  }|j"                  j%                  |        > |j                          t'        j(                  | t+        d	             t-        | d
d|i      }	t/        j0                  t2              5  |j4                  j7                  d      }
|
D cg c]  }|j8                   }}t;        j<                  | j>                  j@                  || d| d| d| d| ddtC        d      	       ddd       tE        |	jF                  jI                  d      dz         S t-        | d||d      S c c}w # 1 sw Y   ExY w)z
    This method is used to update the recruitment, when updating the recruitment,
    any changes in manager is exists then permissions also assigned to the manager
    Args:
        id : recruitment_id
    rg   )r   instancer   r   Nr   r   zRecruitment Updated.r   r   r   2 is updated, You are chosen as one of the managersuB    تم تحديثه، تم اختيارك كأحد المديرينu\    wurde aktualisiert. Sie wurden als                            einer der Manager ausgewählt^ ha sido actualizado/a. Has sido elegido                            a como uno de los gerentesud    a été mis(e) à jour. Vous êtes choisi(e) comme                            l'un des responsablesr   r   r   utf-8r   z(recruitment/recruitment_update_form.htmlr   )%rZ   rq   rr   r\   r   distinctr   template_idrp   rJ   r   r   r   r   r   r   r   r   r   r	   r   r   r   r   r   r   r   r   r   r7   r   rk   rl   r   r   contentdecode)rv   rj   r   survey_template_listr   r   r   r   r   responser   rx   r   s                rz   recruitment_updater   ;  s    "))---8O(0077 8 hj  # >##F$6$6$:$:$<=>"O<D{{&w{{3&-kkooi&@F&J	"PT  ~~&w||oN==?"iikO++,>? =!77;;= =C''++O<==   "Wa(>&?@<vtnH $$Y/ *??NN& DLLx22LLLL--#+,,^_.//qr./ 0: ;./ 07 8./ 02 3($Z0(    ''03XX  2'* ' M	 s    J6J	AJJJ"c                 @    t        | d      }|j                  |      } | S )zA
    This method is used to generate common paginator limit.
       r   get_page)qrysetpage_number	paginators      rz   !paginator_qry_recruitment_limitedr   |  s%     &!$I,FMr|   c           
      j   t        | j                        }|j                  j                         rd}nd}t	        | j                        }t        | j                        }t        |j                  | j                  j                  d            }t        j                         }t        | ||||||d      S )zP
    This method is used to filter out candidate through pipeline structure
    zpipeline/pipeline.htmlzpipeline/pipeline_empty.htmlr   )rec_filter_objr   stage_filter_objcandidate_filter_objnow)r?   r   r   rn   rB   r<   r   rr   r   r   r   )rv   r   r   stage_filtercandidate_filterr   r   s          rz   recruitment_pipeliner     s     #J }}+1w{{+L&w{{34w{{v.L ,,.C(' ,$4	

 
r|   c                 J   t        | j                        }t        | j                        }t        | j                        }| j                  j	                  d      }|j
                  j                  d      }| j                  j                  d      s|j                  t        | j                  j                              }|j
                  j                  | j                  j                        j                  dd      j                         }||j
                  j                  |	      z  }|j                  d      j                         }| j                  j	                  d
      }t        | j                  j                               }t        t         |      }t#        j$                  | j&                  j(                  dz   |j
                  j                  d      j+                  d      |j
                  j+                  d      ||| j                  d       | j                  j                         }	t-        |d      }
| j                  j	                  d      }|
j/                  |      }d}| j                  j	                  d      dk(  rd}t1        | ||||||||	d      S )z<
    This method is used to search/filter from pipeline
    viewTr   r   )r   )rs   ru   flatr   r   r   r   )
candidatesr   r   r   filter_queryr   r   z3pipeline/components/pipeline_search_components.htmlcardz&pipeline/kanban_components/kanban.html)r   r   r   r   statusr   r   )r?   r   rB   r<   rr   r   r   rk   has_permr   rl   values_listr   r   r   r(   rZ   CACHEr   sessionsession_keyr   r   r   r   )rv   r   r   r   r   r   stage_recruitment_idsr   r   previous_datar   r   page_objr   s                 rz   filter_pipeliner    s0    #7;;/Jw{{+L&w{{3;;??6"D==''$'7L<<  !?@#**7<<#<#<=
 OO""',,2K2K"L[)[5XZ 	
 $jmm&:&:BW&:&XX#**T*:CCE[[__X&F7;;0023K#K=K	II##j0*--44t4DMM #oo..z:(&#KK	
 KK))+M,*I++//&)K!!+.HDH{{v&(;# ,$4&	
 r|   c                     | j                   d   }t        j                  j                  |      }|j                  j                  d      j                         }t        |      S )z,
    Method to update stage badge count
    rw   rg   Tr   )r   rb   rq   rr   r   r   countr   )rv   rw   r   r  s       rz   get_stage_badge_countr    sV     {{:&HMM*E&&&6<<>Er|   r   c           
      l   | j                   d   }t        j                  j                  |      }t	        j                  | j
                  j                  dz         d   j                  |      }d}|dk(  rd}t        | |||t	        j                  | j
                  j                  dz         d	   d
      S )z-
    This method will stage tab contents
    rj   rg   r   r   recruitment_id__idz+pipeline/components/stages_tab_content.htmlr  z7pipeline/kanban_components/kanban_stage_components.htmlr   )r   ordered_stagesr   )	r   rZ   rq   rr   r  r	  r
  r   r   )rv   r   ru   r   r  r   s         rz   stage_componentr    s     [[*N%%))^)<KYYw::ZGHff/  =Hv~L, 99W__%@%@:%MN	

 
r|   recruitment.change_candidatec                 t   | j                   j                  d      }| j                   d   }t        j                  | j                  j
                  dz         d   j                  |      j                         }i }t        |      D ]W  \  }}t        j                  | j                  j
                  dz         d   j                  |      }|j                  ||       Y |j                  dk(  rA|j                  j                         r't        d	      |d
<   |j                  j                  |d<   t        |      S )*
    Update candidate sequence method
    orderrw   r   r   rg   r  r   rw   hiredVaccancy is filledmessagevacancy)r   r   r  rr   r	  r
  r   first	enumerater   
stage_typeru   is_vacancy_filledr   r  r   )rv   
order_listrw   r   contextindexcand_id	candidates           rz   #update_candidate_stage_and_sequencer)    s    $$W-J{{:&H		'//--
:;HE	8		 

 G#J/ 9wIIgoo99JFG

&G&
 	 	%%8	9
 7"113!"#7!8GI!&!5!5!=!=GI  r|   c                    | j                   j                  d      }| j                   d   }t        j                  | j                  j
                  dz         d   j                  |      j                         }i }t        |      D ]W  \  }}t        j                  | j                  j
                  dz         d   j                  |      }|j                  ||       Y t        |      S )r  r  rw   r   r   rg   r  r  )r   r   r  rr   r	  r
  r   r   r!  r   r   )rv   r$  rw   r   r   r&  r'  r(  s           rz   update_candidate_sequencer+  +  s     $$W-J{{:&H		'//--
:;HE	8		 

 D#J/ 9wIIgoo99JFG

&G&
 	 	%%8	9
 r|   c                 @    t        | d      }|j                  |      } | S )z
    Limited pagination
    
   r   )r   r   r   s      rz   limited_paginator_qryr.  A  s%     (B'I!!$'HOr|   c                    | j                   j                  d      }t        j                  | j                  j                  dz         d   j                  |      j                         }t        j                  | j                  j                  dz         d   j                  |      }d}t        j                  | j                  j                  dz         d   j                  d	      d
k(  rd}t        j                         }t        | |t        || j                   j                  d            |t        |j                         di       |d      S )z
    Candidate component
    rw   r   r   rg   r  rw   z2pipeline/components/candidate_stage_component.htmlr  r   r  z;pipeline/kanban_components/candidate_kanban_components.htmlcandidate_pageru   )r  r   r   r   )r   rr   r  r	  r
  r   r   r   r   r   r.  getattr)rv   rw   r   r  r   r   s         rz   candidate_componentr3  J  s$    {{z*H		'//--
:;HE	8		 

 7??66CDfef  DH		'//--
:;NKOOPVW	 Q
,,.C/GKKOO,<= :++-/?D	
 r|   c                    | j                   dk(  r:| j                  d   }| j                  d   }i }| j                  j                  d      dk(  r t	        j
                  |      }|D ]  }	 t        j                  j                  |      }t        j                  j                  |j                  |      j                         }|r}||_        |j                          |j                  dk(  rA|j                  j                         r't!        d	      |d
<   |j                  j"                  |d<   t%        j&                  | d        t-        |      S 	 t        j                  j                  |      }t        j                  j                  |j                  |      j                         }|r||_        |j                          |j                  dk(  rA|j                  j                         r't!        d	      |d
<   |j                  j"                  |d<   ||_        |j                          t%        j&                  | d       t-        |      S | j                  d   }| j                  d   }t        j                  j                  |      }t        j                  j                  |j                  |      j                         }|r-||_        |j                          t%        j&                  | d       t/        |       S # t        j(                  $ r# t%        j*                  | t!        d             Y w xY w# t        j(                  $ r, t%        j*                  | t!        d             Y t-        |      S w xY w)z8
    This method is used to update candidates stage
    r   canIdsstageIdbulkTruerg   )ru   rh   r  r  r  r  Candidate stage updatedCandidate not found.candidate_idrw   )r   r   r   rr   jsonloadsrV   rq   rb   r   ru   r   rw   r   r"  r#  r   r  r	   r   DoesNotExisterrorr   r  )rv   r5  rw   r%  r'  r(  r   r;  s           rz   change_candidate_stager@  q  s    ~~h'<<	*;;??6"f,ZZ'F! GG ) 1 1 5 5 5 AI!MM00'0'?'?H 1 eg  -2	*!( ++w6$33EEG567K5L	 25:5I5I5Q5Q	 2 ((2KLGD G$$#C%--11V1<	,,#,#;#; - %'  ).I&NN$''72 //AAC123G1HGI.161E1E1M1MGI.).I&NN$$$W.GH G$$;;~.L{{:&H!!%%%6IMM   //H ! eg 
 "	";<7##? !-- GNN7A.D,EFG$ )) Cw*@(ABG$$Cs&   +CK<C/L5 <2L21L252M43M4c                     | j                   j                  d      }||nd}t        j                  j	                         }t
        j                  j                  |d      }t        j                  j	                         }t        | d|||d      S )z@
    This method is used to render pipeline card structure.
    search T)name__icontainsr   z4pipeline/pipeline_components/pipeline_card_view.html)r   r  r   )	r   rr   rZ   rq   rp   rV   r   rb   r   )rv   rB  r   r  r   s        rz   recruitment_pipeline_cardrE    s     [[__X&F)VrF!))--/O""))&D)QJ]] F>'zVT r|   zrecruitment.delete_recruitmentc                 `   	 t         j                  j                  |      }|j                  rd|_        nd|_        |j	                          t        | j                  j                  dd            S # t         j
                  t        f$ r" t        j                  | t        d             Y _w xY w)zz
    This method is used to archive and unarchive the recruitment
    args:
        rec_id: The id of the Recruitment
    rg   FTRecruitment Does not exists..HTTP_REFERER/)rZ   rq   rr   r   r   r>  OverflowErrorr	   r?  r   r   META)rv   rj   r   s      rz   recruitment_archiverL    s    D!))---8  $)K!$(K!   0 0 EFF $$m4 Dw"A BCDs   AA2 28B-,B-zrecruitment.change_stagec                    t         j                  j                  |      }t        |      }| j                  ryt        | j                  |      }|j                         rQ|j                         }t        j                  | t        d             t        j                  t              5  |j                  j                  d      }|D cg c]  }|j                   }}t!        j"                  | j$                  j&                  ||j(                   d|j*                   dd|j(                   d|j*                   d	d
|j(                   d|j*                   dd|j(                   d|j*                   dd|j(                   d|j*                   ddt-        d      	       ddd       t/        d      S t1        | dd|i      S c c}w # 1 sw Y   t/        d      S xY w)z@
    This method is used to update stage from pipeline view
    rg   r   Stage updated.r   z stage in recruitment zM                            is updated, You are chosen as one of the managersu   تم تحديث مرحلة u    في التوظيف uL                               ، تم اختيارك كأحد المديرينz
Die Stufe z in der Rekrutierung u\                               wurde aktualisiert. Sie wurden als einer der Manager ausgewähltzSe ha actualizado la etapa u.    en la contratación                          z,.Has sido elegido/a como uno de los gerentes	   L'étape z dans le recrutement ud                             a été mise à jour.Vous avez été choisi(e) comme l'un des responsablesr   r   r   N)<script>window.location.reload()</script>zpipeline/form/stage_update.htmlr   )rb   rq   rr   rQ   r   r   r   r	   r   r   r   r   r   rs   r   r   r7   r   rk   rl   r   ru   r   r   r   )rv   rw   ry   r   r   rx   r   s          rz   stage_update_pipelinerQ    s    !!X!.Ii0D|| 	B==?		IWa(8&9:$$Y/ $33BBCUVCKLx22LLLL--#%OO,,B9C[C[B\ ]N O9)//9JJ_`i`x`x_y zM N((99NyOgOgNh i] ^9)//9J K$3344`b'	'88MiNfNfMg he f($Z0(   KLL'<vtnMM) M(   KLLs   * G
GCGGGc                    t         j                  j                  |      }t        |      }| j                  r.t        | j                  |      }|j                         r|j                         }t        j                  | t        d             t        j                  t              5  |j                  j                  d      }|D cg c]  }|j                   }}t!        j"                  | j$                  j&                  || dd| d| d| d	| d
dt)        d      	       ddd       t+        | dd|i      }t-        |j.                  j1                  d      dz         S t+        | dd|i      S c c}w # 1 sw Y   SxY w)zF
    This method is used to update recruitment from pipeline view
    rg   r   zRecruitment updated.r   r   u   تم تحديث 0   ، تم اختيارك كأحد المديرينuZ    wurde aktualisiert.                          Sie wurden als einer der Manager ausgewähltr   ui    a été mis(e) à jour. Vous avez été                            choisi(e) comme l'un des responsablesr   r   r   Nz%pipeline/form/recruitment_update.htmlr   r   r   )rZ   rq   rr   rJ   r   r   r   r	   r   r   r   r   r   r   r   r   r7   r   rk   rl   r   r   r   r   r   )rv   rj   r   r   r   rx   r   r   s           rz   recruitment_update_pipelinerT    s    "))---8O"O<D||&w||oN==?"iikOWa(>&?@$$Y/ *??NN& DLLx22LLLL--#+,,^_..??op./ 0G H./ 07 8./ 0B C($Z0( @64.H    ''03XX  'BVTNSS- M	 s   * E<
E7AE<7E<<Fc                 d   	 t         j                  j                  |      }d|_        |j	                          t        j                  | d       t        | j                  j                  dd            S # t         j                  t        f$ r" t        j                  | t        d             Y _w xY w)zE
    This method is used to close recruitment from pipeline view
    rg   TzRecruitment closed successfullyrG  rH  rI  )rZ   rq   rr   r   r   r	   r   r>  rJ  r?  r   r   rK  rv   rj   r   s      rz   recruitment_close_pipelinerW  %  s    D%--11V1<!%"CD   0 0 EFF $$m4 Dw"A BCDs   AA4 48B/.B/c                     t         j                  j                  |      }d|_        |j	                          t        j                  | d       t        | j                  j                  dd            S )zF
    This method is used to reopen recruitment from pipeline view
    rg   Fz Recruitment reopend successfullyrH  rI  )	rZ   rq   rr   r   r   r	   r   r   rK  rV  s      rz   recruitment_reopen_pipelinerY  5  s^     "))---8O"OW@A 0 0 EFFr|   c                 n   | j                   d   }t        j                  j                  |      }|j                  j                         j                         }t        j                  j                  |      }|j                  |k(  rt        dt        d      d      S |j                  j                  |      }d}|j                         r|j                         j                  }t        |       d   j                  |j                  	      j                         }|s:| j                   j"                  s$t%        |j                  j&                  
      d   r7||_        |j(                  dk(  |_        |j(                  dk(  |_        ||_        d|_        |j1                          t3        j4                  t6              5  |j8                  j;                  d      }|D 	cg c]  }	|	j<                   }
}	t?        j@                  | j                   jB                  |
d|jD                   d|jD                   d|jD                   dd|jD                   d|jD                   dtG        d      	       ddd       t        dt        d      d      S t        dt        d      d      S c c}	w # 1 sw Y   <xY w)z
    This method is a ajax method used to update candidate stage when drag and drop
    the candidate from one stage to another on the pipeline template
    Args:
        id : candidate_id
    r6  rg   noChangezNo change detected.typer  r0  N   ru   ri   r   r  	cancelledFr   zNew candidate arrived on stage u/   وصل مرشح جديد إلى المرحلة z!Neuer Kandidat ist auf der Stufe z angekommenu"   Nuevo candidato llegó a la etapa u%   Nouveau candidat arrivé à l'étape z
person-addr   r   r   r9  dangerz Something went wrong, Try agian.)$r   rV   rq   rr   history_setrp   r   rb   rw   r   r   r   rn   schedule_dater{   ru   rk   ro   rt   rh   r"  r  canceledstart_onboardr   r   r   r   rs   r   r   r7   r   rl   r   r   )rv   r'  rw   candidate_objhistory_querysetry   rc  !stage_manager_on_this_recruitmentr   rx   r   s              rz   candidate_stage_updateri  C  sl    ||I&H%%))W)5M$00446<<>!!X!.I*ZA>S<TUVV$00777KM  )..0>> #	y77	8	 & 	*<<$$ 	(@(@(C(CDQG!*'22g=!*!5!5!D&3#&+#  + 	 //>>?QRH?GH8X..HEHKK))6y6GHI)//IZ[;IOO;LKX<Y__<MN?	?PQ! ,
	 1-F+GH
 	
 a(J&KL ! I	 	s   > J+J&1A?J+&J++J4zrecruitment.view_stagenotec                     t         j                  j                  |      }|j                  j	                         j                  d      }t        | d||d      S )z
    This method renders a template components to view candidate remark or note
    Args:
        id : candidate instance id
    rg   -id+pipeline/pipeline_components/view_note.html)candnotes)rV   rq   rr   stagenote_setrp   r   r   )rv   r'  rf  rn  s       rz   	view_noterp    sW     %%))W)5M''++-66u=E5/ r|   zrecruitment.add_stagenotec                 `   t        d|i      }| j                  dk(  rt        | j                  | j                        }|j	                         r|j                  d      \  }}t        j                  j                  |      }||_	        |j                  |_
        | j                  j                  |_        |j                          |j                  j                  |       t!        j"                  | t%        d             t        j                  j                  |      }t'        | d||d	      S )
H
    This method renders template component to add candidate remark
    r;  r   r   Fcommitrg   Note added successfully..z#candidate/individual_view_note.htmlr(  	note_form)rR   r   r   FILESr   r   rV   rq   rr   r;  rw   rk   rl   
updated_bystage_filesr   r	   r   r   r   )rv   r'  r   noteattachment_idsr(  rf  s          rz   add_noter}    s     .'!:;D~~LLMM
 ==?#'99E9#: D.!))---9I )D%..DM%ll77DOIIK  0Wa(C&DE%%))W)5M-&	
 r|   c                    t        d|i      }| j                  dk(  rt        | j                  | j                        }|j	                         r|j                  d      \  }}t        j                  j                  |      }||_	        |j                  |_
        | j                  j                  |_        |j                          |j                  j                  |       t!        j"                  | t%        d             t'        d|	      S t        j                  j                  |      }|j(                  j+                         j-                  d
      }t/        | d|||d      S )rr  r;  r   r   Frs  rg   ru  	view-noter'  rk  rl  )rw  rm  rn  )rR   r   r   rx  r   r   rV   rq   rr   r;  rw   rk   rl   ry  rz  r   r	   r   r   r   ro  rp   r   r   )rv   r'  r   r{  r|  r(  rf  rn  s           rz   create_noter    s%    .'!:;D~~W\\7==9==?#'99E9#: D.!))---9I )D%..DM%ll77DOIIK  0Wa(C&DEK99%%))W)5M''++-66u=E5MEB r|   zrecruitment.change_stagenotec                    t         j                  j                  |      }t        |      }| j                  rt        | j                  | j
                  |      }|j                         rR|j                          t        j                  | t        d             |j                  j                  }t        d|      S t        | dd|i      S )c
    This method is used to update the stage not
    Args:
        id : stage note instance id
    rg   r   Note updated successfully...r  r  z-pipeline/pipeline_components/update_note.htmlr   )rd   rq   rr   rS   r   rx  r   r   r	   r   r   r;  rh   r   r   )rv   note_idr{  r   r'  s        rz   note_updater    s       G ,D-D||"7<<N==?IIKWa(F&GH''**GK99@64. r|   c                    t         j                  j                  |      }t        |      }| j                  rt        | j                  | j
                  |      }|j                         re|j                          t        j                  | t        d             t        | dd|i      }t        |j                  j                  d      dz         S t        | dd|i      S )r  rg   r   r  z8pipeline/pipeline_components/update_note_individual.htmlr   r   r   )rd   rq   rr   rR   r   rx  r   r   r	   r   r   r   r   r   r   )rv   r  r{  r   r   s        rz   note_update_individualr    s       G ,D$'D||W\\7==4H==?IIKWa(F&GHJH
    ''03XX  BD	
 r|   c                    t         j                  j                  |      }| j                  dk(  r| j                  j                  d      }g }|D ]b  }t        j                  j                  |      }|j                  |j                         |j                  j                  |j                         d t        d|j                  j                        S )z
    This method is used to Add more files to the stage candidate note.
    Args:
        id : stage note instance id
    rg   r   filesr  r  r  )rd   rq   rr   r   rx  r   rc   creater   rh   rz  r   r   r;  rv   rh   r{  r  	files_idsfiler   s          rz   add_more_filesr    s       B 'D~~%%g.	 	.D!))00t0<HX[[)  -		.
 K):):)=)=>>r|   c                    t         j                  j                  |      }| j                  dk(  r| j                  j                  d      }g }|D ]b  }t        j                  j                  |      }|j                  |j                         |j                  j                  |j                         d t        j                  | t        d             t        d|j                   j                   d      S )r  rg   r   r  r  zFiles uploaded successfullyz/recruitment/add-note/rI  )rd   rq   rr   r   rx  r   rc   r  r   rh   rz  r   r	   r   r   r   r;  r  s          rz   add_more_individual_filesr    s       B 'D~~%%g.	 	.D!))00t0<HX[[)  -	. 	!$A"BC,T->->-A-A,B!DEEr|   c                     d}t         j                  j                  |      }|j                          t	        j
                  | t        d             t        |      S zi
    This method is used to delete the stage note file
    Args:
        id : stage file instance id
    rC  rg   zFile deleted successfully)rc   rq   rr   deleter	   r   r   r   )rv   rh   scriptr  s       rz   delete_stage_note_filer  /  sL     F!!R!(DKKMWa ;<=r|   c                 2   d}t         j                  j                  |      }|j                  j	                         j                         j                  j                  }|j                          t        j                  | t        d             t        |      S r  )rc   rq   rr   ro  rp   r   r;  rh   r  r	   r   r   r   )rv   rh   r  r  r'  s        rz   delete_individual_note_filer  =  su     F!!R!(D  $$&,,.;;>>GKKMWa ;<=r|   c                 4   t         j                  j                  |      }|j                  |j	                         j
                          t        j                  | t        d             t        d|j	                         j                  j                        S )Nrg   )candidate_can_viewzCandidate view status updatedr  r  )rd   rq   r   r   r   r  r	   r   r   r   r;  rh   )rv   rh   r{  s      rz   candidate_can_view_noter  M  so     ##r#*DKKtzz|'F'F#FKGWa ?@AK)B)B)E)EFFr|   c                     | j                   d   }| j                   d   }t        j                  j                  |      }||_        |j                          t        ddi      S )zJ
    This is a an ajax method to update schedule date for a candidate
    candidateIdr   rg   r  congratulations)r   rV   rq   rr   rc  r   r   )rv   r;  rc  rf  s       rz   candidate_schedule_date_updater  X  s^     <<.LLL(M%%))\):M"/M$5677r|   zrecruitment.add_stagec                    t        d| j                  j                  d      i      }| j                  dk(  r*t        | j                        }|j                         r|j                         }|j                  j                  t        j                  j                  |j                  j                  d                   |j                          |j                  }t        j                  j                  |d      j!                  d      j#                         }|j$                  d
|_        n|j$                  d
z   |_        |j                          t'        j(                  | t+        d             t-        j.                  t0              5  |j                  j3                  d      }|D cg c]  }|j4                   }}t7        j8                  | j:                  j<                  |d| d|j                   dd| d|j                   dd| d|j                   dd| d|j                   dd| d|j                   ddt?        d      	       d	d	d	       tA        d      S tC        | d d!|i      S c c}w # 1 sw Y   tA        d      S xY w)"zf
    This method is used to create stages, also several permission assigned to the stage managers
    ru   r   r   rs   r   T)ru   r   r   Nr^  zStage added.r   zStage z is updated on recruitment z@,                          You are chosen as one of the managersu   تم تحديث المرحلة u.    في التوظيف                          rS  zStufe z wurde in der Rekrutierung uT                             aktualisiert. Sie wurden als einer der Manager ausgewähltz	La etapa uB    ha sido actualizada en la contratación                          z-. Has sido elegido/a como uno de los gerentesrO  uC    a été mise à jour dans le recrutement                          u7   . Vous avez été choisi(e) comme l'un des responsablesr   r   r   r   zstage/stage_form.htmlr   )"rQ   r   rr   r   r   r   r   rs   r   r.   rq   r   r   r   ru   rb   r   lastr   r	   r   r   r   r   r   r   r   r7   r   rk   rl   r   r   r   )rv   r   ry   r   
rec_stagesr   rx   r   s           rz   r   r   f  sn    !7;;??3C#DED ~~ .==?		I$$((  ''tyy/@/@AQ/R'S NN'66O$$Ot$T*% 
 ""*%&	"%/%8%81%<	"NNWa&78$$Y/ $33BBCUVCKLx22LLLL--#!),G	H`H`Ga b@ A=i[ I$3344df$YK/J9KcKcJd eU V'	{ 3$3344ac'	{ 3$3344km($Z0(   EFF'2VTNCC' M(   EFFs   
 I6*I1=BI61I66J	zrecruitment.view_stagec           
      j   t         j                  j                         }|j                  d      }t	        |d| j
                  j                  d            }t               }t               }|j                         rd}nd}t        | |t        || j
                  j                  d            |||d      S )	z@
    This method is used to render all stages to a template
    T)recruitment_id__is_activeru   rpagezstage/stage_view.htmlzstage/stage_empty.htmlr   )r   r   r   r   )rb   rq   rp   r   r5   r   rr   rB   rQ   rn   r   re   )rv   r   r   r   r   r   s         rz   
stage_viewr    s     ]] F]]T]:F$ L
 JD}}*+!&'++//&*AB(		
	 	r|   c           
         t        | j                        j                  j                  |      }| j                  j	                         }t        |      }t        t        |       t        | dt        || j                  j                  d            || j                  j	                         | j                  j                  d      d      S )Nr  zstage/stage_component.htmlr   HTTP_HX_TARGET)r   r   r   	hx_target)rB   r   r   r   r   r   r(   rb   r   re   rr   rK  )rv   rj   r   r  	data_dicts        rz   
stage_datar    s    %((//6/JFKK))+M'IeY'$!&'++//&*AB$++'') ))*:;		
	 	r|   c                    t         j                  j                  |      }t        |      }| j                  dk(  rt        | j
                  |      }|j                         re|j                          t        j                  | t        d             t        | dd|i      }t        |j                  j                  d      dz         S t        | d	d|i      S )
z
    This method is used to update stage, if the managers changed then    permission assigned to new managers also
    Args:
        id : stage_id

    rg   r   r   rN  r   r   r   r   zstage/stage_update_form.html)rb   rq   rr   rQ   r   r   r   r   r	   r   r   r   r   r   r   )rv   rw   r   r   r   s        rz   stage_updater    s     ]](+Ff-D~~ ?==?IIKWa(8&9:<vtnH    ''03XX  '9FD>JJr|   zrecruitment.add_candidatec                    t        d| j                  j                  d      i      }| j                  r~t        | j                  | j                  d| j                  j                  d      i      }|j                         r1|j                          t        j                  | d       t        d      S t        | dd|i      S )zD
    This method is used to add candidate directly to the stage
    rw   r   zCandidate AddedrP  z!pipeline/form/candidate_form.htmlr   )rC   r   rr   r   rx  r   r   r	   r   r   r   rv   r   s     rz   add_candidater    s     Z1L$MND||LLMM!<=

 ==?IIKW&78 KLL'>OOr|   r   c                     t         j                  j                  |      }| j                  d   |_        |j                          t        d      }t        d| d      S )zE
    This method is used to update the name of recruitment stage
    rg   r   z-The stage title has been updated successfullyz[<div class="oh-alert-container"><div class="oh-alert oh-alert--animated oh-alert--success">z</div></div>)rb   rq   rr   r   r   r   r   r   )rv   rw   ry   r  s       rz   stage_title_updater    s\     !!X!.Ill7+IONN?@G
efmennz{ r|   c                    t               }t        j                  j                  dd      }d}| j                  dk(  r=t        | j
                  | j                        }|j                         r|j                  d      }d|_	        d|_
        |j                  >t        j                  j                  |j                  d	      j                         |_        | j                  j!                  d
      dk(  r	d|_        d}|j$                  j!                  d      r:|j                          t'        j(                  | t+        d             t1        |      S t'        j,                  | d       t/        | d||d      S t/        | d||d      S )z.
    This method used to create candidate
    FTr   r   /recruitment/candidate-viewr   rs  softwarer   ru   r"  
onboardingr8  /onboarding/candidates-viewjob_position_idzCandidate added.zJob position field is required$candidate/candidate_create_form.html)r   open_recruitment)rD   rZ   rq   r   r   r   rx  r   r   re  sourcerw   rb   ru   r   r   rr   r  r   r	   r   r   r?  r   r   )rv   r   r  pathrf  s        rz   r(  r(    sa    !"D"**11$1O(D~~$W\\7==A==? IIUI3M*/M'#-M %%-).)=)=#0#?#?I *> *%' & {{|,6&*#4yy}}./""$  !,>*?@ D>! w(HI:!7GH  .+;< r|   c                     t         j                  j                  |      }|j                  j	                         }t        j                  d|      }t        d|i      S )zU
    This method returns all stages as json
    Args:
        id: recruitment_id
    rg   r<  r   )rZ   rq   rr   rm   rp   r   	serializer   )r   rj   r   
all_stagesall_stage_jsons        rz   recruitment_stage_getr  6  sS     "))---8O **..0J **6:>N>233r|   recruitment.view_candidatec                 Z   | j                   j                  d      }| j                   j                         }t        j                  j                  d      }t        j                  j                  dd      }t        t        j                  j                  dd            }t        t        j                  j                  |      j                  dd            }t        | j                   |	      }t        j                  j                         rd
}nd}t        |      }	t        t        |	       |D 
cg c]  }
|
j                   c}
| j                  d<   t!        | |t#        |j$                  | j                   j                  d            ||||	t&        j(                  ||d      S c c}
w )z:
    This method render all candidate to the template
    r   Tr   Fr  emailr   username__inr   zcandidate/candidate_view.htmlzcandidate/candidate_empty.htmlfiltered_candidatesr   )r   r   r   	view_typer   	gp_fieldsemp_listr   )r   rr   r   rV   rq   r   rZ   r   r  r
   r<   rn   r   r(   rh   r	  r   re   r   r=   fields)rv   r  r  r  r   mailsexisting_emailsr   r   r  r(  s              rz   candidate_viewr  D  sc    'IKK))+M""))D)9J&&--Ud-KL""..wT.BCE/;;G$;OO !zBJ!23'Ii+ MW-Wyill-WGOO)*!*--1HI"$)00'(		
  .Xs   4F(c           	         | j                   j                         }| j                  j                  d      r.t        j
                  j                         j                  d      }nMt        j
                  j                  | j                  j                  j                        j                  d      }| j                   j                  d      rt        | |d      }t        | j                   |      j                  }| j                   j                  d      }t        ||      }t!        |      }t#        t        |       t%        j&                         }t)        | d||||d      S )	z<
    This method is used to filter Disciplinary Action.
    view_interviewschedule-interview_dateemployee_idr)   r   r   zcandidate/interview_list.html)r   r   r   r   )r   r   rk   r  rY   rq   rp   r   r   rl   rh   rr   r)   r>   r   re   r   r(   r   r   r   )rv   r  
interviews
dis_filterr   r  r  r   s           rz   interview_filter_viewr  p  s    KK))+M||56&..224==>OP
&..551144 6 

($
% 	 {{x GZ:
 zBEEJ++//&)KZ5H'I'3
,,.C'$		
	 	r|   c           	      v   | j                   j                         }| j                  j                  d      r.t        j
                  j                         j                  d      }nMt        j
                  j                  | j                  j                  j                        j                  d      }t        | j                   |      }| j                   j                  d      }t        |j                  |      }| j                   j                         }d}t        j                          }t#        | |||||d      S )z;
    This method render all interviews to the template
    r  r  r  r   r   zcandidate/interview_view.html)r   r   r   r   )r   r   rk   r  rY   rq   rp   r   r   rl   rh   r>   rr   re   r   r   r   r   )rv   r  r  r   r   r  r   r   s           rz   interview_viewr    s    
 KK))+M||56&..224==>OP
&..551144 6 

($
% 	 7;;<D++//&)KTWWk2HKK))+M.H
,,.C		
	 	r|   z$recruitment.change_interviewschedulec                     t         j                  j                  |      j                         }|j                  j                  |       t        j                  | d       |j                          t        t              S )z
    This view is used to remove the employees from the meeting ,
    Args:
        interview_id(int) : primarykey of the interview.
        employee_id(int) : primarykey of the employee
    rg   z Interviewer removed succesfully.)rY   rq   r   r   r  remover	   r   r   r   r  )rv   interview_idr  	interviews       rz   interview_employee_remover    sa     "))00L0AGGII  -W@ANN)**r|   c                     | j                   j                  d      r't               }t               }||d}t	        | d|      S t        | t        t        t        d      S )z6
    This method is used to Export candidate data
    HTTP_HX_REQUEST)export_filterexport_columnzcandidate/export_filter.htmlr%  Candidate_export)rv   modelfilter_class
form_class	file_name)rK  rr   rI   r<   r   r&   rV   )rv   r  r  r   s       rz   candidate_exportr    sb    
 ||)*+-')**
 g=wOO$&$ r|   c           
      t   | j                   j                         }t        j                  j	                         }| j                   j                  d      |j                  d      }t        | j                   |      j                  }t        | dt        || j                   j                  d            |d      S )zK
    This method renders all candidate on candidate_list.html template
    r   Tr   r   zcandidate/candidate_list.htmlr   r   r   r   r   rV   rq   rp   rr   r   r<   r   r   re   rv   r  r  s      rz   candidate_view_listr    s     KK))+M""&&(J{{{#+&&&6
 zBEEJ'!*gkkoof.EF	
 r|   c           
      t   | j                   j                         }t        j                  j	                         }| j                   j                  d      |j                  d      }t        | j                   |      j                  }t        | dt        || j                   j                  d            |d      S )zK
    This method renders all candidate on candidate_card.html template
    r   Tr   r   zcandidate/candidate_card.htmlr   r  r  r  s      rz   candidate_view_cardr    s     KK))+M""&&(J{{{#+&&&6
 zBEEJ'!*gkkoof.EF	
 r|   c                 
   t        j                  |      }|sDt        j                  | t	        d             t        | j                  j                  dd            S t        t         j                  j                  dd            }t        t        j                  j                  |      j                  dd            }|j                  j                         }t        j                  j                  |      }g }d	}	|D ]  }
|j!                  |
j"                          t%        |      d	k7  r t'        t)        |      t%        |      z        }	| j*                  j                  d
g       }t-        |t.              rt1        j2                  |      n|}d}d}t5        |      D ]8  \  }}||k(  s|t%        |      dz
  k(  rd}n||dz      }|d	k(  rd}n||dz
     } n t7        j8                         }t;        | d||||||	||d      S )z;
    This method is used to view profile of candidate.
    Candidate not foundrH  rI  r  Tr   r  r;  r   r  Nr^  zcandidate/individual.html)r(  previousnextrequests_idsr  average_rate	documentsr   )rV   findr	   r?  r   r   rK  rr   r   rq   r  r
   r   candidate_ratingrp   rW   r   ratinglenroundsumr	  
isinstancer   astliteral_evalr!  r   r   r   )rv   r'  kwargsrf  r  r  ratingsr  rating_listavg_rater  filtered_candidate_idsr  next_idprevious_idr&  req_idr   s                     rz   candidate_view_individualr    s    NN7+Mw"7 89#GLL$4$4^S$IJJ""..wT.BCE/;;G$;OO ,,002G!))00g0FIKH *6==)*
;1[)C,<<= %__001FK
 ,c2 	/0#  GK"<0 vWL)A--&uqy1z"*5195 ,,.C#&#('$"		
 r|   c                    	 t         j                  j                  |      }t        |      }d}| j                  dk(  rVt        | j
                  | j                  |      }|j                         r#|j                         }|j                  >t        j                  j                  |j                  d      j                         |_	        |j                  \|j                  j                  |j                  k7  r9|j                  j                  j                  d      j                         |_	        | j                  j                  d      d	k(  r	d
|_        d}|j                          t#        j$                  | t'        d             t)        |      S t+        | dd|i      S # t         j,                  t.        f$ r" t#        j0                  | t'        d             Y nw xY wt3        | j4                  j                  dd            S )zT
    Used to update or change the candidate
    Args:
        id : candidate_id
    rg   r   r  r   r   r  )r"  r  r8  Tr  zCandidate Updated Successfully.r  r   zCandidate Does not exists..rH  rI  )rV   rq   rr   rD   r   r   rx  r   r   rw   rb   r   ru   r   rm   r   r  r	   r   r   r   r   r>  rJ  r?  r   rK  )rv   r'  r  rf  r   r  s         rz   candidate_updater  M  s   !B!))---9$m<,>>V#(gmmmD }} $		 ))1-2]]-A-A'4'C'C#, .B . eg "* !))5%..==(778 *88BBII+4 J #eg &.
 ;;??<0F:*.M'8D""$  !,M*NO~%gEPT~VV""M2 Bw"? @AB 0 0 EFFs   FF% F% %8G G c                 
   t        j                  |      }|sDt        j                  | t	        d             t        | j                  j                  dd            S |j                  }|j                  }|j                  }|j                  }|j                  }|j                  }	|j                  j                  }
|j                   j#                         }t$        j&                  j)                  |      j+                         }|r!t        j                  | t	        d             n;t,        j&                  j)                  |      j+                         st,        j&                  j/                  ||||	d      }||_        |j3                          t4        j&                  j7                  |	      \  }}||_
        ||_        |
|_        |j3                          g }|D ]K  }t9        |j:                  ||j<                  |j>                  |j@                  
      }|jC                  |       M |r6t8        j&                  jE                  |       nt        jF                  | d       t        | j                  j                  dd            S )zt
    This method is used to convert a candidate into employee
    Args:
        cand_id : candidate instance id
    r  rH  rI  )usernamezEmployee instance already exist)employee_user_id__usernameT)employee_first_namer  phonegenderis_directly_convertedr  )titler  documentr  reject_reasonz(A employee with this mail already exists)$rV   r  r	   r?  r   r   rK  rr   namemobiler  department_idr  r  ru   
company_idcandidatedocument_setrp   r
   rq   r   rn   r.   r  converted_employee_idr   r/   get_or_creater6   r  r  r  r  r   bulk_createinfo)rv   r'  r  rf  	cand_namecand_mobcand_jobcand_dep	cand_mailcand_gendercand_companycand_documentsuser_existsnew_employee	work_infocreatedemp_document_listdocemp_documents                      rz   candidate_conversionr2  z  s     NN7+Mw"7 89#GLL$4$4^S$IJJ""I##H,,H%%H##I&&K //::L"88<<>N,,%%y%9@@BKw"C DE$$	$JQQS''.. )"& / 
 /;+4<<JJ$ K 
	7 %-	!"*	+	! 	3C#ii(zz!//L $$\2	3 (():;gIJ 0 0 EFFr|   c                    t         j                  j                  |      }	 |j                  r|j                  j                  }t
        j                  j                  t        j                  |      }t        j                  |       d|_        |j                          t        j                  | t        d             t        d|      S # t        $ r
}Y d}~d}~ww xY w)z{
    This method is used to delete the profile image of the candidate
    Args:
        obj_id : candidate instance id
    rg   NzProfile image removed.zrec-candidate-updater  )rV   rq   rr   profiler  osjoinr   
MEDIA_ROOTr  r   r	   r   r   r   r   )rv   obj_idrf  	file_pathabsolute_pathes         rz   delete_profile_imager<    s     %%))V)4M	  %--22IGGLL)<)<iHMIIm$$(M! Wa(@&AB *F;;  s   BC
 
	CCzrecruitment.view_historyc                     t         j                  j                  |      }|j                  j	                         }t        | dd|i      S )za
    This method is used to view candidate stage changes
    Args:
        id : candidate_id
    rg   z candidate/candidate_history.htmlhistory)rV   rq   rr   r>  rp   r   )rv   r'  rf  candidate_history_querysets       rz   candidate_historyr@    sN     %%))W)5M!.!6!6!:!:!<*	./ r|   c           
         d}d}| j                   j                  d      r$t        | j                   j                  d            }|r t        j                  j                  |      }t        j                  j                         }|r#t        |t              r|j                  |      }nd}t        j                  j                         }t        | d||||t               j                         d      S )zM
    This method is used to render the bootstrap modal content body form
    Nrw   rg   )stage_id__idz+pipeline/pipeline_components/send_mail.html)rm  	templatesr  rw   searchWords)r   rr   r%   rV   rq   rp   r  intr   r+   r   r$   get_template_language)rv   r'  rf  rw   r  rC  s         rz   form_send_mailrG    s     MH{{z" !<=!))---9""&&(JJx-&&H&=
#++//1I5!"$ +-CCE	

 
r|   z!recruitment.add_interviewschedulec                    t         j                  j                  |      }t         j                  j                  |      }d}t	        d|i      }||j
                  d   _        | j                  dk(  rKt	        | j                        }|j                         r%|j                          |j                  d   }|j                  d   }|j                  d   }|j                  d   }|D 	cg c]  }	|	j                   }
}	t        j                  | j                  j                   |
d	|j"                   d
| d| dd|j"                   d| d| dd|j"                   d| d| dd|j"                   d| d| dd|j"                   d| d| ddt%        d      	       t'        j(                  | d       t+        d      S t-        | |||d      S c c}	w ) r
    This method is used to Schedule interview to candidate
    Args:
        cand_id : candidate instance id
    rg   z4pipeline/pipeline_components/schedule_interview.htmlr;  r   r   r  interview_dateinterview_time:You are scheduled as an interviewer for an interview with  on  at .&   أنت مجدول كمقابلة مع     يوم     في توقيت 0   Sie sind als Interviewer für ein Interview mit  am  um  eingeplant.=   Estás programado como entrevistador para una entrevista con  el  a las E   Vous êtes programmé en tant qu'intervieweur pour un entretien avec  le     à r   interview-viewr   !Interview Scheduled successfully.rP  r   r'  )rV   rq   rr   r   rM   r  r   r   r   r   r   r   r   r7   r   rk   rl   r  r   r	   r   r   r   )rv   r'  r(  r  r   r   emp_idsrJ  rK  rx   r   s              rz   interview_schedulera    sT    !!%%%1I""))W)5JEH .))DED+5DKK(~~$W\\2==?IIK''6G''7G!../?@N!../?@N?FG8X..GEGKK))QRYR^R^Q__cdrcssw  yG  xH  HI  J@hWeVffw  yG  xH  HI  JJ7<<.X\]k\llpq  qA  AM  NWX_XdXdWeeijxiy  zA  BP  AQ  QR  S_`g`l`l_mmq  sA  rB  BF  GU  FV  VW  X$ !12
 W&IJ KLL'8dw%GHH Hs   +Gc                 \   t         j                  j                         }d}t               }||j                  d   _        | j                  dk(  rKt        | j                        }|j                         r%|j                          |j                  d   }|j                  d   }|j                  d   }|j                  d   }|D cg c]  }|j                   }	}t        j                  | j                  j                  |	d|j                    d| d	| d
d|j                    d| d| d
d|j                    d| d| dd|j                    d| d| d
d|j                    d| d| d
dt#        d      	       t%        j&                  | d       t)        d      S t+        | |d|i      S c c}w )rI  zcandidate/interview_form.htmlr;  r   r  rJ  rK  rL  rM  rN  rO  rP  rQ  rR  rS  rT  rU  rV  rW  rX  rY  rZ  r[  r\  r   r]  r   r^  rP  r   )rV   rq   rp   rM   r  r   r   r   r   r   r   r   r7   r   rk   rl   r  r   r	   r   r   r   )
rv   r  r   r   r`  r'  rJ  rK  rx   r   s
             rz   create_interview_schedulerc  %  s.    ""&&(J.H "D+5DKK(~~$W\\2==?IIK''6G''7G!../?@N!../?@N?FG8X..GEGKK))QRYR^R^Q__cdrcssw  yG  xH  HI  J@hWeVffw  yG  xH  HI  JJ7<<.X\]k\llpq  qA  AM  NWX_XdXdWeeijxiy  zA  BP  AQ  QR  S_`g`l`l_mmq  sA  rB  BF  GU  FV  VW  X$ !12
 W&IJ KLL'8fd^44 Hs   F)z$recruitment.delete_interviewschedulec                     | j                   d   }t        j                  j                  |      }|j	                          t        j                  | d       |dk(  rt        t              S t        d      S )zq
    This method is used to delete interview
    Args:
        interview_id : interview schedule instance id
    r   rg   zInterview deleted successfully.r   rP  )
r   rY   rq   rr   r  r	   r   r   r  r   )rv   r  r   r  s       rz   interview_deletere  L  sg     ;;vD!))--->IW?@v~-..GHHr|   c                 B   t         j                  j                  |      }| j                  d   }|dk(  r!t        j                  j                         }d}n6t        j                  j                  |j                  j                        }d}d}t        |      }||j                  d   _        | j                  dk(  rMt        | j                  |      }|j                         r%|j                  d	   }|j                  d   }|j                  d
   }	|j                  d   }
|j!                          |D cg c]  }|j"                   }}t%        j&                  | j(                  j*                  |d|j,                   d|	 d|
 dd|j,                   d|	 d|
 dd|j,                   d|	 d|
 dd|j,                   d|	 d|
 dd|j,                   d|	 d|
 ddt/        d      	       t1        j2                  | d        t5        d!      S t7        | ||||d"      S c c}w )#zx
    This method is used to Edit Schedule interview
    Args:
        interview_id : interview schedule instance id
    rg   r   r   r   z;pipeline/pipeline_components/schedule_interview_update.htmlr   r;  r   r  rJ  rK  rL  rM  rN  rO  rP  rQ  rR  rS  rT  rU  rV  rW  rX  rY  rZ  r[  r\  r   r]  r   zInterview updated successfully.rP  )r   r  r   )rY   rq   rr   r   rV   rp   r   r;  rh   rM   r  r   r   r   r   r   r   r   r7   r   rk   rl   r  r   r	   r   r   r   )rv   r  r  r   r  r   r   r`  r'  rJ  rK  rx   r   s                rz   interview_editrg  _  s    "))--->I;;vDv~&&**,
&&--1G1G1J1J-K
LH )4D+5DKK(~~$W\\IF==?''6G''7G!../?@N!../?@NIIK?FG8X..GEGKK))QRYR^R^Q__cdrcssw  yG  xH  HI  J@hWeVffw  yG  xH  HI  JJ7<<.X\]k\llpq  qA  AM  NWX_XdXdWeeijxiy  zA  BP  AQ  QR  S_`g`l`l_mmq  sA  rB  BF  GU  FV  VW  X$ !12
 W&GH KLL(	
  Hs   6Hc                 .   | j                   j                  d      }t        j                  j                  |      }t        j                  j                  |j                  j                        }t        |j                  j                  j                         g|D cg c]  }|j                  j                          c} }t        t        |            }|D ci c]  }|j                  |j                          }}t        d|i      S c c}w c c}w )Nr'  rg   r_  	employees)r   rr   rV   rq   rb   r   ru   rh   r   r   rp   rs   r   r   get_full_namer   )	rv   r'  rf  ry   r   all_managersunique_managersrx   employees_dicts	            rz   get_managersrn    s    kkooi(G%%))W)5M$$M4P4P4S4S$TI $$99==?2;	<%


"
"
$	<L 3|,-O ?N2:X++--N  n566 
=s   !D
"Dc                    | j                   j                  d      }| j                   j                  d      }| j                   j                  d      }| j                   j                  d      }t        j                  j                  |      }| j                  j                  d      }|D cg c])  }|j                  |j                         |j                  f+ }}|r!t        j                  j                  |      }	nt        j                  j                         }	||	z  j                         }| j                   j                  d      }
|D ]c  }t        t        j                  j                  |
      j                  dd	
            }|D ]  }t        j                   |      }t        j"                  || j$                  j&                  d      }|j)                  |      }|j+                  dt-        |i dd      j.                  df        t        j                   |      }t        j"                  || j$                  j&                  d      }|j)                  |      }|j0                  }t3        |||g      }d|_        ||_        	 |j9                          t;        j<                  | d       f tG        d      S c c}w # t>        $ r6}tA        jB                  |       t;        jD                  | d       Y d}~d}~ww xY w)zK
    This method is used to send acknowledgement mail to the candidate
    rh   subjectbodyr  r   other_attachmentsrg   template_attachmentsTr   )r   selfr6   F)r  r  zapplication/pdf)rp  rq  tohtmlzMail sent to candidatezSomething went wrongNrP  )$r   rr   r   rV   rq   r   rx  r  readcontent_typenoner   r   r+   r  r   TemplateContextrk   rl   r   r   r'   r   r  r   content_subtypeattachmentsr   r	   r   r   r2   	exceptionr?  r   )rv   r;  rp  bdycandidate_idsr  rr  r  r}  rf  template_attachment_idsr(  bodysrv  template_bdyr%  
render_bdyru  r  r;  s                       rz   send_acknowledgementr    s    <<##D)Llly)G
,,

6
"CLL((6M"")))?J--.AB@Q8<DIIK!2!23K  !))00L0A!))..0},668J%ll223IJ (<	''... / k&tk,

  	D#,,T2L&&&0I0IJG &,,W5J Re:NVV%	  ((-"""GLL,E,EF
 "((1
__t

 !''	<JJLW&>?K(<R CDDg`  	<QNN7$:;;	<s   ,.J?&K	L+K>>Lc                     t        j                  | j                  d         }|j                         D ]<  \  }}t        j
                  j                  |      }||_        |j                          > t        ddd      S )zA
    This method is used to update the sequence of candidate
    sequenceDatarg   zSequence updatedr"  )r  r]  )
r<  r=  r   r   rV   rq   rr   r   r   r   )rv   sequence_datar'  seqrm  s        rz   candidate_sequence_updater    ss     JJw||N;<M%++-   $$$0		
 $6GHHr|   c                     t        j                  | j                  d         }|j                         D ]<  \  }}t        j
                  j                  |      }||_        |j                          > t        ddd      S )zB
    This method is used to update the sequence of the stages
    r   rg   r   zStage sequence updatedr\  )
r<  r=  r   r   rb   rq   rr   r   r   r   )rv   r  rw   r  r   s        rz   stage_sequence_updater    sq     JJw||J78M&,,. #!!X!.

 7OPQQr|   c                 R   | j                   j                  d      }|dk(  r!t        j                  j	                  d      }nt        j                  j                         }|D cg c]  }t        |j                         }}|j                         }||d}t        |d      S c c}w )z9
    This method is used for select all in candidate
    r   rp   Tr   employee_idstotal_countFsafe)
r   rr   rV   rq   r   rp   r   rh   r  r   )rv   r   ri  empr  r  r%  s          rz   candidate_selectr  	  s    
 ++//&)Ke%%,,t,<	%%))+	+45CCK5L5//#K+KHGe,, 6s   $B$c                    | j                   j                  d      }| j                   j                  d      }|rt        j                  |      ni }|dk(  rwt	        |t
        j                  j                               }|j                  }|D cg c]  }t        |j                         }}|j                         }||d}	t        |	      S yc c}w )z?
    This method is used to select all filtered candidates
    r   r   rp   r   r  N)r   rr   r<  r=  r<   rV   rq   rp   r   r   rh   r  r   )
rv   r   filteredfiltersr   r  r  r  r  r%  s
             rz   candidate_select_filterr    s    
 ++//&)K{{x(H&.djj"BGe*7Y=N=N=R=R=TU /11/BCCFFCC)//1#/LG$$  Ds   Cc                 
   |}t         j                  j                  |      }| j                  j                  }| j
                  j                  d      }t        j                  j                  |||       t        t              S )zr
    This method is used to create rating for the candidate
    Args:
        cand_id : candidate instance id
    rg   r  )r;  r  r  )
rV   rq   rr   rk   rl   r   rX   r  r   r   )rv   r'  r(  r  r  s        rz   create_candidate_ratingr  4  ss     G!!%%%1I,,++K\\h'F""v; #  ())r|   zrecruitment.view_skillzonec                 :   t        | j                        j                  j                  d      }t	        |d| j                  j                  d      d      }g }|D ]  }|j                  |d           t        | j                        j                  j                  d      }t        |      }t        t        |      t        |      z
        }g }|D ]  }|j                  |g dd        |j                  |z   }t        || j                  j                  d            }| j                  j                         }	t        |	      }
t        t        |
       |j                  rd}nd	}|| j                  j                  d      |	t               |
d
}t!        | ||      S )z5
    This method is used to show Skill zone view
    Tr   skill_zone_idr   r   rC  r   r   dynamic_namezskill_zone/skill_zone_view.htmlz skill_zone/empty_skill_zone.html)skill_zonesr   r   r   r   r  )r@   r   r   r   r5   rr   r   rA   r   r   r   re   r   r   r(   r`   r   )rv   r  skill_groups	all_zoneszoneskill_zone_filteredall_zone_objectsunused_skill_zonesunused_zonesr  r  r   r%  s                rz   skill_zone_viewr  J  s    %W[[144;;d;KJ$	L I *i)* *'++699@@4@P/0c"23c)nDEL" 
 "	

  ++l:L w{{v/FGLKK))+M'Ii+45 $' " G '8W55r|   zrecruitment.add_skillzonec                    t               }| j                  dk(  r_t        | j                        }|j                         r:|j	                          t        j                  | t        d             t        d      S t        | dd|i      S )z3
    This method is used to create Skill zone.
    r   z Skill Zone created successfully.rP  z!skill_zone/skill_zone_create.htmlr   )
rP   r   r   r   r   r	   r   r   r   r   r  s     rz   skill_zone_creater  }  st      D~~"7<<0==?IIKWa(J&KL KLL+	 r|   zrecruitment.change_skillzonec                 Z   t         j                  j                  |      }t        |      }| j                  dk(  rat        | j
                  |      }|j                         r:|j                          t        j                  | t        d             t        d      S t        | d||d      S )z3
    This method is used to update Skill zone.
    rg   r   r   z Skill Zone updated successfully.rP  z!skill_zone/skill_zone_update.htmlr   sz_id)r`   rq   rr   rP   r   r   r   r   r	   r   r   r   r   )rv   r  
skill_zoner   s       rz   skill_zone_updater    s     ""&&%&0J
3D~~"7<<*E==?IIKWa(J&KL KLL+& r|   zrecruitment.delete_skillzonec                 f   	 t        j                  |      }|r0|j                          t        j                  | t        d             nt        j                  | t        d             t        t              S # t        $ r0 t        j                  | t        d             Y t        t              S w xY w)z
    function used to delete Skill zone.

    Parameters:
    request (HttpRequest): The HTTP request object.
    sz_id : Skill zone id

    Returns:
    GET : return Skill zone view template
    !Skill zone deleted successfully..Skill zone not found.Related entries exists)
r`   r  r  r	   r   r   r?  r   r   r  )rv   r  r  s      rz   skill_zone_deleter    s    =^^E*
Wa(K&LMNN7A&=$>? O$$  =w": ;<O$$=s   A&A7 7(B0/B0c                 ~   t        j                  |      }|r|j                  }|dk(  red|_        t        j                  j                  |      }|D ]  }d|_        |j                           t        j                  | t        d             ndd|_        t        j                  j                  |      }|D ]  }d|_        |j                           t        j                  | t        d             |j                          t        t              S t        j                  | t        d             t        t              S )z
    function used to archive or un-archive Skill zone.

    Parameters:
    request (HttpRequest): The HTTP request object.
    sz_id : Skill zone id

    Returns:
    GET : return Skill zone view template
    TF)r  z"Skill zone archived successfully..z$Skill zone unarchived successfully..r  )r`   r  r   ra   rq   r   r   r	   r   r   r?  r   r  )rv   r  r  r   skill_zone_candidatesis         rz   skill_zone_archiver    s"    &J((	#(J $6$>$>$E$E# %F %! + # Wa(L&MN#'J $6$>$>$E$E# %F %! + " Wa(N&OP O$$ 	w"9 :;O$$r|   c                    d}| j                   j                  d      dk(  rd}t        | j                         j                  }t	        | j                         j                  }| j                   j                  d      dk(  r_t	        | j                         j                  j                  d      }t        | j                         j                  j                  d      }n^t	        | j                         j                  j                  d	      }t        | j                         j                  j                  d	      }t        |d
| j                   j                  d      d      }g }|D ]  }|j                  |d           t        |      }t        t        |      t        |      z
        }g }	|D ]  }|	j                  |g dd        |j                  |	z   }t        || j                   j                  d            }| j                   j                         }
t        |
      }t        t        |       ||
|d}t!        | ||      S )zA
    This method is used to filter and show Skill zone view.
    zskill_zone/skill_zone_list.htmlr   r  zskill_zone/skill_zone_card.htmlr   r   Fr   Tr  r   r   rC  r  )r  r   r   )r   rr   r@   r   rA   r   r5   r   r   r   r   re   r   r   r(   r`   r   )rv   r   r  r  r  r  r  r  r  r  r  r  r%  s                rz   skill_zone_filterr    s	    1H{{v&(4$W[[144J)'++699{{{#w.-gkk:==DDuDU(588??%?P
 .gkk:==DDtDT(588??$?O
$	L I *i)* /0c"23c)nDEL" 
 "	

  ++l:L w{{v/FGLKK))+M'Ii+# G
  r|   z#recruitment.view_skillzonecandidatec                 $   t         j                  j                  |      }d}t        j                  j	                  |d      }t        || j                  j                  d            | j                  j                         |d}t        | ||      S )z
    This method is used to show Skill zone candidates.

    Parameters:
    request (HttpRequest): The HTTP request object.
    sz_cand_id : Skill zone id

    Returns:
    GET : return Skill zone candidate view template
    rg   z)skill_zone_cand/skill_zone_cand_view.htmlT)r  r   r   )sz_candidatesr   r  )	r`   rq   rr   ra   r   re   r   r   r   )rv   r  r  r   r  r%  s         rz   skill_zone_cand_card_viewr  $	  s     ""&&%&0J:H&..55 D 6 M '}gkkoof6MNkk##%G
 '8W--r|   "recruitment.add_skillzonecandidatec                 ^   t         j                  j                  |      }d}t        d|i      }| j                  dk(  r_t        | j
                        }|j                         r:|j                          t        j                  | t        d             t        d      S t        | |||d      S )	z
    This method is used to add candidates to a Skill zone.

    Parameters:
    request (HttpRequest): The HTTP request object.
    sz_cand_id : Skill zone id

    Returns:
    GET : return Skill zone candidate create template
    rg   )skill_zone_cand/skill_zone_cand_form.htmlr  r   r   zCandidate added successfully.rP  r  )r`   rq   rr   rO   r   r   r   r   r	   r   r   r   r   )rv   r  r  r   r   s        rz   skill_zone_candidate_creater  >	  s     ""&&%&0J:H!?J*GHD~~%gll3==?IIKWa(G&HI KLL'8dU%CDDr|   z%recruitment.change_skillzonecandidatec                 z   t         j                  j                  |      j                         }d}t	        |      }| j
                  dk(  rat	        | j                  |      }|j                         r:|j                          t        j                  | t        d             t        d      S t        | |||d      S )z
    This method is used to edit candidates in a Skill zone.

    Parameters:
    request (HttpRequest): The HTTP request object.
    sz_cand_id : Skill zone candidate id

    Returns:
    GET : return Skill zone candidate edit template
    rg   r  r   r   zCandidate edited successfully.rP  )r   
sz_cand_id)ra   rq   r   r   rO   r   r   r   r   r	   r   r   r   r   )rv   r  skill_zone_candr   r   s        rz   skill_zone_cand_editr  Y	  s     )0077:7FLLNO:H!?;D~~%gll_M==?IIKWa(H&IJ KLL'8d*%MNNr|   z%recruitment.delete_skillzonecandidatec                    	 t         j                  j                  |      j                          t	        j
                  | t        d             t        t              S # t         j                  $ r0 t	        j                  | t        d             Y t        t              S t        $ r0 t	        j                  | t        d             Y t        t              S w xY w)
    function used to delete Skill zone candidate.

    Parameters:
    request (HttpRequest): The HTTP request object.
    sz_cand_id : Skill zone candidate id

    Returns:
    GET : return Skill zone view template
    rg   r  r  r  ra   rq   rr   r  r	   r   r   r>  r?  r   r   r  rv   r  s     rz   skill_zone_cand_deleter  s	  s    =""&&*&5<<>!$G"HI
 O$$	 ** <w"9 :; O$$  =w": ;<O$$=   AA 2C 'CCc                    d}| j                   j                  d      dk(  rd}t        j                  j	                         }t        | j                   |      j                  }| j                   j                         }t        |      }t        t        |       t        || j                   j                  d            ||t               d}t        | ||      S )zA
    This method is used to filter the skill zone candidates
    z)skill_zone_cand/skill_zone_cand_card.htmlr   r   z)skill_zone_cand/skill_zone_cand_list.htmlr   r   )r  r   r   r   )r   rr   ra   rq   rp   r@   r   r   r   r(   re   r   )rv   r   r  candidates_filterr  r  r%  s          rz   skill_zone_cand_filterr  	  s     ;H{{v&(>#++//1J+GKK*MPPKK))+M'I()4#$5w{{v7NO  "	G  r|   c                    	 t         j                  j                  |      }|j                  }|dk(  r'd|_        t	        j
                  | t        d             n&d|_        t	        j
                  | t        d             |j                          t        t              S # t        j                  $ r0 t	        j                  | t        d             Y t        t              S w xY w)z
    function used to archive or un-archive Skill zone candidate.

    Parameters:
    request (HttpRequest): The HTTP request object.
    sz_cand_id : Skill zone candidate id

    Returns:
    GET : return Skill zone candidate view template
    rg   TFz!Candidate archived successfully..z#Candidate unarchived successfully..r:  )ra   rq   rr   r   r	   r   r   r   r`   r>  r?  r   r  )rv   r  r  r   s       rz   skill_zone_cand_archiver  	  s    ;,4488J8G#--	(-O%Wa(K&LM )-O%Wa(M&NO O$$ !! ;w"8 9:O$$;s   BB 2C"!C"c                    	 t         j                  j                  |      j                          t	        j
                  | t        d             t        t              S # t         j                  $ r0 t	        j                  | t        d             Y t        t              S t        $ r0 t	        j                  | t        d             Y t        t              S w xY w)r  rg   z Candidate deleted successfully..r:  r  r  r  s     rz   r  r  	  s    =""&&*&5<<>!$F"GH
 O$$	 ** ;w"8 9: O$$  =w": ;<O$$=r  c                 >   | j                   j                  d      s<| j                   j                  d      s!t        j                  | d       t	        d      S t
        j                  j                  |      }d}t        |t        j                  j                  |      j                  dd	
      d      }| j                  dk(  rt        | j                        }|j                         r|j                  d   }|D ]n  }t        j                  j                  ||      j!                         r3t               }||_        ||_        |j                  d   |_        |j)                          p t        j*                  | d       t	        d      S t-        | |||d      S )zp
    This method is used to Add candidate into skill zone
    Args:
        cand_id : candidate instance id
    r  r  zYou dont have permission.rP  rg   z'skill_zone_cand/to_skill_zone_form.htmlr  r  Tr   )r;  skill_zone_idsr   r   r  )r;  r  reasonz*Candidate Added to skill zone successfullyr_  )rk   r  r	   r"  r   rV   rq   rr   rT   ra   r   r  r   r   r   r   rn   r;  r  r  r   r   r   )rv   r'  r(  r   r   r  r  zone_candidates           rz   to_skill_zoner  	  s{    	<=<<  !EFg:;GHH!!%%%1I8H%088??& @ k/k5	
D ~~w||,==?++,<=K# *)1188!*$ 9 &( &8%9N2;N/37N0,0,=,=h,GN)"'')* W&RS KLL'8dw%GHHr|   c                 H   |}t         j                  j                  |      }| j                  j                  }| j
                  j                  d      }t        j                  j                  ||      }t        |      |_        |j                          t        t              S )zp
    This method is used to update the candidate rating
    Args:
        id : candidate rating instance id
    rg   r  )r;  r  )rV   rq   rr   rk   rl   r   rX   rE  r  r   r   r   )rv   r'  r(  r  r  rates         rz   update_candidate_ratingr  
  s     G!!%%%1I,,++K\\h'F""&&I;&WDf+DKIIK())r|   c                 t    t         j                  j                  dd      }d|i}t        | d|      }d|d<   |S )zA
    This method is used to render the open recruitment page
    FT)r   is_publishedr   z"recruitment/open_recruitments.htmlzALLOW-FROM *zX-Frame-Options)rZ   defaultr   r   )rv   r   r%  r   s       rz   open_recruitmentsr  
  sL     &&--U-NLG gCWMH"0HOr|   c                 d    t         j                  j                  |      }d|i}t        | d|      S )zD
    This method is used to render the recruitment details page
    rg   r   z$recruitment/recruitment_details.html)rZ   r  rr   r   )rv   rh   r   r%  s       rz   recruitment_detailsr  &
  s;     %%))R)0K{G 'A7KKr|   c                     | j                   d   }t        j                  j                  |      }t        j                  j                  |j                        j                  d      }t        | dd|i      S )zG
    This method is used to track mails sent along with the status
    r;  rg   )to__icontainsz-created_atzcandidate/mail_log.htmltracked_mails)	r   rV   rq   rr   r*   r   r  r   r   )rv   r;  r(  r  s       rz   get_mail_logr  1
  sm     ;;~.L!!%%%6I$$++)//+JSSM '46VWWr|   z)recruitment.add_recruitmentgeneralsettingc                     t         j                  j                         }|r|n	t               }d| j                  j	                         v |_         |j                          t        d      S )zG
    This method is used to update the recruitment general setting
    candidate_self_trackingr   )r[   rq   r   r   keysr  r   r   rv   r   s     rz   r  r  ?
  sU     )00668H#x)B)DH'@GKKDTDTDV'VH$HMMO	""r|   c                     t         j                  j                         }|r|n	t               }d| j                  j	                         v |_         |j                          t        d      S )zN
    This method is used to enable/disable the selt tracking rating field
    r  r   )r[   rq   r   r   r  show_overall_ratingr   r   r  s     rz   %candidate_self_tracking_rating_optionr  M
  sU     )00668H#x)B)DH#<@P@P@R#RH HMMO	""r|   c                 L   | j                   dk(  r| j                  d   }| j                  d   }t               }|j                  | ||      }|=|j                  | j
                  d<   |j                  | j
                  d<   t        d      S t        | dd	d
i      S t        | d      S )Nr   r  r  )r  passwordr;  candidate_emailzcandidate-self-status-trackingzcandidate/self_login.htmlr?  zInvalid credentials)	r   r   r8   authenticaterh   r	  r  r   r   )rv   r  r  backendr(  s        rz   candidate_loginr  [
  s    ~~W%g&02((56(R	 .7llGOON+1:GOO-.<==4w@U6V  '677r|   c                     | j                   j                  dd       | j                   j                  dd       t        j                  | d       t	        d      S )z0Logs out the candidate by clearing session data.r;  Nr  zYou have been logged out.r  )r	  popr	   r   r   rv   s    rz   candidate_logoutr  o
  sJ     OO-OO)40W9:%&&r|   c                    t        |       d   }|r| j                  j                  d      }|st        d      S t        j
                  j                  |      }|j                  j                  t        t        t        j                         d      dt                     	      j                  d
dd      }t        | d||d      S t        | d      S )3
    This method is accessed by the candidates
    r    r;  candidate-loginpkr   rJ  thenr^  r  output_fieldis_todayr  r  rK  &candidate/candidate_self_tracking.htmlr(  r  404.html)r    r	  rr   r   rV   rq   candidate_interviewannotater   r   r   todayr   r   r   )rv   self_tracking_featurer;  r(  r  s        rz   candidate_self_status_trackingr  x
  s    
 :'B' **>:-..%%))\):	22;;DJJLq9)^ < 
 (:02B
C 	 4#:>
 	

 ':&&r|   c                    t        |       d   }|r^| j                  j                  d      }| j                  j	                  d      s|| j                  j
                  j                  j                  |      j                         s>| j                  j
                  j                  j                  |      j                         r|| j                  d<   |}|st        d      S t        j                  j                  |      }|j                  j                  t        t!        t#        j$                         d	      d
t'                           j)                  ddd      }t+        | d||d      S t+        | d      S )r  r    r;  r  )candidate__id)r(  r  r  r   r  r^  r  r  r  r  rK  r  r   r  )r    r	  rr   rk   r  rl   r~   r   rn   rm   r   rV   rq   r  r  r   r   r   r  r   r   r   )rv   r'  r  r;  r(  r  s         rz   ,candidate_self_status_tracking_managers_viewr	  
  sY    :'B' **>:LL!!">?||((88??% @ fh ||((2299G9LSSU.5GOON+"L-..%%))\):	22;;DJJLq9)^ < 
 (:02B
C 	 4#:>
 	

 ':&&r|   zrecruitment.add_rejectreasonc                    t        t        | j                  j                  d                  }d}|r t        j
                  j                  |      }t        |      }| j                  dk(  rXt        | j                  |      }|j                         r1|j                          t        j                  | d       t        d      S t        | dd	|i      S )
zA
    This method is used to create/update the reject reasons
    instance_idNrg   r   r   zReject reason savedrP  z settings/reject_reason_form.htmlr   )r%   r   r   rr   r]   rq   rK   r   r   r   r   r	   r   r   r   )rv   r  r   r   s       rz   create_reject_reasonr  
  s      GKKOOM$B CDKH''++{+;X.D~~x@==?IIKW&;< KLL'=~NNr|   c                     t        | d      S )zB
    Recruitment optional feature for candidate self tracking
    z"recruitment/settings/settings.html)r   r  s    rz   r  r  
  s     '?@@r|   zrecruitment.delete_rejectreasonc                 6   | j                   j                  d      }t        j                  j	                  |      }|D ]5  }|j                          t        j                  | |j                   d       7 t        | j                  j                  dd            S )z:
    This method is used to delete the reject reasons
    idsr    is deleted.rH  rI  )r   r   r]   rq   r   r  r	   r   r  r   rK  rr   )rv   r  reasonsr  s       rz   delete_reject_reasonr  
  s     ++

e
$C"")))5G AV\\N,"?@A   0 0 EFFr|   c                    | j                         }t        j                  |      }t        j                  d|      }g }t        t        |            D ]t  }||   }|j                  d      d   }|D ]T  }	 |d   D ]I  }	|	d   D ]?  }
|j                  |
d   |
d   t        d |
d   D              t        |
d         z  d	       A K V v |S #  Y _xY w)
z
    This method is used to extract text from the pdf and create a list of dictionaries containing details about the extracted text.
    Args:
        pdf (): pdf file to extract text from
    pdfr   blockslinesspanstextsizec              3   B   K   | ]  }|j                         sd   yw)r^  N)isupper).0cs     rz   	<genexpr>z.extract_text_with_font_info.<locals>.<genexpr>  s      6"*+qyy{A6"s   )r  	font_sizecapitalization)
rw  ioBytesIOfitzopenranger  get_textr   r  )r  	pdf_bytespdf_docr0  	text_infopage_numr   r  blocklinespans              rz   extract_text_with_font_infor.  
  s     
Ijj#G
))E7
#CI#c(O 8}v&x0 	E!'N D $W 
!(((,V-1&\25 6"/3F|6" 3" #&d6l"334	
	( s   4ACCc                 $    t        | d d      }|S )z
    This method is used to rank the text

    Args:
        text_info: List of dictionary containing the details

    Returns:
        Returns a sorted list
    c                     | d   | d   fS )Nr  r    xs    rz   <lambda>zrank_text.<locals>.<lambda>  s    !K.!4D2E!F r|   Tr   r   )sorted)r)  ranked_texts     rz   	rank_textr8    s     FPTK r|   c                     g d}|D ]+  }	 t        j                  | |      }|j                  d      c S  | S # t        $ r Y ;w xY w)z
    This method is used to change the date format to YYYY-MM-DD

    Args:
        dob: Date

    Returns:
        Return date in YYYY-MM-DD
    )%Y-%m-%dz%Y/%m/%dz%d-%m-%Yz%d/%m/%Yz%Y.%m.%dz%d.%m.%Yr:  )r   strptimestrftime
ValueError)dobdate_formatsfmtparsed_dates       rz   dob_matchingrB    s]    L  	"++C5K''
33 J  		s   &7	AAc           	      B   t        |       }t        |      }t        j                  d      }t        j                  d      }t        j                  d      }t        j                  d      }ddddddddd}|D cg c]  }|d   t	        d |D              k(  r|d	   ! }	}|	rd
j                  |	      |d<   |D ]^  }|d	   }
|
s|d   s&|j                  |
      }|r|j                         |d<   |d   s/|j                  |
      }|rt        |j                               |d<   |d   s&|j                  |
      }|r|j                         |d<   |d   s&|j                  |
      }|r|j                         |d<   d|
j                         v r(|d   s#|
j                  dd      j                         |d<   |
j                  d
      D ]  }|j                         t        v s||d<     |
j                  d
      D ]  }|j                         t        v s||d<     a |S c c}w )z
    This method creates the contact information dictionary from the provided pdf file
    Args:
        pdf_file: pdf file
    z\b\+?\d{1,2}\s?\d{9,10}\bz9\b(?:\d{1,2}|\d{4})[-/.,]\d{1,2}[-/.,](?:\d{1,2}|\d{4})\bz3\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\bz\b\d{5,6}(?:-\d{4})?\brC  )	full_nameaddresscountrystatephone_numberr>  email_idzipr  c              3   &   K   | ]	  }|d      yw)r  Nr1  )r  items     rz   r  zextract_info.<locals>.<genexpr>Y  s     #N$D$5#Ns   r   rD  rH  r>  rJ  rI  rE  zAddress:rF  rG  )r.  r8  recompilemaxr6  rB  grouprB  lowerreplacestripsplit
capitalizer!   r#   )r  r)  r7  phone_patterndob_patternemail_patternzip_code_patternextracted_inforL  name_candidatesr  phone_match	dob_match	zip_matchemail_matchs                  rz   extract_infora  :  sI    ,C0II&KJJ;<M**DK JJUVMzz";< 	N  #N+#N NN 	VO  &)hh&?{# #/F|n-'..t4K1<1B1B1D~.e$#**40I(4Y__5F(Gu%e$(//5I(1(9u%j)'..t4K-8->->-@z*

$^I-F(,Z(D(J(J(LN9%JJsO 	1D K/,0y)	1 JJsO 	/D F**.w'	/C#/J ]s   :$Hc                 L    | j                   d   }t        |      }t        |      S )V
    This function is returns the data for completing the candidate creation form
    resume)rx  ra  r   )rv   resume_filecontact_infos      rz   resume_completionrg    s'     --)K,L%%r|   c                     | j                   j                  d      }t        j                  j                  |      }d}|r%|j                  j                         rt        d      }t        d|i      S )z'
    check vaccancy of recruitment
    r6  rg   z
No messager  r  )r   rr   rb   rq   ru   r#  r   r   )rv   rw   r   r  s       rz   check_vaccancyri    sa     {{y)HMM*EG%%779()G,--r|   c                 \    t         j                  j                         }t        | dd|i      S )z?
    This function is used to view skills page in settings
    z settings/skills/skills_view.htmlskills)r_   rq   rp   r   )rv   rk  s     rz   skills_viewrl    s+    
 ]] F'=&?QRRr|   c                 2   t        t        | j                  j                  d                  }| j                  j                  d      }| j                  j                  d      }d}|r t        j
                  j                  |      }t        |      }| j                  dk(  rZt        | j                  |      }|j                         r2|j                          t        j                  | d       | j                  j                  d      d	k(  rd
dlm}  |d      }t        j
                  j                         j!                         }| j                  j#                         }|j%                  d      }	|	j'                  d       |	j)                  t        |j*                               |	d   |d<   |	j-                          |j/                         }
	 |	D ]
  }|
d| z  }
 	 t1        | d|
       S t3        d      S |||d}t5        | d|      S #  Y 3xY w)z2
    This method is used to create the skills
    r  r   r   Nrg   r   r   zSkill created successfullyr8  r   r   zrecruitment-createrk  r  z&skills=?rP  )r   r   hx_valsz settings/skills/skills_form.htmlr  )r%   r   r   rr   r_   rq   rN   r   r   r   r   r	   r   django.urlsr   rp   r  r   r   r  r   rh   r  r   r   r   r   )rv   r  r   rp  r   r   r   urlmutable_getrk  r   rL  r%  s                rz   create_skillsrt    s   
  GKKOOM$B CDKkkooi(Gkkoof%GH==$$$4x(D~~',,:==?IIKW&BC{{y)V3/23 ==,,.335%kk..0$,,X6h'c(++./(.r
H%

",,. & 2(4& 112  3%q00 KLL G '=wOOs   H Hc                 6   | j                   j                  d      }t        j                  j	                  |      }|D ]5  }|j                          t        j                  | |j                   d       7 t        | j                  j                  dd            S )z2
    This method is used to delete the skills
    r  r   r  rH  rI  )r   r   r_   rq   r   r  r	   r   r  r   rK  rr   )rv   r  rk  skills       rz   delete_skillsrw    s     ++

e
$C]]!!!-F @U[[M">?@   0 0 EFFr|   c                     t        t        | j                  j                  d                  }t        j
                  j                  |      }t        | d||d      S )zF
    This function returns the bulk_resume.html page to the modal
    rj   r_  zpipeline/bulk_resume.html)resumesrj   )r%   r   r   rr   r^   rq   r   r   )rv   rj   ry  s      rz   view_bulk_resumesrz    sQ     3w{{x89:Fnn##6#:G,'V.T r|   c                    t        t        | j                  j                  d                  }t        j
                  j                  |      }| j                  dk(  rb| j                  j                  d      }|D ]#  }t        j
                  j                  ||       % t        d      }d| }t        | |       S y)	z5
    This function is used to create bulk resume
    rj   rg   r   r  )r  ru   view-bulk-resume?rec_id=N)r%   r   r   rr   rZ   rq   r   rx  r   r^   r  r   r   )rv   rj   r   r  r  rr  query_paramss          rz   add_bulk_resumesr    s     3w{{x89:F%%))V)4K~~%%g. 	DNN!!* " 	 ()!&*3%~.//  r|   c                    | j                   j                  d      }| j                   j                  d      }t        j                  j                  |      j                          t        d      }d| }t        | |       S )z
    Used to delete resume
    r  rj   r   r|  r}  )	r   r   rr   r^   rq   r   r  r   r   )rv   r  rj   rr  r~  s        rz   delete_resume_filer  
  ss     ++

e
$C[[__X&F
NN%,,.
$
%CfX&LseL>*++r|   c                 F   t        j                  | j                        }g }t        t	        |            D ]X  }|j                  |      }|j                         }t        j                  d|j                               }|j                  |       Z |j                          |S )zw
    This method is used to extract the words from the pdf file into a list.
    Args:
        pdf_file: pdf file

    z\b\w+\b)r#  r$  r  r%  r  	load_pager&  rN  findallrR  extendclose)pdf_filepdf_documentwordsr*  r   	page_text
page_wordss          rz   extract_words_from_pdfr    s     99X]]+LE#l+, !%%h/MMO	ZZ
IOO,=>
Z ! Lr|   c                    t         j                  j                  |      j                         }|j                  j                  dd      }|j                  j                         }|j                  d      }t        |j                  dd            }g }|D ]Q  }t        |j                        t        fd|D              }	||	d}
t              sd|
d	<   |j                  |
       S |D cg c]  }|d
   j                  |v s| }}|D cg c]  }|d
   j                  |vs| }}t        |d d      }t        |d d      }||z   }t!        | d||d      S c c}w c c}w )z
    This function returns the matching resume table after sorting the resumes according to their scores

    Args:
        rec_id: Recruitment ID

    rg   r  Tr   )is_candidaterh   c              3   B   K   | ]  }|j                         v   y wN)rR  )r  rv  r  s     rz   r  z#matching_resumes.<locals>.<genexpr>G  s     #OuEKKMU$:#Os   )rd  matching_skills_count	image_pdfrd  c                     | d   S Nr  r1  r2  s    rz   r4  z"matching_resumes.<locals>.<lambda>W  s    Q/F-G r|   r5  c                     | d   S r  r1  r2  s    rz   r4  z"matching_resumes.<locals>.<lambda>Z  s    +B)C r|   zpipeline/matching_resumes.html)matched_resumesrj   )rZ   rq   r   r   rk  r  rd  rp   r   r  r  r  r  r   rh   r6  r   )rv   rj   r   rk  ry  r  is_candidate_idsresume_ranksrd  r  rL  rankcandidate_resumesnon_candidate_resumesranked_resumesr  s                  @rz   matching_resumesr  3  s    %%,,,7==?K++G$+?F  $$&G>>t>4L<33Dt3DEL "&v{{3 ##O#O O ;PQ5z $DD!" &h):):>N)N  &h):):BR)R  ##GQU CT +->>N(-	
 !s   1E"E"E')E'c                     | j                   j                  d      }t        t        |      }|j                  }t        |      }t        |      S )rc  	resume_idrg   )r   rr   r   r^   r  ra  r   )rv   r  
resume_objre  rf  s        rz   matching_resume_completionr  i  s@     ,I"6i8J//K,L%%r|   zrecruitment.view_rejectreasonc                 \    t         j                  j                         }t        | dd|i      S )z<
    This method is used to view all the reject reasons
    zsettings/reject_reasons.htmlreject_reasons)r]   rq   rp   r   )rv   r  s     rz   candidate_reject_reasonsr  w  s3     "))--/N/2BN1S r|   c           
          g }g }g }g }t         j                  j                  dd      }|D ]  }t        j                  dd      }t        j                  dd      }t        j                  dd      }	|j                  d| d| d|	 d       |j                  d	| d| d|	 d
       |j                  |        |j                  |j                  j                  d      j                                 t        ||||t        d      dd      S )z
    function used to show hired candidates in all recruitments.

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns:
    GET : return Json response labels, data, background_color, border_color.
    FTr  r      zrgba(z, z, 0.2zrgb())r  z#No records available at the moment.)labelsr   background_colorborder_colorr  r  )
rZ   rq   r   randomrandintr   r(  r  r   r   )
rv   r  r   r  r  r   r   redgreenblues
             rz   hired_candidate_chartr    s     FDL&&--Ud-KL# FnnQ$q#&~~a%%uBugRvU CDd3%r%4&:;'K))00t0<BBDEF  0(>?	
 	 	r|   c                    | j                   j                  d      r| j                   j                  d      nd}t        d|i      }| j                  dk(  r_t        | j                        }|j                         r:|j                          t        j                  | t        d             t        d      S d|i}t        | d|	      S )
z
    This function is used to create document requests of an employee in employee requests view.

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns: return document_request_create_form template
    r;  Nr   r   z%Document request created successfully*<script>window.location.reload();</script>r   z+documents/document_request_create_form.htmlr  )r   rr   rG   r   r   r   r   r	   r   r   r   r   )rv   r;  r   r%  s       rz   candidate_document_requestr    s     ,3;;??>+J'PT  (0NOD~~+GLL9==?IIKWa(O&PQ LMM 	G > r|   c                    t         j                  j                  |      }t        d|i      }t         j                  j	                  |      |j
                  d   _        | j                  dk(  rjt        | j                  | j                        }|j                         r:|j                          t        j                  | t        d             t        d      S ||d}t!        | d|	      S )
z
    This function is used to create documents from employee individual & profile view.

    Parameters:
    request (HttpRequest): The HTTP request object.
    emp_id (int): The id of the employee

    Returns: return document_tab template
    rg   r;  r   r   zDocument created successfully.r  )r   r;  z#candidate/document_create_form.htmlr  )rV   rq   rr   rE   r   r  r   r   r   rx  r   r   r	   r   r   r   r   )rv   rh   r;  r   r%  s        rz   document_creater    s     $$((B(/L .,)GHD+4+<+<+C+Cr+C+JDKK(~~$W\\7==A==?IIKWa(H&IJ LMM $G '@'RRr|   c                     t        t        |      }| j                  j                  d      }| j                  dk(  r%||_        |j                          t        ddd      S t        dddd	
      S )z
    This function is used to create documents from employee individual & profile view.

    Parameters:
    request (HttpRequest): The HTTP request object.

    Returns: return document_tab template
    rg   r  r   Tz#Document title updated successfully)r   r  FzInvalid requesti  )r  )r   rW   r   rr   r   r  r   r   )rv   rh   r  r  s       rz   update_document_titler    sq     !!2r:H<<G$D~~)NO
 	
 *;<S
 	
r|   z$recruitment.delete_candidatedocumentc           
      L   	 t         j                  j                  |      }|r]|j                          t	        j
                  | t        d|j                          d|j                         j                   d             nt	        j                  | t        d             d| j                  v r?| j                  j                  d      j                  d      rt        |        t               S t        d	      S # t        $ r" t	        j                  | t        d             Y w xY w)
a  
    Handle the deletion of a document, with permissions and error handling.

    This view function attempts to delete a document specified by its ID.
    If the user does not have the "delete_document" permission, it restricts
    deletion to documents owned by the user. It provides appropriate success
    or error messages based on the outcome. If the document is protected and
    cannot be deleted, it handles the exception and informs the user.
    rg   zDocument request z for z deleted successfullyzDocument not foundz You cannot delete this document.r  r  r  )rW   rq   r   r  r	   r   r   r   r  r?  r   rK  rr   
startswithr-   r   )rv   rh   r  s      rz   document_deleter    s    G$,,33r3:OO'(8'9x~~?O?[?[>\\qr NN7A&:$;<
 7<<'GLL,<,<-j- 	w~HII  Gw"D EFGs   BC8 8(D#"D#c                 v   t         j                  j                  |      }t        |      }| j                  dk(  rlt        | j
                  | j                  |      }|j                         r:|j                          t        j                  | t        d             t        d      S ||d}t        | d|      S )	a   
    This function is used to upload documents of an employee in employee individual & profile view.

    Parameters:
    request (HttpRequest): The HTTP request object.
    id (int): The id of the document.

    Returns: return document_form template
    rg   r   r   zDocument uploaded successfullyr  )r   r  zcandidate/document_form.htmlr  )rW   rq   rr   rH   r   r   rx  r   r   r	   r   r   r   r   )rv   rh   document_itemr   r%  s        rz   file_uploadr     s     &--11R18M&>D~~*LL'---
 ==?IIKWa(H&IJ LMM !G '97KKr|   c                    t         j                  j                  |      j                         }d|i}|j                  r|j                  j
                  }t        j
                  j                  |      d   dd j                         }t        |      }	 t        |d      5 }|j                         }ddd       |d<   ||d<   ||d<   t        | d	|      S # 1 sw Y   %xY w#  d}Y .xY w)
z
    This function used to view the uploaded document in the modal.
    Parameters:

    request (HttpRequest): The HTTP request object.
    id (int): The id of the document.

    Returns: return view_file template
    rg   r  r^  Nrbfile_contentfile_extensionrx  zcandidate/view_file.html)rW   rq   r   r   r  r  r5  splitextrR  r0   r$  rw  r   )	rv   rh   document_objr%  r9  r  rx  r  r  s	            rz   	view_filer  >  s     %,,33r3:@@BLLG  ))..	)))4Q7;AAC'7	 i& +$#yy{+
 #/$2 !".'5w??+ +	 Ls$   C!  C1C! CC! !C'z$recruitment.change_candidatedocumentc                    t        t        |      }|j                  rAd|_        |j	                          t        j                  | t        d             t        d      S t        j                  | t        d             t        d      S )z
    This function used to view the approve uploaded document.
    Parameters:

    request (HttpRequest): The HTTP request object.
    id (int): The id of the document.

    Returns:
    rg   approvedzDocument request approvedNo document uploadedr  )
r   rW   r  r  r   r	   r   r   r?  r   )rv   rh   r  s      rz   document_approver  a  st     %%62>L(!$?"@A DEE 	w"8 9:DEEr|   c                    t        t        |      }t               }|j                  r| j                  dk(  rt        | j
                  |      }|j                         r|j                  d      }|j                  |_        d|_	        |j                          t        j                  | t        d             t        d      S t        j                  | t        d	             t        d      S t        | d
||d      S )z
    This function used to view the reject uploaded document.
    Parameters:

    request (HttpRequest): The HTTP request object.
    id (int): The id of the document.

    Returns:
    rg   r   r   Frs  rejectedzDocument request rejectedr  r  zcandidate/reject_form.html)r   r  )r   rW   rF   r  r   r   r   r   r  r  r	   r?  r   r   r   )rv   rh   r  r   r   s        rz   document_rejectr  y  s     %%62>L&(D>>V#.w||lSD}}99E92-5-C-C*&0#!!#w*E(FG#$PQQw"8 9:HII$|4 r|   c                    t         j                  j                  |      }| j                  j                  r| j                  j
                  nd}| j                  j                  r$| j                  j
                  j                         n|j                  }t        d|i      }| j                  dk(  rt        | j                  | j                        }|j                         rd|j                  d      \  }}||_        |j                  |_        ||_        d|_        |j                          |j$                  j'                  |       t)        j*                  | t-        d	             t/        j0                  t2              5  |j4                  j6                  j9                         }|j                  j:                  j9                         }	||	z  }
|
j=                         D cg c]  }|j>                   }}tA        jB                  |||| d
| d| d| | d| d| d| d| d| ddtE        dd|i      
       ddd       tG        | d||d      S c c}w # 1 sw Y   xY w)rr  rg   Nr;  r   r   Frs  Tru  z# has added a note on the candidate u	   أضاف u"    ملاحظة حول المرشح z	 hat dem u    eine Notiz hinzugefügt.u    agregó una nota al rO  u    a ajouté une note à r   zcandidate-view-individualr'  )r  )	labelr   r   r   r   r   r   r   r   r  rv  )$rV   rq   rr   rk   is_authenticatedrl   rj  r  rR   r   r   rx  r   r   r;  rw   ry  r  rz  r   r	   r   r   r   r   r   ru   r   rp   rs   r   r   r7   r   r   r   )rv   r'  r(  ry  r  r   r{  r|  r   rs   rk  rx   r   s                rz   candidate_add_notesr    sJ    !!%%%1I.5ll.K.K**QUJ <<(( 	!!//1^^ 
 .'!:;D~~LLMM
 ==?#'99E9#: D. )D%..DM(DO&*D#IIK  0Wa(C&DE$$Y/ $33HHLLN!*!3!3!B!B!F!F!H'.8>J>S>S>U2:H--  #!7"Ei[Q'w.PQZP[\$gYyk9RS$g%:9+QG$g%<YKqI($3Y<P0 0"	
 ' s    A I"I5AIII&c                    | j                   j                  }|j                  j                  t	        t        t        j                         d      dt                           j                  ddd      }t        | d	d
|i      S )Nr   r  r^  r  r  r  r  rK  ztabs/scheduled_interview.htmlr  )rk   rl   interviewschedule_setr  r   r   r   r  r   r   r   )rv   rx   r  s      rz   employee_profile_interview_tabr    sz     ||((H//88

15%
 9  hz,.>?  ':\:<VWWr|   )F)r   r  (  __doc__r  r   r!  r<  r5  r  rN  r   r   	itertoolsr   urllib.parser   r#  djangor   django.confr   django.contribr	   django.contrib.auth.modelsr
   django.corer   django.core.cacher   r  django.core.mailr   django.core.paginatorr   django.db.modelsr   r   r   r   r   django.httpr   r   r   django.shortcutsr   r   r   rq  r   django.utilsr   django.utils.translationr   r   django.views.decorators.httpr   base.backendsr   base.context_processorsr    base.countriesr!   r"   r#   
base.formsr$   base.methodsr%   r&   r'   r(   r)   base.modelsr*   r+   r,   r-   employee.modelsr.   r/   employee.viewsr0   horillahorilla.decoratorsr1   r2   r3   r4   horilla.group_byr5   horilla_documents.modelsr6   notifications.signalsr7   recruitment.authr8   recruitment.decoratorsr9   r:   r;   recruitment.filtersr<   r=   r>   r?   r@   rA   rB   recruitment.formsrC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   recruitment.methodsrU   recruitment.modelsrV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   recruitment.views.paginator_qryre   r{   rt   r   r   r   r   r   user_recruitmentsr   r  r  r   r  r)  r+  r.  r3  r@  rE  rL  rQ  rT  rW  rY  ri  rp  r}  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r(  r  r  r  r  r  r  r  r  r  r  r2  r<  r@  rG  ra  rc  re  rg  rn  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r.  r8  rB  ra  rg  ri  rl  rt  rw  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r1  r|   rz   <module>r     s     	  	  	 #  !     # + # , ) + H H H H @ @  ! 6 = 0 A 3 3 '  S R = +   / - ( ; 
      ( 4    " :84,^ 780 9  0f 89! : !H :;;  < ;|   67 8 @ 67: 8  :z 12 3  673  8 2 67! 8 !0 67 8 ( 67! 8  !H 127$ 3 7$t 89 :   :;G < G$ 23!N 4  !NH $DE%T F  %TP $DEG F G $DE	G F 	G 678 8 8v 45 6   34 5  < 34 5  4 67 8 * 67 8 < ?  ?$ F  F$ 
  
       34G 5  G 89	8 : 	8 /00D 1 0Df 23 4 :$ 23K  4 K0 ./P 0  P$ vh
    
 56% 7 %P 56	4 7 	4 67' 8 'T !  !H  @ >?+ @ +  * 67 8 & 67 8  & 45@ 6 @F 67(G 8 (GV 676G 8 6Gr 67< 8 <( 45 6  67 8  < ;<"I =  "IJ ;<!5 =  !5H >?I @  I  >?/ @  /d7* 67>E 8 >EB 67
I 8 
I $>?	R @ 	R - -& % %, * ** 45.6 6 .6b 34 5  $ 67 8  & 67% 8 %. 67#% 8 #%L 455 6  5p =>. ? .0 <=E >  E0 ?@O A  O. ?@% A %, => ? 4 ?@% A %8 ?@% A %* &I  &IR * * L /0	X 1 	X @A# B  # @A# B  #8(' ' ': ./$' 0 $'N 34O 5  O$ 34A 5 A 67	G 8 	GD :JZ&	. S S ,P ,P^ 67	G 8 	G ./	 0  	 ./0 0  0( ./, 0  ,0 ./0 0  0f ./	& 0 	& 45 6     F  8 S  S6 
 
0 9: J ;   JF L  L8 @  @B 9:F ;  F* 9: ;  D ; ;| X  Xr|   