
    si                       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" 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/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z?m@Z@mAZA ddlBmCZC ddlDmEZEmFZFmGZGmHZHmIZI ddlJmKZKmLZLmMZMmNZN ddlOmPZPmQZQ ddlRmSZS ddlTmZ ddlUmVZVmWZWmXZXmYZYmZZZ ddl[m\Z\ dd l]m^Z^ dd!l_m`Z` dd"lambZb dd#lcmdZdmeZemfZfmgZg dd$lhmiZimjZjmkZkmlZlmmZmmnZnmoZo dd%lpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZ dd&lmZ dd'lmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ dd(lmZmZ dd)lmZ dd*Zdd+Zd, ZeYeW eZd-.      d/                      ZeY eZd0.      d1               ZeY eZd2.      eWd3                      Zd4 Zi ZeY efd0.      d5               ZeYeW efd0.      d6                      ZeY efd0      d7               ZeY efd0.      dd8efd9              ZeY efd:.      d;               ZeY efd:.      d<               Zd= ZeYeW efd0.      d>                      ZeY efd:      d?               ZeY eZd0.      d@               ZeY eZdA.      dB               ZeYeW efdC.      dD                      ZeYeW egd2.      dE                      ZeY egd2.      dF               ZeY egd2.      dG               ZeY efd:.      dH               ZeYeW eddI.      dJ                      ZeYeW efdK.      ddL                     ZeYeW efdK.      ddM                     ZeY efdN.      dO               ZeY efdN.      dP               ZeYeWdQ               ZeYeWdR               ZeYdS        ZeYeWdT               ZeYeW efdK.      dU                      ZeY eZd:.      dV               ZeY efdW.      dX               ZeY eZdY.      dZ               Zd[ ZeY efdC.      eWd\                      ZeY egdC      d]               ZeYeW efd^      d_                      ZeY e9d`g      eWda                      ZeY eVd^dbgc      dd               ZeY eZd^.      de               ZeY eZdf.      dg               ZeYeWdh               ZeYdi        ZeY efdj.      dk               ZeYdl        ZeY eZdf.      dm               ZeYeW eZdf.      dn                      ZeY efdf.      do               ZeY efdf.      dp               ZeY efdf.      dq               ZeY efdf.      dr               ZeY efdf.      ds               ZeY eddf.      dt               ZeY eddf.      du               ZeY efdf.      dv               Zdw ZeY eddf.      dx               ZeY efd:dygc      dz               Ze"j                  eY efd:.      d{                      ZeY efd:.      d|               ZeY eZd}.      d~               ZeYeW efd:.      dd                     ZeYeW efd.      d                      ZeYeW efd.      d                      ZeYeW efd.      d                      ZeYeW efdj.      d                      Zd Zd ZeY efd:.      d               ZeY efd:.      d               ZeY egdC.      d               ZeYd        ZeYd        ZeYd        ZeY efd.      d               ZeYeW efd.      d                      ZeYeW efd.      d                      ZeY efd.      d               ZeY efd.      d               ZeYeW efd.      d                      ZeY efd.      d               ZeYeW efd.      d                      ZeYeW efd.      d                      ZeY efd.      d               ZeY efd.      d               ZeY efd.      d               ZeY efd.      d               ZeYeWd               ZeYd        Zd Zd ZeY efdf      d               ZeYeW eZd      d                      ZeYeW eZd      d                      Zd Zd Zeed        Z eY efd^      d               ZeYeW eZd      d                      ZeY eZd0      d               ZeY eZd      d               Zd Zd Zd Zd Zd Z	d Z
eYd        ZeYd        ZeY eZd      dd              ZeYeW efd^      d                      ZeYeW efd^      d                      ZeYeW efd^      d                      Zd ZeYeW efd^      d                      ZeY efd^      d               ZeY eZdë      dĄ               ZeYdń        ZeYdƄ        ZeYeWdǄ               ZeYdȄ        ZeYeW efdɫ      dʄ                      ZeeeWd˄               ZeeeWd̄               ZeYeW efdͫ      d΄                      ZeYeW efdͫ      dτ                      ZeedЄ        ZeYeWdф               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)IntegrityErrortransaction)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)any_permission_requiredhx_request_requiredloggerlogin_requiredpermission_required)group_by_queryset)Document)notify)CandidateAuthenticationBackend)all_manager_can_enter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LinkedInAccountRecruitmentRecruitmentGeneralSettingRecruitmentSurveyRejectReasonResumeSkill	SkillZoneSkillZoneCandidateStage
StageFiles	StageNote)delete_postpost_recruitment_in_linkedin)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allrg   objectsgetstage_managersis_recruitmentmanagerrecruitment_idro   )requeststage_idrr   employee	stage_objs        ;/var/www/python-projects/worksol/recruitment/views/views.pyis_stagemanagerr      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
    rn   )
rr   rs   recruitment_setru   rv   rw   r_   rx   ry   recruitment_managers)r}   rq   rr   r   recruitment_objs        r   r{   r{      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pager~   r   Fr   )rF   GETrt   rw   qsorder_byappendr@   candidate_setfilterstagestrro   r8   ry   object_list)r}   recruitmentsgroupsrecr   all_stages_grouperdatar   stage_candidates	page_namer   ordered_datagroupersfounds                 r   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(  rt        | j
                        }|j                         r|j                         }|j                  j                  t        j                  j                  |j                  j                  d                   |j                  j                  t         j                  j                  |j                  j                  d                   |j"                  r#|j$                  rt'        | ||j$                         |j(                  d	   D ]<  }|j*                  j-                         D ]  }|j.                  j1                  |        > t3        j4                  | t7        d
             t9        j:                  t<              5  |j                  j?                  d      }|D cg c]  }|j@                   }}tC        jD                  | jF                  jH                  |ddddddtK        d      	       ddd       tM        d      S tO        | d||d      S c c}w # 1 sw Y   tM        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   )(rN   r   dictry   methodr   is_validsaver   setr0   rx   r   r   getlistr   r.   publish_in_linkedinlinkedin_account_idrk   cleaned_datarecruitmentsurvey_setrw   recruitment_idsaddr	   success_
contextlibsuppress	Exceptionselect_relatedr   r:   sendrr   rs   r   r   r   )	r}   r   r   r   surveysurmanagersr   userss	            r   r   r      sZ    #$D{{&w{{/?/?/AB&-kkooi&@F&J	"PT  ~~&w||4==?"iikO0044  ''99,,-CD ( 
 **..##**$))2C2CDT2U*V  33#77,_o.Q.Q ++,>? =!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    J-5J(=J-(J--K 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updater_   rx   r   rw   ry   rC   itemsr   rl   r   	urlencode)r}   r   r   initial_tag
filter_objr   keyvalues           r   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                 0   t        j                  |      }|s*t        j                  | t	        d             t        d      S 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%                         r|j'                         }|j(                  d	   D ]<  }|j*                  j                         D ]  }|j,                  j/                  |        > |j'                          t1        |j2                        d
kD  r:|j4                  r.|j6                  r"t9        |       t;        | ||j6                         t        j<                  | t	        d             t?        | dd|i      }	tA        jB                  tD              5  |jF                  jI                  d      }
|
D cg c]  }|jJ                   }}tM        jN                  | jP                  jR                  || d| d| d| d| ddtU        d      	       ddd       t        |	jV                  jY                  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
    z<The recruitment entry you are trying to edit does not exist.*<script>window.location.reload();</script>)r   instancer   r   Nr   r   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   )-r_   findr	   errorr   r   ra   rx   r   distinctr   template_idrw   rN   r   ry   r   r   r   r   r   r   r   r   lenchanged_datar   r   rj   rk   r   r   r   r   r   r   r   r   r:   r   rr   rs   r   contentdecode)r}   rq   r   survey_template_listr   r   r   r   r   responser   r   r   s                r   recruitment_updater   G  s    "&&v.OQUV	
 HII(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<==   "4$$%)#77';;00/2U2U 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   	 L)L<ALLLc                 @    t        | d      }|j                  |      } | S )zA
    This method is used to generate common paginator limit.
       r   get_page)qrysetpage_number	paginators      r   !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)rC   r   r   ru   rF   r@   r  ry   r   r  r   )r}   r   r   stage_filtercandidate_filterr   r  s          r   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   )rz   r|   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   )rC   r   rF   r@   ry   r   r   rr   has_permr   rs   values_listr   r   r   r*   r_   CACHEr   sessionsession_keyr   r   r   r   )r}   r   r	  r
  r  r   stage_recruitment_idsr   r   previous_datar  r  page_objr   s                 r   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
    r~   rn   Tr   )r   rg   rx   ry   r   r   countr   )r}   r~   r   r  s       r   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
    rq   rn   r   r   recruitment_id__idz+pipeline/components/stages_tab_content.htmlr  z7pipeline/kanban_components/kanban_stage_components.htmlr   )r   ordered_stagesr   )	r   r_   rx   ry   r  r  r  r   r   )r}   r  r|   r   r#  r   s         r   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
    orderr~   r   r   rn   r  )r   r~   hiredVaccancy is filledmessagevacancy)r   r   r  ry   r  r  r   first	enumerater   
stage_typer|   is_vacancy_filledr   r,  r   )r}   
order_listr~   r   contextindexcand_id	candidates           r   #update_candidate_stage_and_sequencer6  +  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 ]e  \  }}t        j                  | j                  j
                  dz         d   j                  |      }|j                  |||j                  dk(         g t        |      S )	r'  r(  r~   r   r   rn   r  r)  )r   r~   r)  )r   r   r  ry   r  r  r   r-  r.  r   r/  r   )r}   r1  r~   r   r   r3  r4  r5  s           r   update_candidate_sequencer8  E  s     $$W-J{{:&H		'//--
:;HE	8		 

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

&G&
 	 	U53C3Cw3N 	 	
	
 r   c                 @    t        | d      }|j                  |      } | S )z
    Limited pagination
    
   r   )r   r   r  s      r   limited_paginator_qryr;  _  s%     (B'I!!$'HOr   c                 X   | j                   j                  d      }t        j                  | j                  j                  dz         d   j                  |      j                         }t        j                  | j                  j                  dz         d   j                  |      }d}| j                   j                  d      d	k(  rd
}t        j                         }t        | |t        || j                   j                  d            |t        |j                         di       |d      S )z
    Candidate component
    r~   r   r   rn   r  r~   z2pipeline/components/candidate_stage_component.htmlr  r  z;pipeline/kanban_components/candidate_kanban_components.htmlcandidate_pager|   )r  r   r   r  )r   ry   r  r  r  r   r-  r   r  r   r;  getattr)r}   r~   r   r  r   r  s         r   candidate_componentr@  h  s    {{z*H		'//--
:;HE	8		 

 7??66CDfef  DH{{v&(P
,,.C/GKKOO,<= :++-/?D	
 r   c                 $   | j                   dk(  rL| 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&                  | t!        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&                  | t!        d             t-        |      S | j                  d   }| j                  d   }t        j                  j                  |      }t        j                  j                  |j                  |      j                         }|r6||_        |j                          t%        j&                  | t!        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Truern   )r|   ro   r)  r*  r+  r,  Candidate stage updatedCandidate not found.candidate_idr~   )r   r   r   ry   jsonloadsrZ   rx   rg   r   r|   r-  r~   r   r/  r0  r   r,  r	   r   DoesNotExistr   r   r$  )r}   rB  r~   r2  r4  r5  r   rH  s           r   change_candidate_stagerL    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 ((!4M2NOGD G$$#C%--11V1<	,,#,#;#; - %'  ).I&NN$''72 //AAC123G1HGI.161E1E1M1MGI.).I&NN$$$Wa0I.JK G$$;;~.L{{:&H!!%%%6IMM   //H ! eg 
 "	!$=">?7##? !-- GNN7A.D,EFG$ )) Cw*@(ABG$$Cs&   +C!LC8M 2MM2NN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   ry   r_   rx   rw   rZ   r   rg   r   )r}   rN  r   r  r   s        r   recruitment_pipeline_cardrQ    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
    rn   FTRecruitment Does not exists..HTTP_REFERER/)r_   rx   ry   r   r   rK  OverflowErrorr	   r   r   r   META)r}   rq   r   s      r   recruitment_archiverX    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
    rn   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   )rg   rx   ry   rU   r   r   r   r	   r   r   r   r   r   rz   r   r   r:   r   rr   rs   r   r|   r   r   r   )r}   r~   r   r   r   r   r   s          r   stage_update_pipeliner]    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
    rn   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   )r_   rx   ry   rN   r   r   r   r	   r   r   r   r   r   r   r   r   r:   r   rr   rs   r   r   r   r   r   )r}   rq   r   r   r   r   r   r   s           r   recruitment_update_pipeliner`    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
    rn   TzRecruitment closed successfullyrS  rT  rU  )r_   rx   ry   r   r   r	   r   rK  rV  r   r   r   rW  r}   rq   r   s      r   recruitment_close_pipelinerc  @  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
    rn   Fz Recruitment reopend successfullyrT  rU  )	r_   rx   ry   r   r   r	   r   r   rW  rb  s      r   recruitment_reopen_pipelinere  P  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
    rC  rn   noChangezNo change detected.typer+  r=  N   r|   rp   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   rF  dangerz Something went wrong, Try agian.)$r   rZ   rx   ry   history_setrw   r-  rg   r~   r   r   r   ru   schedule_dater   r|   rr   rv   r{   ro   r/  r)  canceledstart_onboardr   r   r   r   rz   r   r   r:   r   rs   r   r   )r}   r4  r~   candidate_objhistory_querysetr   ro  !stage_manager_on_this_recruitmentr   r   r   s              r   candidate_stage_updateru  ^  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
    rn   -id+pipeline/pipeline_components/view_note.html)candnotes)rZ   rx   ry   stagenote_setrw   r   r   )r}   r4  rr  rz  s       r   	view_noter|    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
    rH  r   r   Fcommitrn   Note added successfully..z%cbv/candidates/profile_notes_tab.htmlr5  	note_form)rV   r   r   FILESr   r   rZ   rx   ry   rH  r~   rr   rs   
updated_bystage_filesr   r	   r   r   r   )r}   pkr   noteattachment_idsr5  rr  s          r   add_noter    s     ."!56D~~LLMM
 ==?#'99E9#: D.!))---4I )D%..DM%ll77DOIIK  0Wa(C&DE%%))R)0M/&	
 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 )r~  rH  r   r   Fr  rn   r  	view-noter4  rw  rx  )r  ry  rz  )rV   r   r   r  r   r   rZ   rx   ry   rH  r~   rr   rs   r  r  r   r	   r   r   r   r{  rw   r   r   )r}   r4  r   r  r  r5  rr  rz  s           r   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
    rn   r   Note updated successfully...r  r  z-pipeline/pipeline_components/update_note.htmlr   )ri   rx   ry   rW   r   r  r   r   r	   r   r   rH  ro   r   r   )r}   note_idr  r   r4  s        r   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  rn   r   r  z8pipeline/pipeline_components/update_note_individual.htmlr   r   r   )ri   rx   ry   rV   r   r  r   r   r	   r   r   r   r   r   r   )r}   r  r  r   r   s        r   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
    rn   r   filesr  r  r  )ri   rx   ry   r   r  r   rh   creater   ro   r  r   r   rH  r}   ro   r  r  	files_idsfiler   s          r   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  rn   r   r  r  zFiles uploaded successfullyz/recruitment/add-note/rU  )ri   rx   ry   r   r  r   rh   r  r   ro   r  r   r	   r   r   r   rH  r  s          r   add_more_individual_filesr  6  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
    rO  rn   zFile deleted successfully)rh   rx   ry   deleter	   r   r   r   )r}   ro   scriptr  s       r   delete_stage_note_filer  J  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  )rh   rx   ry   r{  rw   r-  rH  ro   r  r	   r   r   r   )r}   ro   r  r  r4  s        r   delete_individual_note_filer  X  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 )Nrn   )candidate_can_viewzCandidate view status updatedr  r  )ri   rx   r   r   r-  r  r	   r   r   r   rH  ro   )r}   ro   r  s      r   candidate_can_view_noter  h  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   rn   r+  congratulations)r   rZ   rx   ry   ro  r   r   )r}   rH  ro  rr  s       r   candidate_schedule_date_updater  s  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
    r|   r   r   rz   r   T)r|   r   r   Nrj  zStage added.r   zStage z is updated on recruitment z@,                          You are chosen as one of the managersu   تم تحديث المرحلة u.    في التوظيف                          r_  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 gerentesr[  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   )"rU   r   ry   r   r   r   r   rz   r   r0   rx   r   r   r   r|   rg   r   lastr   r	   r   r   r   r   r   r   r   r:   r   rr   rs   r   r   r   )r}   r   r   r   
rec_stagesr   r   r   s           r   r   r     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_activer|   rpagezstage/stage_view.htmlzstage/stage_empty.htmlr   )r   r   r   r   )rg   rx   rw   r   r8   r   ry   rF   rU   ru   r   rl   )r}   r   r   r   r   r   s         r   
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)rF   r   r   r   r   r   r*   rg   r   rl   ry   rW  )r}   rq   r   r  	data_dicts        r   
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

    rn   r   r   rZ  r   r   r   r   zstage/stage_update_form.html)rg   rx   ry   rU   r   r   r   r   r	   r   r   r   r   r   r   )r}   r~   r   r   r   s        r   stage_updater    s     ]](+Ff-D~~ ?==?IIKWa(8&9:<vtnH    ''03XX  '9FD>JJr   c                 x   t         j                  j                  |      }| j                  dk(  r	 t	        j
                  | j                  j                  dd            }t        |      D ];  \  }}|j                  j                  |      }|dz   |_	        |j                          = t        j                  | d       t        ddi      S |j                  j#                  d      }t%        | d||d      S # t        $ r9}t        j                  | d	       t        d
t!        |      dd      cY d}~S d}~ww xY w)zL
    This method is used to update the stage sequence of the onboarding
    rn   r   r(  z[]rj  zSequence Updated Successfullyr  r   zError Updating Sequence..r   )r  r+    r  Nr   zcbv/pipeline/stage_order.html)r   r   )r_   rx   ry   r   rI  rJ  r   r.  rt   r   r   r	   r   r   r   r   r   r   r   )	r}   r  r   r(  r3  r~   r   er   s	            r   update_stage_orderr    s%    %%))R)0K~~
	TJJw||//>?E#,U#3 x#--11X1>!&

 W&EF9 566
 ""++J7F'&	
   	TNN7$?@7s1v FsSS	Ts   BC7 7	D9 .D4.D94D9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
    r~   r   zCandidate Addedr\  z!pipeline/form/candidate_form.htmlr   )rG   r   ry   r   r  r   r   r	   r   r   r   r}   r   s     r   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
    rn   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>)rg   rx   ry   r   r   r   r   r   )r}   r~   r   r+  s       r   stage_title_updater  8  s\     !!X!.Ill7+IONN?@G
efmennz{ r   z"onboarding.add_onboardingcandidate)permsc                    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   r  softwarer   r|   r/  
onboardingrE  /onboarding/candidates-viewjob_position_idzCandidate added.zJob position field is required$candidate/candidate_create_form.html)r   open_recruitment)rH   r_   rx   r   r   r   r  r   r   rq  sourcer~   rg   r|   r-  r   ry   r)  r   r	   r   r   r   r   r   )r}   r   r  pathrr  s        r   r5  r5  H  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
    rn   rI  r   )r_   rx   ry   rt   rw   r   	serializer   )r   rq   r   
all_stagesall_stage_jsons        r   recruitment_stage_getr  t  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   ry   r   rZ   rx   r   r_   r   r  r
   r@   ru   r   r*   ro   r  r   rl   r   rA   fields)r}   r  r  r  r   mailsexisting_emailsr   r   r  r5  s              r   candidate_viewr    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.
    "recruitment.view_interviewschedule-interview_dateemployee_idr+   r   r   zcandidate/interview_list.html)r   r   r   r  )r   r   rr   r  r]   rx   rw   r   r   rs   ro   ry   r+   rB   r   rl   r   r*   r   r  r   )r}   r  
interviews
dis_filterr  r  r  r  s           r   interview_filter_viewr    s    KK))+M||AB&..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   rr   r  r]   rx   rw   r   r   rs   ro   rB   ry   rl   r   r   r  r   )r}   r  r  r   r  r  r   r  s           r   interview_viewr    s    
 KK))+M||AB&..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        d      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
    rn   z Interviewer removed succesfully.z,<script> $('#applyFilter').click();</script>)
r]   rx   r   r-  r  remover	   r   r   r   )r}   interview_idr  	interviews       r   interview_employee_remover    sa     "))00L0AGGII  -W@ANNFGGr   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r2  Candidate_export)r}   modelfilter_class
form_class	file_name)rW  ry   rM   r@   r   r(   rZ   )r}   r  r  r   s       r   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   rZ   rx   rw   ry   r   r@   r   r   rl   r}   r  r  s      r   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      r   candidate_view_cardr  1  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        | dd|i      S )z(
    method for rendering about tab
    Candidate not foundrT  rU  z%cbv/candidates/profile_about_tab.htmlr5  )	rZ   r   r	   r   r   r   rW  ry   r   r}   r  kwargsrr  s       r   candidate_about_tabr
  G  sb     NN2&Mw"7 89#GLL$4$4^S$IJJ/	
 r   c                 J    t        j                  |      }t        | dd|i      S )z)
    method for rendering resume tab
    z&cbv/candidates/profile_resume_tab.htmlr5  rZ   r   r   r  s       r   candidate_resume_tabr  [  /     NN2&M0	
 r   c                 J    t        j                  |      }t        | dd|i      S ))
    method for rendering survey tab
    z&cbv/candidates/profile_survey_tab.htmlr5  r  r  s       r   candidate_survey_tabr  l  r  r   c                     t        j                  |      }|j                  j                         }t	        | d||d      S )r  zcandidate/document.html)r5  	documents)rZ   r   candidatedocument_setrw   r   )r}   r  r	  rr  r  s        r   candidate_document_request_tabr  }  sD     NN2&M33779I!&"	
 r   c                 J    t        j                  |      }t        | dd|i      S )z*
    method for rendering history tab
    zcandidate/history.htmlr5  r  r  s       r   candidate_history_tabr    s/     NN2&M 	
 r   c                 J    t        j                  |      }t        | dd|i      S )z-
    method for rendering onboarding tab
    z*cbv/candidates/profile_onboarding_tab.htmlr5  r  r  s       r   candidate_onboarding_tabr    s/     NN2&M4	
 r   c                 J    t        j                  |      }t        | dd|i      S )z)
    method for rendering rating tab
    zcandidate/rating_tab.htmlr5  r  r  s       r   candidate_rating_tabr    s/     NN2&M#	
 r   c                 J    t        j                  |      }t        | dd|i      S ),
    method for rendering interview tab
    z)cbv/candidates/profile_interview_tab.htmlr5  r  r  s       r   candidate_interview_tabr    s/     NN2&M3	
 r   c                     t         j                  j                  |      }t        j                  j	                  |      j                  d      }t        | d||d      S )r  rn   r  r  tabs/scheduled_interview.html)r  r   )r0   rx   ry   r]   r   r   r   )r}   r  r	  r   r  s        r   scheduled_interview_tabr!    sa     ##r#*H"**11h1GPPJ '!x8 r   c                     t        | d      S )z;
    This method is used to view profile of candidate.
    zcandidate/individual.htmlr   )r}   r4  r	  s      r   candidate_view_individualr$    s    j # r   z%onboarding.change_onboardingcandidatec                    	 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
    rn   r   r  r   r   r  )r/  r  rE  Tr  zCandidate Updated Successfully.r  r   zCandidate Does not exists..rT  rU  )rZ   rx   ry   rH   r   r   r  r   r   r~   rg   r   r|   r-  rt   r   r)  r	   r   r   r   r   rK  rV  r   r   rW  )r}   r4  r	  rr  r   r  s         r   candidate_updater&  9  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                  |      }|s;t        j                  | d       t	        | j
                  j                  dd            S |j                  r;t        j                  | d       t	        | j
                  j                  dd            S t        j                  j                  |j                        j                         }t        j                  j                  |j                        j                         }|rt        j                  | d       nw|s^	 t        |j                  |j                  |j                   |j"                  d	      }|j%                          |j&                  }|j(                  |_        |j(                  j*                  |_        |j,                  j.                  |_        |j%                          t0        j                  j3                  |j4                  j7                         D cg c]:  }t1        |j8                  ||j:                  |j<                  |j>                  
      < c}       ||_        |j%                          t        j@                  | tC        d             nt        j                  | d       d| j
                  v rtI        dddi      S t	        | j
                  j                  dd            S c c}w # tD        $ r t        jF                  | d       Y hw xY w)Nr  rT  rU  z3This candidate is already converted to an employee.)username)employee_user_id__usernamez+User instance with this mail already existsT)employee_first_namer  phonegenderis_directly_converted)titler  documentr  reject_reasonz;Candidate has been successfully converted into an employee.z/An error occurred while creating employee data.z*An employee with this email already existsr     z
HX-Refreshr   )r  headers)%rZ   r   r	   r   r   rW  ry   converted_employee_idinfor
   rx   r   r  ru   r0   namemobiler,  r   employee_work_infor  department_idr|   
company_idr9   bulk_creater  rw   r.  r/  r  r0  r   r   r   warningr   )	r}   r4  r	  rr  user_existsemployee_existsnew_employee	work_infodocs	            r   candidate_conversionrA  h  sv    NN7+Mw!68#GLL$4$4^S$IJJ**gTU#GLL$4$4^S$IJJ,,%%}/B/B%CJJLK&&--#0#6#6 . fh  w!NP$	Y#$1$6$6#))#**$++&*L $77I(5(E(EI%&3&C&C&Q&QI##0#?#?#J#JI NN((  -BBFFH	  !ii$0!$"zz&)&7&7	 3?M/ OP 	gKLGLL(3v0FGG 0 0 EFF7	$  	YW&WX	Ys%   (C K" ?K=K" K" "LL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
    rn   NzProfile image removed.zrec-candidate-updater  )rZ   rx   ry   profiler  osjoinr   
MEDIA_ROOTr  r   r	   r   r   r   r   )r}   obj_idrr  	file_pathabsolute_pathr  s         r   delete_profile_imagerJ    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
    rn   z candidate/candidate_history.htmlhistory)rZ   rx   ry   rL  rw   r   )r}   r4  rr  candidate_history_querysets       r   candidate_historyrN    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
    Nr~   rn   )stage_id__idz+pipeline/pipeline_components/send_mail.html)ry  	templatesr  r~   searchWords)r   ry   r'   rZ   rx   rw   
isinstanceintr   r-   r   r&   get_template_language)r}   r4  rr  r~   r  rQ  s         r   form_send_mailrV    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
    rn   z4pipeline/pipeline_components/schedule_interview.htmlrH  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.r\  r   r4  )rZ   rx   ry   r   rQ   r  r   r   r   r   r   r   r   r:   r   rr   rs   r5  r   r	   r   r   r   )r}   r4  r5  r  r   r   emp_idsrY  rZ  r   r   s              r   interview_schedulerp    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                 F   t         j                  j                         }d}t               }||j                  d   _        | j                  dk(  r@t        | 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|i      S c c}w )rX  candidate/interview_form.htmlrH  r   r  rY  rZ  r[  r\  r]  r^  r_  r`  ra  rb  rc  rd  re  rf  rg  rh  ri  rj  rk  r   rl  r   rm  r   )rZ   rx   rw   rQ   r  r   r   r   r   r   r   r   r:   r   rr   rs   r5  r   r	   r   r   )
r}   r  r   r   ro  r4  rY  rZ  r   r   s
             r   create_interview_schedulers    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'8fd^44 Hs   Fz$recruitment.delete_interviewschedulec                 N   | j                   j                  dd      }	 t        j                  j                  |      j	                          t        j                  | t        d             t        |dk(  rd      S d      S #  t        j                  | t        d             Y 9xY w)	zf
    Deletes an interview schedule.
    Args:
        interview_id: InterviewSchedule instance ID
    r  r   rn   zInterview deleted successfully.zScheduled Interview not foundr   z.<script>$('.filterButton')[0].click()</script>r\  )
r   ry   r]   rx   r  r	   r   r   r   r   )r}   r  r  s      r   interview_deleteru  C  s     ;;??67+DD!!%%%6==?!$E"FG 6> 	9  9 Dw"A BCs   AB !B$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
    rn   r  r   r   z;pipeline/pipeline_components/schedule_interview_update.htmlr   rH  r   r  rY  rZ  r[  r\  r]  r^  r_  r`  ra  rb  rc  rd  re  rf  rg  rh  ri  rj  rk  r   rl  r   zInterview updated successfully.r\  )r   r  r  )r]   rx   ry   r   rZ   rw   r   rH  ro   rQ   r  r   r   r   r   r   r   r   r:   r   rr   rs   r5  r   r	   r   r   r   )r}   r  r  r  r  r   r   ro  r4  rY  rZ  r   r   s                r   interview_editrw  [  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               }t        j                  j                  |      }|j
                  j                  j                         }||j                  d   _	        | j                   j                  d      }|rLt        j                  j                  |      }|j                  j                         |j                  d   _        t        | d|dd      S )NrH  rn   r  r  rr  T)r   CBV)r   ry   rQ   rZ   rx   r|   r   rw   r  r   r]   r  r   r   )r}   r4  r   rr  r   r  interviewers          r   get_interview_managersr{    s    kkoon-G "D%%))W)5M++@@DDFH*2DKK'		B	'//33r3:-8-D-D-H-H-JM"*'d# r   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 )Nr4  rn   rk  	employees)r   ry   rZ   rx   rg   r   r|   ro   r   r   rw   rz   r   r   get_full_namer   )	r}   r4  rr  r   r   all_managersunique_managersr   employees_dicts	            r   get_managersr    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      }|r!t        j                  j                  |      }nt        j                  j                         }||z  j                         }| j                   j                  d      }|D ]  }	|D 
cg c])  }
|
j                  |
j                         |
j                  f+ }}
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        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
    ro   subjectbodyr  r   other_attachmentsrn   template_attachmentsTr  )r   selfr9   F)r  r.  zapplication/pdf)r  r  tohtmlzMail sent to candidatezSomething went wrongNr\  )$r   ry   r   rZ   rx   r   r  noner   r5  readcontent_typer   r-   r  r   TemplateContextrr   rs   r   r   r)   r   r  r   content_subtypeattachmentsr   r	   r   r   r5   	exceptionr   r   )r}   rH  r  bdycandidate_idsr  r  rr  template_attachment_idsr5  r  r  bodysr  template_bdyr2  
render_bdyr  r  r  s                       r   send_acknowledgementr    s    <<##D)Llly)G
,,

6
"CLL((6M"")))?J--.AB!))00L0A!))..0},668J%ll223IJ +<	DU
<@TYY		T%6%67
 
 ''... / k&tk,

  	D#,,T2L&&&0I0IJG &,,W5J Re:NVV%	  ((-"""GLL,E,EF
 "((1
__t

 !''	<JJLW&>?Q+<X CDDW
P  	<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
    sequenceDatarn   zSequence updatedr4  )r+  ri  )
rI  rJ  r   r   rZ   rx   ry   r   r   r   )r}   sequence_datar4  seqry  s        r   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   rn   r   zStage sequence updatedrh  )
rI  rJ  r   r   rg   rx   ry   r   r   r   )r}   r  r~   r  r   s        r   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   rw   Tr   employee_idstotal_countFsafe)
r   ry   rZ   rx   r   rw   r   ro   r  r   )r}   r  r}  empr  r  r2  s          r   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   rw   r   r  N)r   ry   rI  rJ  r@   rZ   rx   rw   r   r   ro   r  r   )
r}   r  filteredfiltersr
  r  r  r  r  r2  s
             r   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
    rn   rating)rH  r  r  )
rZ   rx   ry   rr   rs   r   r\   r  r   r  )r}   r4  r5  r  r  s        r   create_candidate_ratingr  D	  ss     G!!%%%1I,,++K\\h'F""v; #  ())r   zrecruitment.view_skillzonec                 L   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	}|	|
t               t               || j                  j                  d      d
}t!        | ||      S )z5
    This method is used to show Skill zone view
    Tr   skill_zone_idr   r   rO  r   r   dynamic_namezskill_zone/skill_zone_view.htmlz skill_zone/empty_skill_zone.html)r   r   r  r   skill_zonesr   r  )rD   r   r   r   r8   ry   r   rE   r   r   r   rl   r   r   r*   re   r   )r}   r  skill_groups	all_zoneszoneskill_zone_filteredall_zone_objectsunused_skill_zonesunused_zonesr  r  r   r2  s                r   skill_zone_viewr  Z	  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                         r9|j	                          t        j                  | t        d             t               }t        | dd|i      S )z3
    This method is used to create Skill zone.
    r   z Skill Zone created successfully.skill_zone/skill_zone_form.htmlr   )	rT   r   r   r   r   r	   r   r   r   r  s     r   skill_zone_creater  	  sp      D~~"7<<0==?IIKWa(J&KL&(D)	 r   zrecruitment.change_skillzonec                 D   t         j                  j                  |      }t        |      }| j                  dk(  rVt        | j
                  |      }|j                         r/|j                          t        j                  | t        d             t        | d||d      S )z3
    This method is used to update Skill zone.
    rn   r   r   z Skill Zone updated successfully.r  r   sz_id)re   rx   ry   rT   r   r   r   r   r	   r   r   r   )r}   r  
skill_zoner   s       r   skill_zone_updater  	  s     ""&&%&0J
3D~~"7<<*E==?IIKWa(J&KL)& r   zrecruitment.delete_skillzonec                 V   	 t        j                  |      }|r0|j                          t        j                  | t        d             nt        j                  | t        d             t        d      S # t        $ r, t        j                  | t        d             Y t        d      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 existsz?<script>$('.filterButton')[0].click();reloadMessage();</script>)	re   r   r  r	   r   r   r   r   r   )r}   r  r  s      r   skill_zone_deleter  	  s    =^^E*
Wa(K&LMNN7A&=$>? I   =w": ;<I =s   A&A3 3(B('B(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  )re   r   r   rf   rx   r   r   r	   r   r   r   r   r  )r}   r  r  r   skill_zone_candidatesis         r   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   rO  r  )r  r   r   )r   ry   rD   r   rE   r   r8   r   r   r   r   rl   r   r   r*   re   r   )r}   r   r  r  r  r  r  r  r  r  r  r  r2  s                r   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
    rn   z)skill_zone_cand/skill_zone_cand_view.htmlT)r  r   r   )sz_candidatesr   r  )	re   rx   ry   rf   r   rl   r   r   r   )r}   r  r  r   r  r2  s         r   skill_zone_cand_card_viewr  7
  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
    rn   )skill_zone_cand/skill_zone_cand_form.htmlr  r   r   zCandidate added successfully.r\  r  )re   rx   ry   rS   r   r   r   r   r	   r   r   r   r   )r}   r  r  r   r   s        r   skill_zone_candidate_creater  Q
  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
    rn   r  r   r   zCandidate edited successfully.r\  )r   
sz_cand_id)rf   rx   r   r-  rS   r   r   r   r   r	   r   r   r   r   )r}   r  skill_zone_candr   r   s        r   skill_zone_cand_editr  l
  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
    rn   r  r  r  rf   rx   ry   r  r	   r   r   rK  r   r   r   r  r}   r  s     r   skill_zone_cand_deleter  
  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   ry   rf   rx   rw   rD   r   r   r   r*   rl   r   )r}   r   r  candidates_filterr  r  r2  s          r   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
    rn   TFz!Candidate archived successfully..z#Candidate unarchived successfully..rG  )rf   rx   ry   r   r	   r   r   r   re   rK  r   r   r  )r}   r  r  r   s       r   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  rn   z Candidate deleted successfully..rG  r  r  r  s     r   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.r\  rn   z'skill_zone_cand/to_skill_zone_form.html)rH  r  Tr  )rH  skill_zone_idsr   r   r  )rH  r  reasonz*Candidate Added to skill zone successfullyrn  )rr   r  r	   r4  r   rZ   rx   ry   rX   rf   r   r  r   r   r   r   ru   rH  r  r  r   r   r   )r}   r4  r5  r   r   r  r  zone_candidates           r   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
    rn   r  )rH  r  )rZ   rx   ry   rr   rs   r   r\   rT  r  r   r   r  )r}   r4  r5  r  r  rates         r   update_candidate_ratingr    s     G!!%%%1I,,++K\\h'F""&&I;&WDf+DKIIK())r   c                 v    t         j                  j                  ddd      }d|i}t        | d|      }d|d<   |S )zA
    This method is used to render the open recruitment page
    FT)r   is_publishedr   r   z"recruitment/open_recruitments.htmlzALLOW-FROM *zX-Frame-Options)r_   defaultr   r   )r}   r   r2  r   s       r   open_recruitmentsr  +  sU     &&--44 . L 	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
    rn   r   z$recruitment/recruitment_details.html)r_   r  ry   r   )r}   ro   r   r2  s       r   recruitment_detailsr  ;  s;     %%))R)0K{G 'A7KKr   c                     t        j                  |      }t        j                  j	                  |j
                        j                  d      }t        | d||d      S )zG
    This method is used to track mails sent along with the status
    )to__icontainsz-created_atzcandidate/mail_log.html)r5  tracked_mails)rZ   r   r,   rx   r   r  r   r   )r}   r  rr  r  s       r   get_mail_logr  F  s_     NN2&M$$++-:M:M+NWWM !&*	
 r   z)recruitment.add_recruitmentgeneralsettingc                 D   t         j                  j                         }|r|n	t               }| j                  j	                  d      dk(  rd|_        t        d      }nd|_        t        d      } |j                          t        j                  | |       t        d      S )zG
    This method is used to update the recruitment general setting
    candidate_self_trackingr   Tz Application Tracking is enabled Fz!Application Tracking is disabled 3<script>$('#reloadMessagesButton').click()</script>)r`   rx   r-  r   ry   r  r   r   r	   r   r   r}   r   r+  s      r   r  r  [  s     )00668H#x)B)DH{{01V;+/(67+0(78HMMOWg&MNNr   c                 f   t         j                  j                         }|r|n	t               }| j                  j	                  d      dk(  rd|_        t        d      }nd|_        t        d      } |j                          t        j                  | |        |j                          t        d      S )zN
    This method is used to enable/disable the selt tracking rating field
    r  r   TzRating visibility is enabled FzRating visibility is disabled r  )r`   rx   r-  r   ry   show_overall_ratingr   r   r	   r   r   r  s      r   %candidate_self_tracking_rating_optionr  o  s     )00668H#x)B)DH{{01V;'+$34',$45HMMOWg&HMMOMNNr   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(  passwordrH  candidate_emailzcandidate-self-status-trackingzcandidate/self_login.htmlr   zInvalid credentials)	r   r   r;   authenticatero   r  r  r   r   )r}   r  r6  backendr5  s        r   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.rH  Nr  zYou have been logged out.r  )r  popr	   r   r   r}   s    r   candidate_logoutr	    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"   rH  candidate-loginr  r   rY  thenrj  r  output_fieldis_todayr  r  rZ  &candidate/candidate_self_tracking.htmlr5  r  404.html)r"   r  ry   r   rZ   rx   candidate_interviewannotater   r   r   todayr   r   r   )r}   self_tracking_featurerH  r5  r  s        r   candidate_self_status_trackingr    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"   rH  r  )candidate__id)r5  r  r  r   r  rj  r  r  r  r  rZ  r  r  r  )r"   r  ry   rr   r  rs   r   r   ru   rt   r   rZ   rx   r  r  r   r   r   r  r   r   r   )r}   r4  r  rH  r5  r  s         r   ,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_idNrn   r   r   zReject reason savedr\  z settings/reject_reason_form.htmlr   )r'   r   r   ry   rb   rx   rO   r   r   r   r   r	   r   r   r   )r}   r   r   r   s       r   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.htmlr#  r  s    r   r  r    s     '?@@r   zrecruitment.delete_rejectreasonc                 P   | j                   j                  d      }t        j                  j                  |      }t        j                  j	                         }|j                          t        j                  | |j                   d       |dk(  rt        d      S t        d      S )z:
    This method is used to delete the reject reasons
    ro   rn    is deleted.rj  z-<script>$('.reload-record').click();</script>z4<script>$('#reloadMessagesButton').click();</script>)
r   ry   rb   rx   r  r  r	   r   r.  r   )r}   ro   r  r  s       r   delete_reject_reasonr%    s     
	B!!%%%,F  &&(E
MMOWl;<zKLLNOOr   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)rj  N)isupper).0cs     r   	<genexpr>z.extract_text_with_font_info.<locals>.<genexpr>,  s      6"*+qyy{A6"s   )r+  	font_sizecapitalization)
r  ioBytesIOfitzopenranger   get_textr   sum)r'  	pdf_bytespdf_docr@  	text_infopage_numr   r(  blocklinespans              r   extract_text_with_font_inforB    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 )Nr2  r3   xs    r   <lambda>zrank_text.<locals>.<lambda>C  s    !K.!4D2E!F r   Tr   r   )sorted)r=  ranked_texts     r   	rank_textrL  8  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.%YrN  )r   strptimestrftime
ValueError)dobdate_formatsfmtparsed_dates       r   dob_matchingrV  H  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})?\brO  )	full_nameaddresscountrystatephone_numberrR  email_idzipr2  c              3   &   K   | ]	  }|d      yw)r2  NrE  )r/  items     r   r1  zextract_info.<locals>.<genexpr>  s     #N$D$5#Ns   r+   rX  r\  rR  r^  r]  rY  zAddress:rZ  r[  )rB  rL  recompilemaxrE  rN  grouprV  lowerreplacestripsplit
capitalizer#   r%   )r'  r=  rK  phone_patterndob_patternemail_patternzip_code_patternextracted_infor`  name_candidatesr+  phone_match	dob_match	zip_matchemail_matchs                  r   extract_inforu  e  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)r  ru  r   )r}   resume_filecontact_infos      r   resume_completionr{    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
    rC  rn   z
No messager*  r+  )r   ry   rg   rx   r|   r0  r   r   )r}   r~   r   r+  s       r   check_vaccancyr}    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)rd   rx   rw   r   )r}   r  s     r   skills_viewr    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   Nrn   r   r   zSkill created successfullyrE  r   r   zrecruitment-creater  r  z&skills=?r\  )r   r   hx_valsz settings/skills/skills_form.htmlr  )r'   r   r   ry   rd   rx   rR   r   r   r   r   r	   r   django.urlsr   rw   r  r   r   r  r   ro   r  r   r   r   r   )r}   r   r   r  r   r   r   urlmutable_getr  r   r`  r2  s                r   create_skillsr    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                 ^   | j                   j                  d      }t        j                  j	                  |      }|D ]m  }t        j                  j
                  }|j                          t        j                  | |j                   d       |dk(  rt        d      c S t        d      c S  y)z2
    This method is used to delete the skills
    idsr   r$  r   r  z,<script>$('.reload-record').click()</script>N)r   r   rd   rx   r   r  r  r	   r   r.  r   )r}   ro   r  r  skillr  s         r   delete_skillsr    s     ++

e
$C]]!!!-F P##U[[M">?A: UVV NOOPr   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
    rq   rk  zpipeline/bulk_resume.html)resumesrq   )r'   r   r   ry   rc   rx   r   r   )r}   rq   r  s      r   view_bulk_resumesr    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
    rq   rn   r   r  )r  r|   view-bulk-resume?rec_id=N)r'   r   r   ry   r_   rx   r   r  r   rc   r  r   r   )r}   rq   r   r  r  r  query_paramss          r   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  rq   r   r  r  )	r   r   ry   rc   rx   r   r  r   r   )r}   r  rq   r  r  s        r   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)r6  r7  r  r8  r   	load_pager9  rb  findallrf  extendclose)pdf_filepdf_documentwordsr>  r   	page_text
page_wordss          r   extract_words_from_pdfr  K  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

    rn   r.  Tr  )is_candidatero   c              3   B   K   | ]  }|j                         v   y wN)rf  )r/  r  r  s     r   r1  z#matching_resumes.<locals>.<genexpr>w  s     #OuEKKMU$:#Os   )rx  matching_skills_count	image_pdfrx  c                     | d   S Nr  rE  rF  s    r   rH  z"matching_resumes.<locals>.<lambda>  s    Q/F-G r   rI  c                     | d   S r  rE  rF  s    r   rH  z"matching_resumes.<locals>.<lambda>  s    +B)C r   zpipeline/matching_resumes.html)matched_resumesrq   )r_   rx   r   r-  r  r  rx  rw   r   r  r  r:  r   r   ro   rJ  r   )r}   rq   r   r  r  r  is_candidate_idsresume_ranksrx  r  r`  rankcandidate_resumesnon_candidate_resumesranked_resumesr  s                  @r   matching_resumesr  c  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 )rw  	resume_idrn   )r   ry   r   rc   r  ru  r   )r}   r  
resume_objry  rz  s        r   matching_resume_completionr    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)rb   rx   rw   r   )r}   r  s     r   candidate_reject_reasonsr    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  )
r_   rx   r   randomrandintr   r5  r  r   r   )
r}   r  r   r  r  r   r   redgreenblues
             r   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
    rH  Nr   r   z%Document request created successfullyr   r   z+documents/document_request_create_form.htmlr  )r   ry   rK   r   r   r   r   r	   r   r   r   r   )r}   rH  r   r2  s       r   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
    rn   rH  r   r   zDocument created successfully.r   )r   rH  z#candidate/document_create_form.htmlr  )rZ   rx   ry   rI   r   r  r   r   r   r  r   r   r	   r   r   r   r   )r}   ro   rH  r   r2  s        r   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
    rn   r.  r   Tz#Document title updated successfully)r   r+  FzInvalid requestr  r  )r   r[   r   ry   r   r.  r   r   )r}   ro   r/  r5  s       r   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.
    rn   zDocument request z for z deleted successfullyzDocument not foundz You cannot delete this document.r  r/  r   )r[   rx   r   r  r	   r   r   r-  r  r   r   rW  ry   
startswithr/   r   )r}   ro   r/  s      r   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
    rn   r   r   zDocument uploaded successfullyr   )r   r/  zcandidate/document_form.htmlr  )r[   rx   ry   rL   r   r   r  r   r   r	   r   r   r   r   )r}   ro   document_itemr   r2  s        r   file_uploadr  P  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
    rn   r/  rj  Nrbfile_contentfile_extensionr  zcandidate/view_file.html)r[   rx   r   r-  r/  r  rD  splitextrf  r2   r7  r  r   )	r}   ro   document_objr2  rH  r  r  r  r  s	            r   	view_filer  n  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:
    rn   approvedzDocument request approvedNo document uploadedr   )
r   r[   r/  r  r   r	   r   r   r   r   )r}   ro   r  s      r   document_approver    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:
    rn   r   r   Fr  rejectedzDocument request rejectedr   r  zcandidate/reject_form.html)r   r  )r   r[   rJ   r/  r   r   r   r   r0  r  r	   r   r   r   r   )r}   ro   r  r   r   s        r   document_rejectr    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)r~  rn   NrH  r   r   Fr  Tr  z# has added a note on the candidate u	   أضاف u"    ملاحظة حول المرشح z	 hat dem u    eine Notiz hinzugefügt.u    agregó una nota al r^  u    a ajouté une note à r   zcandidate-view-individualr4  )r	  )	labelr   r   r   r   r   r   r   r   r  r  )$rZ   rx   ry   rr   is_authenticatedrs   r~  r5  rV   r   r   r  r   r   rH  r~   r  r  r  r   r	   r   r   r   r   r   r|   r   rw   rz   r   r   r:   r   r   r   )r}   r4  r5  r  r  r   r  r  r   rz   r  r   r   s                r   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  rj  r  r  r  r  rZ  r   r  )rr   rs   interviewschedule_setr  r   r   r   r  r   r   r   )r}   r   r  s      r   employee_profile_interview_tabr    sz     ||((H//88

15%
 9  hz,.>?  ':\:<VWWr   )F)r   r  (   __doc__astr   r4  rI  rD  r  rb  r   r   	itertoolsr   urllib.parser   r6  djangor   django.confr   django.contribr	   django.contrib.auth.modelsr
   django.corer   django.core.cacher   r  django.core.mailr   django.core.paginatorr   	django.dbr   r   django.db.modelsr   r   r   r   r   django.httpr   r   r   django.shortcutsr   r   r   r  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.modelsr0   r1   employee.viewsr2   horillahorilla.decoratorsr3   r4   r5   r6   r7   horilla.group_byr8   horilla_documents.modelsr9   notifications.signalsr:   recruitment.authr;   recruitment.decoratorsr<   r=   r>   r?   recruitment.filtersr@   rA   rB   rC   rD   rE   rF   recruitment.formsrG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   recruitment.methodsrY   recruitment.modelsrZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   recruitment.views.linkedinrj   rk   recruitment.views.paginator_qryrl   r   r{   r   r   r   r   r  user_recruitmentsr  r  r  r   r$  r6  r8  r;  r@  rL  rQ  rX  r]  r`  rc  re  ru  r|  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r5  r  r  r  r  r  r  r  r  r
  r  r  r  r  r  r  r  r!  r$  r&  atomicrA  rJ  rN  rV  rp  rs  ru  rw  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  r%  rB  rL  rV  ru  r{  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rE  r   r   <module>r     s     	  	  	 #  !     # + # , ) + 1 H H H H @ @  ! 6 = 0 A 3 3 '  S R = +   / - ( ;       ( 4    $ Q 984,^ 787 9  7t 89! : !H :;I  < IX   67 8 @ 67: 8  :z 12 3  673  8 2 67! 8 !0 67 8 0 67 8  B 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 89 :   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 9: ; > ./P 0  P$ vh
    
 &(L
M% %P 56	4 7 	4 67' 8 'T !  !H  @ >?H @ H  * 67 8 & 67 8  & 45 6 $ 45 6  45 6  45 6 D 45 6  89 :  89 :  45 6  89@ : @F )+R
S(G (GV 67?G 8  ?GD 67< 8 <( 45 6  67 8  < ;<"I =  "IJ ;< 5 =   5F >? @  * >?/ @  /d&7* 67?E 8 ?ED 67
I 8 
I $>?	R @ 	R - -& % %, * ** 45/6 6 /6d 34 5  & 67 8  $ 67 8 2 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 1 & @AO B  O" @AO B  O$8(' ' ': ./$' 0 $'N 34O 5  O$ 34A 5 A 67P 8 PD :JZ&	. S S ,P ,P^ 67P 8 P" ./	 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   