o
    ނi~                    @   sJ  d dl Z d dlZd dlm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
 d dlZd dlmZmZ d dlmZmZ d dlmZ d dlmZmZ d dlmZmZmZ d d	lmZmZmZ d d
lmZ d dlm Z  d dl!m"Z# d dl$m%Z%m&Z&m'Z' d dl(m)Z) d dl*m+Z+m,Z, ddl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEm@Z@mFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZX ddlYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZq ddlrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZmZ d dlmZ d dlmZ ddlmZ eedgeg eg dd Zeedgeg eg dd Zeedgeg eg dd Zeedgeg eg dd  Zedgd!d Zedgd"d# Zedgd$d% Zedgd&d' Zedgd(d) Zed*gd+d, Zed*dgd-d. Zedgd/d0 Zedgd1d2 Zed*gd3d4 Zedgd5d6 Zd7d8 Zedgd9d: Zedgd;d< Zeedgeg eg d=d> Zed*dgd?d@ Zedgeg eg dAdB Zed*dgeg eg dCdD ZedgdEdF ZedgdGdH ZedgdIdJ ZedgdKdL ZedgdMdN ZedgdOdP Zed*geg eg dQdR ZedgdSdT ZedgdUdV Zedgeg eg dWdX Zed*gdYdZ Zed*dgd[d\ Zd]d^ Zedgd_d` Zedgdadb Zedgeg eg dcdd Zedgdedf Zedgeg eg dgdh Zedgdidj Zedgdkdl Zedgdmdn Zeedgeg eg dodp Zeedgeg eg dqdr Zedgdsdt Zedgdudv Zed*gdwdx Zedgdydz Zedgd{d| Zedgd}d~ Zedgdd Zedgdd Zedgdd Zedgdd Zed*geg eg dd Zdd Zed*gdd Zedgdd Zedgdd Zedgdd Zedgdd Zedgdd Zedgdd Zedgdd Zedgdd Zedgdd Zedgdd Zedgdd Zedgdd Zeedgeg eg dd Zed*gdd Zedgdd Zedgdd Zedgdd Zedgdd Zedgdd Zedgdd Zedgdd Zedgeg eg dd Zedgdd Zedgdd Zedgdd Zed*gdd Zedgdd ZedgddĄ ZedgddƄ Zed*gddȄ Zed*gddʄ Zedgdd̄ Zedgdd΄ ZedgddЄ Zedgdd҄ Zed*gddԄ Zed*gddք Zed*gdd؄ Zedgddڄ Zedgdd܄ Zedgddބ Zedgdd Zd dl Z edgdd Zedgdd ZdS )    N)datetime)urljoin)JsonResponseFileResponse)decrypt_codeencrypt_code)compareVoices)BASE_DIR
MEDIA_ROOT)api_viewauthentication_classespermission_classes)HttpResponser   HttpResponseForbidden)csrf_exempt)perform_login)app_settings)	auth_usergetCompanyIdgetUserCompany)Q)	getConfigcheck_referrer   ),addCompanyDataServicecandidateRegistrationServicedeductCreditsServiceregisterUserServiceauthentication_servicegetJdWorkflowServiceinterviewSchedulingServicejdPublishServicechangeUserstatusServiceupdateJdDataService1skillsWithTopicsWithSubtopicsWithQuestionsService	jdTestAddaddJdServicesupdateJdServicesworkFlowDataServiceinterviewCompletionServicequestionsResponseServicegetInterviewStatusServicegenerateCandidateReportaddNewUserServicenotifyCandidateServicecheckTestHasPaperServicedeleteTestInJdServicesaveInterviewersServicer,   demoUserServiceupdateCandidateWorkflowServicedashBoardGraphDataServicemapUploadedCandidateFieldsprocessAddCandidateService#checkJdCandidateRegistrationServicedownloadUploadReportServicegetResumeDatasoftDeleteResumegenerateBrandedProfilegetRecritmentDashboardDatagetJdProfileDatashortlistProfileServicedashBoardDataServiceaddNewClientServicechangeClientstatusServiceRecruitersPerformanceServicejobBoardConfigServiceSourcePerformanceService)AccountBranding	CandidateCompanyCreditsJobDescLookupmasterRegistrationUser	User_dataWorkflowInterviewMediaCallScheduleBrulesProfileProfileExperienceSourceProfileSkillsEmail_templateCompany
ResumeFileResumeProfileActivityWorkCal	jdlibrary)#addCandidateDBscheduleInterviewDBinterviewResponseDBaddInterviewFeedbackDBupdateEmailtempDBinterviewRemarkSaveDBupdateCompanyDBsaveStarQuestiondemoRequestDBdeleteCandidateDBupdateSourcesDataDBupdateCandidateInfoDBupdateDashboardDisplayFlagDBaddProfileDBaddResumeProfileDBupdateProfileDetailsDBupdateProfileEducationDBupdateProfileExperienceDBupdateProfileProjectsDBupdateProfileAwardsDBupdateProfileCertificatesDBupdateProfileSkillsDBupdateProfileActivityDBsaveWorkCalDB scheduleCandidateInterviewLinkDBscheduleCandidateInterviewDBjdRecruiterAssignDBupdateFullProfileDBaddWorkspaceDBaddProfileActivityDBupdateWorkspaceDBupdateProfileCompletionsaveJobBoardConfigDBsaveJDJobBoardsDBaddResumeDB)hirelines_registration_scriptconst_profile_status)fetch_gmail_attachments)r   )convert_word_binary_to_pdfPOSTc              
   C   s   d d dd}z"| j dkr$t| jd}t|}t||d< W t	|S W t	|S  tyG } zd|d< t||d< W Y d }~t	|S d }~ww N   dataerror
statusCoder   r   r   zError in adding company datar   
methodjsonloadsr   getr   int	Exceptionstrr   requestresponsedataObjsdata_add_statuse r   &/home/acert/hirelines/app_api/views.pyaddCompanyData,   s$   
r   c              
   C   s~   d d dd}z!| j dkr#t| j}t| d|d< d|d< W t|S W t|S  ty> } zd|d< t||d	<  d }~ww )
Nr   r   r   zDetails Saved Sucessfullyr   r   r   zError in Registrationr   )r   r   r   bodyr   r   r   r   r   r   r   r   r   r   r   addJDCandidateA   s&   

	r   c              
   C      d d dd}z"| j dkr$t| jd}t|}t||d< W t	|S W t	|S  ty? } zd|d< t||d<  d }~ww r   )
r   r   r   r   r   r   r   r   r   r   r   r   r   r   registerUserX   s$   
r   c              
   C   s   d d dd}zY| j dkr[t| jd}t|}|d d krJtjj|d d	 }t
| j|tjdd d d	 t|}d
|d< |j|d< |d |d< nd|d< d|d< d|d< W t|S W t|S  tyv } zd|d< t||d<  d }~ww )Nr   r   r   r   r   email)	usr_emailF)signupredirect_urlsignal_kwargstoken_generatedtoken
login_typeAnonymousUserzlogin failedr   zError in Sign-inr   )r   r   r   r   r   r   rM   objectsfilterfirstr   _requestallauth_settingsEMAIL_VERIFICATIONr   roler   r   r   )r   r   r   
auth_tokenusruserr   r   r   r   	loginUsern   s:   


r   c              
   C   r   r   r   r   r   r   r   r      s$   
c              
   C      d d dd}z*| j dkr,t| jd}t| j}t||}||d< d|d< W t
|S W t
|S  tyG } zd|d< t	||d<  d }~ww )	Nr   r   r   r   r   r   z!Error in adding Test in Work flowr   )r   r   r   r   r   r   r   r%   r   r   r   )r   r   r   	companyIDtestDatar   r   r   r   	jdAddTest   s(   




r   c              
   C   s   d d dd}z,| j dkr.t| jd}t| j}t||| j}||d< d|d< W t
|S W t
|S  tyI } zd|d< t	||d<  d }~ww )	Nr   r   r   r   r   r   zError in Saving JD Datar   )r   r   r   r   r   r   r   r&   r   r   r   )r   r   r   r   jdDatar   r   r   r   addJD   s(   



r   c              
   C   s   d d dd}z)| j dkr+t| jd}t| j}t|}||d< d|d< W t
|S W t
|S  tyF } zd|d< t	||d<  d }~ww )	Nr   r   r   r   r   r   zError in getting JD datar   )r   r   r   r   r   r   r   r#   r   r   r   )r   r   r   r   
jdDataDictr   r   r   r   jdUpdateData   s(   



r   c              
   C   s   d d dd}z(| j dkr*t| jd}t| j}t||| j d|d< W t
|S W t
|S  tyE } zd|d< t	||d<  d }~ww )	Nr   r   r   r   r   r   zError in JD Updata datar   )r   r   r   r   r   r   r   r'   r   r   r   )r   r   r   r   r   r   r   r   updateJD   s&   


	r   GETc              
   C   s   d d dd}z'| j dkr)| jd}t| j}t||}||d< d|d< W t|S W t|S  tyD } zd|d< t||d	<  d }~ww )
Nr   r   r   jidr   r   r   zError in getting jd worflowr   )	r   r   r   r   r   r   r   r   r   )r   r   jobid
company_idworkflow_datar   r   r   r   getJdWorkflow   s(   



r   c              
   C   s  d d dd}z| j dkrt| j}|j}t d d }d}t||}t| j	d}t
jj|d |d	d
ddd }g }	t|d
 }
|
D ]}d| }|	| qH|	|d
< d}tjj|d d}|r|D ]}|r|j|d kr|jdkr|jr|j}qj|r||d< |d |d< ||d< td| tj||dd}|j}|rt|d}|d }|}|d dkr||d< d|d< W t|S W t|S W t|S W t|S  ty } zd|d< t||d< tt| W Y d }~t|S d }~ww )Nr   r   r   DOMAINacertz/api/jd-screening-questionsr   jd_id)id	companyidskillsetlocationexpminexpmaxz,  )r   test_idSscreeningPaperr   jd_dataFr   verifyutf-8r   r   zError in getJdQuestionsViewr   ) r   r   r   r   r   r   r   r   r   r   rI   r   r   valueslastastliteral_evaljoinkeysappendrN   r   	papertypepaperidprintrequestspostcontentdecoder   r   r   )r   r   r   user_companyacert_domainendpointurlr   r   skills_list	skill_setskillr   workFlowData	workFlow_get_evaluation_submissionsresponse_content	json_data
acert_datajd_questionsr   r   r   r   getJdQuestionsView  sp   


$

6
r   c              
   C   s   d d dd}z5| j dkr2t| jd}| j}t| j}t|}t||d |j	}||d< d|d< nt
dW S W t|S  tyR } zd|d< t||d	<  d }~ww 
Nr   r   r   r   r   r   Request BlockedError in saving Job Descriptionr   )r   r   r   r   r   r   r   r   r]   r   r   r   r   r   )r   r   r   
user_emailr   r   c_datar   r   r   r   addCandidateM  s,   



	r   c              
   C   s   d d dd}z-| j dkr*t| jd}| j}t|}t||}||d< d|d< ntdW S W t|S  t	yJ } zd|d< t
||d	<  d }~ww r   )r   r   r   r   r   r   r   r(   r   r   r   r   )r   r   r   r   r   workflowDatar   r   r   r   r     s*   



	r   c              
   C   s   d d dd}z't | j}| jdkr)| jd}t||}||d< d|d< W t|S W t|S  tyD } zd|d< t||d	<  d }~ww )
Nr   r   r   int_idr   r   r   zError in Call Scheduling viewr   )	r   r   r   r   r   r    r   r   r   )r   cidr   r   r   interview_schedule_datar   r   r   r   interviewScheduling  s(   




r   c              
   C   s   d d dd}z+| j dkr-t| j}t| jd}t|j|}||d< d|d< W t|S W t|S  t	yP } zd|d< t
||d< W Y d }~t|S d }~ww )	Nr   r   r   r   r   r   z"Error in Scheduling Interview viewr   )r   r   r   r   r   r   r   r^   r   r   r   r   )r   r   r   r   resr   r   r   r   scheduleInterviewView  s(   



r   c                 C   s&   zt tddW S    t ddd Y S )Nzapplication/javascriptcontent_typez"console.error("Script not found");)r   r   )r   enc_jdidr   r   r   candidateRegistrationCDNForm  s   r  c              
   C      d d dd}z$| j dkr&t| jd}t|}||d< d|d< W t|S W t|S  tyI } zd|d< t||d< W Y d }~t|S d }~ww )	Nr   r   r   r   r   r   zError in Meeting Response viewr   )	r   r   r   r   r   r_   r   r   r   r   r   r   r   r   r   r   r   interviewResponseView  s&   

r  c              
   C   r  )	Nr   r   r   r   r   r   zError in questios Response viewr   )	r   r   r   r   r   r*   r   r   r   r  r   r   r   questionsResponseView  s&   

r  c              
   C   sR  d d dd}z| j dkrt| j}t|d }tjj|d}t d }|d }|dkr/d}nt	jj
|j|j|d	 d
}|rB|dkr|jdkr{tjj
|dd }|rv|j}	||d< |j|d< |j}	t||	|}
|
dkrqd|d< nd|d< nd|d< n	d|d< nd|d< d|d< W t|S W t|S  ty } zd|d< t||d<  d }~ww )Nr   r   r   encjdidr   
APP_CONFIGregister_candidate_once_per_jdYr   )r   r   r   NA)r   orderjdz
begin-frominsufficient_creditszInsufficient Creditsr   z#Registration completed successfullyzWorkflow not definedzJD inactivezCandidate already registeredr   r   zError in registerCandidater   )r   r   r   r   r   rI   r   r   r   rG   r   r   r   statusrN   r   r   r]   r   r   r   )r   r   r   r   job_description
app_configr
  check_candidate_registeredr   r   add_resperrr   r   r   registerCandidate  sT   









)r  c              
   C   s$  d d dd}zd| j dkrbt| j}|j}t|}t d d }d}t||}ttj	j
|djdd	d
}d||d}	tj||	dd}
|
j}|rbt|d}|d }|d dkrb||d< d|d< | j dkr]t| j}|j}t|}t d d }d}t||}ttj	j
|djdd	d
}t| jd}|d dkr||d< ||d< tj||dd}|j}|rt|d}|d }|}|d dkr||d< d|d< |d dkr||d< ||d< tj||dd}|j}|rt|d}|d }|d }d|d< |d dkr||d< d|d< |d dkrb||d< ||d< |d |v rPtj||dd}|j}|rOt|d}|d }|d dkrO||d< d|d< nd|d< d|d< W t|S W t|S W t|S W t|S  ty } zd|d< t||d< tt| W Y d }~t|S d }~ww ) Nr   r   r   r   r   z/api/evaluate-papersr   r   Tflatget_evaluation_papers)request_forenc_company_idcompany_paper_idsFr   r   r   r   r   r   r  submissionsr  r  update_marksanswer_datazMarks Updated successfullysend_evaluation_resultpaper_idzQuery Not Foundz Error in evaluationquestionsViewr   )r   r   r   r   r   r   r   listrN   r   r   values_listr   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r  r   r   r   r  company_papersr  r   r   r   r   r   evaluationquestionsr   r!  respr   r   r   r   evaluationViewH  s   





	P r)  c              
   C   r  )	Nr   r   r   r   r   r   zError in getCallStatusr   )	r   r   r   r   r   r+   r   r   r   r  r   r   r   getInterviewStatusView  s&   

	r*  c           	      C   s   t | jd}t|d dd }t|d dd dd }tjj|d	 }t
|d	 |jd
  tjj|d	 }d|_|  tjtdd}tj|rxt|D ]}|| drwtj||}tj|rwt| q[tddiS )Nr   reg_code_r      .r   )candidateidvideoid)recordedr/  r  r  uploadscandidate_audior   success)r   r   r   r   r   splitrG   r   r   r   rO   r   saverP   callendflagospathr   r
   existslistdir
startswithisfileremover   )	r   r   c_codeschidcandidate_detailscall_detailsprofiling_dirfilename	file_pathr   r   r   interviewFile  s"    
rF  c              
   C   s   d d dd}z+| j dkr-t| jd}t| j}t||j d|d< d|d< W t|S W t|S  t	yP } zd|d< t
||d	< W Y d }~t|S d }~ww )
Nr   r   r   r   Savedr   r   z#Error in Saving Meeting Status viewr   )r   r   r   r   r   r   r   r)   r   r   r   r   )r   r   r   r   r   r   r   r   interviewCompletion  s(   


rH  c              
   C   s   d d dd}z*| j dkr,t| j}t| jd}t|| d|d< d|d< W t
|S W t
|S  tyO } zd|d< t	||d	< W Y d }~t
|S d }~ww )
Nr   r   r   r   zFeedback given successfullyr   r   zError in feedback viewr   )r   r   r   r   r   r   r   r`   r   r   r   r   r   r   r   r   r   r   r   interviewFeedback  (   




rJ  c              
   C   s   d d dd}z5| j dkr2t| j}t| jd}t||}||d< |d dkr7d|d< W t
|S W t
|S W t
|S  tyR } zd	|d< t	||d
<  d }~ww )Nr   r   r   r   msgzDeleted-successfullyr   r   z$Error in Deleting Test from workflowr   )r   r   r   r   r   r   r   r0   r   r   r   )r   r   r   r   testDetailsr   r   r   r   deleteTestinJs%  s.   



rN  c              
   C   s   d d dd}z*| j dkr,t| j}t| jd}t||}||d< d|d< W t
|S W t
|S  tyG } zd|d< t	||d<  d }~ww )	Nr   r   r   r   r   r   zError in saving interviewersr   )r   r   r   r   r   r   r   r1   r   r   r   )r   r   r   r   interviwersDatar   r   r   r   saveInterviewersForJd<  s(   



rP  c              
   C   s   d d dd}z*| j dkr,t| j}t| jd}t||}||d< d|d< W t
|S W t
|S  tyO } zd|d< t	||d< W Y d }~t
|S d }~ww )	Nr   r   r   r   r   r   zError in Test has paper idr   )r   r   r   r   r   r   r   r/   r   r   r   )r   r   r   r   testaaPaperDetailsr   r   r   r   checkTestHasPaperR  rK  rR  c              
   C   s   d d dd}z.| j dkr0t| j}t| jd}| j}t||| d|d< d|d< W t|S W t|S  t	yS } zd|d< t
||d	< W Y d }~t|S d }~ww )
Nr   r   r   r   z#Email Template updated successfullyr   r   zError in updateEmailtempr   )r   r   r   r   r   r   r   FILESra   r   r   r   )r   r   r   r   fileObjsr   r   r   r   updateEmailtempg  s*   


rU  c              
   C   s   d d dd}z;| j d}t|}t|d d}t| dd}d|d	  d
|d< |W  d    W S 1 s8w   Y  W t|S  ty` } zd|d< t||d< W Y d }~t|S d }~ww )Nr   r   r   rE  rbapplication/pdfr   attachment; filename="	file_name.pdf"Content-DispositionzError in downloading reportr   r   )	r   r   r,   openr   readr   r   r   )r   r   candidate_idpdf_pathpdf_filer   r   r   r   candidateReport~  s    $
ra  c              
   C   s   d d dd}z/| j dkr1t| j}t| jd}t| j}t||}||d< d|d< W t|S W t|S  t	yL } zd|d< t
||d<  d }~ww )	Nr   r   r   r   r   r   zError in Jd Publishr   )r   r   r   r   r   r   r   r   r!   r   r   r   )r   r   r   r   companyDatar   r   r   r   r   	jdPublish  s*   




rc  c              
   C      d d dd}z*| j dkr,t| j}t| jd}t|| d|d< d|d< W t
|S W t
|S  tyO } zd|d< t	||d	< W Y d }~t
|S d }~ww )
Nr   r   r   r   zCandidate Notified Successfullyr   r   zError in Candidate Notify viewr   )r   r   r   r   r   r   r   r.   r   r   r   rI  r   r   r   notifyCandidate  rK  re  c              
   C   s  d d dd}z| j dkr| j}t|d }|d dkr|d }tjj|d}tjj||d	}d
}|j|jkr?d}|j|j }nd
}|j}t	 d }	t
|	d }
t
|	d }||kr\d
}n	||
krcd}nd}d
}|d
kso|dkr}|jdkr}d}d|_|  d}ttjj||ddjddd}||||||d|d< |d dkr|d }|d }t||| d|d< W t|S W t|S  ty } zd|d< t||d< W Y d }~t|S d }~ww )Nr   r   r   r   request_typecheck_credits
paper_typer  )r   	transtyper  r  r	  lowcredits_warningreg_stop_warningLr  zHR-Admin)r   role__containsr  r   Tr  )r   credit_availablity_statcredits_statushradmin_emails_listcurrent_creditssend_lowcredits_notificationr   deduct_creditsr#  r   r   $Error in getUpdateCompanyCreditsViewr   )r   r   r   rE   r   r   rH   balancecreditsr   r   lowcreditsnotificationr6  r$  rL   r   r%  r   r   r   r   )r   r   r   r   rh  company_accountcompany_creditsrn  rq  r  rj  rk  ro  rr  hr_admin_labelrp  r#  r   r   r   r   getUpdateCompanyCreditsView  sn   


 
	
8r{  c              
   C   s   d d dd}zO| j dkrQt| j}|j}tjj|d}t d }t|d }t|d }|j	|kr4d}n
|j	|kr<d	}nd
}|j	|d}	|	|d< d|d< W t|S W t|S  t
yt }
 zd|d< t|
|d< W Y d }
~
t|S d }
~
ww )Nr   r   r   r  r	  rj  rk  r  rl  r  )balance_creditscredits_avaliabiltyr   r   r   zError in getCreditsViewr   )r   r   r   r   rE   r   r   r   r   ru  r   r   r   )r   r   r   r   rx  r  rj  rk  r}  company_account_objr   r   r   r   getCreditsView  s>   





r  c              
   C   s  d d dd}z| j dkrt| j}|j}t|}t| jd}|d dkr| j	}t
jj|d\}}|d |_|d	 |_|  d
}	d
}
| D ]3}|d |_|  t|j}	| j d| jd  d|j }||_|  td |	 }	dt|	di}
qI||d< t d d }d}t||}tj|||
dd}|j}|rt|d}|d }|dkrd|d< d|d< W t|S W t|S W t|S W t|S W t|S  ty } zd|d< t||d< tdt| W Y d }~t|S d }~ww )Nr   r   r   r   rf  update_brandingr  css_contentr  r   z://	HTTP_HOSTz/media/logorV  r   r   r   z/api/company-brandingF)r   filesr   r   r   r   zBranding updated successfullyz"Error in updateCompanyBrandingViewr   z%Error in updateCompanyBrandingView : ) r   r   r   r   r   r   r   r   r   rS  rF   r   get_or_creater   r  r6  itemslogourlr   schemeMETAr	   r\  r   r   r   r   r   r   loggingr   r   )r   r   r   r   r  r   rT  company_brandingcompany_branding_flaglogo_file_path	logo_filefilelogo_fullpathr   r   r   update_responser   r   resp_status_coder   r   r   r   updateCompanyBrandingView/  sn   







-(	r  c                 C   s&   t | j}t|j}t|j|jdS )N)namecompanyname)r   r   r   r   r   r  )r   r   companyr   r   r   getUserNameh  s   

r  c              
   C      d d dd}z#t | j}t| jd }}t|j|}||d< d|d< W t
|S  ty@ } zd|d< t	||d<  d }~ww Nr   r   r   r   r   zError in Creating New Userr   )r   r   r   r   r   r   r-   r   r   r   r   r   r   r   r   userDatar   r   r   r   addNewUsersn  "   

r  c              
   C   r  r  )r   r   r   r   r   r   r"   r   r   r   r   r  r   r   r   changeUserStatus  r  r  c           
   
   C   s  d d dd}z| j dkr| j}t|d }|d dkrRtjjt|d |d}tjj||j|j	|d	 t|d
 d
 }t |_|d |_|  d|d< d|d< |d dkrutjjt|d |d}|d |_|  d|d< d|d< |d dkrtjjt|d |d}t|d
 }t||j|j	|d	 |t dd}|  |d	 dkrtjj|j	d}t|j|j|d|jd}|  |jr|d	 dkrt|jdd n|d	 dkrt|jdd d|d< d|d< W t|S W t|S W t|S  ty }	 zd |d< t|	|d!<  d }	~	ww )"Nr   r   r   r   update_type
reg_statusparticipant_refidr/  r   rh  r#  )r   r/  r   r   r   update_valuez(Registration status updated successfullyr   r   r   candidate_statusz%candidate status updated successfullyadd_registrationI)r   r/  r   r   r   registrationdater  r  r  )r/  hridr#  r  r   r   SCzScreening SentECTzCoding Test SentzRegistered successfullyrt  r   )r   r   r   rG   r   r   rK   r   r   r   r   r   nowcompletiondater  r6  rI   rP   	createdbyr   	profileidrz   r   r   r   )
r   r   r   r   	candidateregistrationr#  job_desccall_scheduler   r   r   r   updateHirelinesData  s   





C)r  c              
   C   r  )	Nr   r   r   r   r   r   z#Error in save interview remark viewr   )	r   r   r   r   r   rb   r   r   r   r  r   r   r   interviewRemarkSave  s&   

r  c              
   C   s   d d dd}z8| j dkr:| j}t|d }|d }tjj||d}tjj|jd	 
 }||d< d	|d
< W t|S W t|S  ty] } zd|d< t||d< W Y d }~t|S d }~ww )Nr   r   r   r   
cand_refidr  r  r   r   r   zError in getJDDatar   )r   r   r   rG   r   r   rI   r   r   r   r   r   r   r   )r   r   r   r   r  r  r   r   r   r   r   	getJDData  s,   

r  c              
   C      d d dd}z$| j dkr&t| jd}t| d|d< d|d< W t|S W t|S  tyI } zd|d< t||d	< W Y d }~t|S d }~ww )
Nr   r   r   r   zmake a star questionr   r   Error in update emailsr   )	r   r   r   r   r   rd   r   r   r   r   r   r   r   makeAstarQuestion  &   


r  c              
   C   r  )	Nr   r   r   r   r   r   z)error while getting the topics for skillsr   )	r   r   r   r   r   r$   r   r   r   )r   r   r   
skillsDatar   r   r   r   skillsWithTopicwithSubtopics.  r  r  c              
   C   r  )
Nr   r   r   r   z$Company details updated successfullyr   r   r  r   )	r   r   r   r   r   rc   r   r   r   r   r   r   r   updateCompanyC  r  r  c              
   C   r  )	Nr   r   r   r   r   r   zError in adding demo userr   )	r   r   r   r   r   r2   r   r   r   )r   r   r   demo_idr   r   r   r   demoUserY  &   

r  c              
   C   r  )
Nr   r   r   r   zDemo requestedr   r   zError in requesting demor   )	r   r   r   r   r   re   r   r   r   r   r   r   r   demoRequestp  r  r  c              
   C   r  )
Nr   r   r   r   zCandidate deletedr   r   z Error in deleting the candidatesr   )	r   r   r   r   r   rf   r   r   r   r   r   r   r   deleteCandidate  r  r  c              
   C   s   d d dd}z&| j dkr(t| jd}t|}t||d< d|d< W t	|S W t	|S  tyK } zd|d< t||d< W Y d }~t	|S d }~ww )	Nr   r   r   r   r   r   z)Error in updating candidate workflow datar   )
r   r   r   r   r   r3   r   r   r   r   )r   r   r   updated_datar   r   r   r   updateCandidateWorkflow  s&   


r  c              
   C   s   d d dd}z | j dkr"t| j}t|}||d< d|d< W t|S W t|S  tyE } zd|d< t||d< W Y d }~t|S d }~ww )	Nr   r   r   r   r   r   Error in getting dashboard datar   )r   r   r   r4   r   r   r   )r   r   r   dashboard_datar   r   r   r   getDashboardGraphData  s&   



r  c              
   C   rd  )
Nr   r   r   r   zSources Data Updatedr   r   r  r   )r   r   r   r   r   r   r   rg   r   r   r   r   r   r   r   r   r   r   r   updateSourceData  (   



r  c              
   C   rd  )
Nr   r   r   r   zCandidate info Updatedr   r   z Error in updating candidate infor   )r   r   r   r   r   r   r   rh   r   r   r   r  r   r   r   updateCandidateInfo  r  r  c              
   C   s   d d dd}z+| j dkr-t| j}t| j}| j}t||j|}||d< d|d< W t	|S W t	|S  tyH } zd|d< t||d<  d }~ww )	Nr   r   r   r   r   r   z$Error in excel mapping response datar   )
r   r   r   r   rS  r5   r   r   r   r   )r   r   r   r   rT  mapping_responser   r   r   r   candidateUploadFile  s*   



r  c              
   C   s   d d dd}z8| j dkr:t| j}t| jd}t| j}tj	t
|||jfd}d|_|  d|d< W t|S W t|S  tyU } zd	|d< t||d
<  d }~ww )Nr   r   r   r   )targetargsTr   r   z)Error in confirmed candidate data servicer   )r   r   r   r   r   r   r   r   	threadingThreadr6   r   daemonstartr   r   r   )r   r   r   r   r   threadr   r   r   r   confirmedCandidateData  s,   



r  c              
   C   rd  )
Nr   r   r   r   zData Updatedr   r   z(Error in updating dashboard display datar   )r   r   r   r   r   r   r   ri   r   r   r   r  r   r   r   updateDashboardDisplayFlag+  r  r  c              
   C   s   d d dd}z$| j dkr&t| jd}t|}||d< d|d< W t|S W t|S  tyA } zd|d< t||d<  d }~ww )	Nr   r   r   r   r   r   z-Error in checking candidate registration datar   )	r   r   r   r   r   r7   r   r   r   )r   r   r   registration_flagr   r   r   r   checkJdCandidateRegistrationB  s&   

r  c              
   C   s   d d dd}z*| j dkr,t| j}t|}tt|d ddd}d|d	  |d
< |W S W t|S  tyG } zd|d< t||d<  d }~ww )Nr   r   r   report_file_pathrV  zAapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetr   zattachment; filename=report_file_namer[  z"Error in downloading Upload Reportr   r   )	r   r   r   r8   r   r\  r   r   r   )r   r   r   report_file_datar   r   r   r   downloadUploadReportX  s,   

r  c              
   C   s   d d d}z5| j d}|sd|d< t|ddW S tjj|d }|r*|j|d< nd	| |d< W t|S W t|S  tyU } zt	||d< W Y d }~t|S d }~ww )
N)r#  r   r   zMissing test_idr   i  r  )
workflowidr#  zNo paper found for test_id )
r   r   r   rQ   r   r   r   r   r   r   )r   r   r   bruler   r   r   r   get_paperidu  s$   
r  c                 C   s@  t | jdd}|dd}|dd}|dd}|dd}|dd}|d	d}|d
d}|dd}	|r@t|nd }|rHt|nd }| j}
tjj|
dj}t	jj
|dd}|rg|j
|d}|d ur|d urg }tj D ] }|jr|jr|j|j }||  kr|krn qv||j qv|j
|d}|rtjj
|d }|r|j
|jd}n| }|rtjj
|djddd}|j
|d}|r|j
|d d}|r|	rt|d}t|	djdddd}|j
||d}ddd d!d"}g }|D ]}tjj
|jd# }|r|jr|jr|j|j nd}tjj
|jdjd$dd p,d}t|d%dp5d}tjj
|jd#d&d' }|rX|d&pNd}|d'pVd}nd}d}||j|jd(|j rl|j nd|j!rt|j!nd)|j"r||j"nd)|j#r|j#nd)| d*|t$|j%|j%|||d+ qt&d|d,S )-Nr   {}titler   exp_fromexp_tosourceskillsr  	date_fromdate_tor   r  z-dateofcreationtitle__icontains)id__inr  )sourceid)primaryskills__icontainsr  Tr  r   r  z%Y-%m-%d   ;   )hourminutesecond)dateofcreation__gtedateofcreation__lteDraftRejectedOfferedEmployee)DROr  )r  labelstrengthprimaryskillssecondaryskillsz%d-%b-%Y %I:%M %p z Years)r   datecoder  	firstnamelastname
experiencer  r  primaryskills_namesecondaryskills_nameprofilestrength)r   r   )'r   r   r   r   r   r   rL   r   r   rR   r   order_byrS   allyearfromyeartor   r  rT   r   r   nonerU   r%  r   strptimereplacer  getattrr   dateofcreationstrftimeprofilecoder  r  r  r   r  r   )r   r   r  r  r  source_coder  r  r  r  
login_userr   filtered_profilesmatched_idsexpyears
source_objskill_profile_idsstart_datetimeend_datetime
status_mapfinal_outputprofilesource_valuestrength_valskills_data
primary_sksecondary_skr   r   r   filter_profiles_api  s   &

r(  c                 C   s2   t jj|d}t|jd}tdd| iS )N)resumeidr   pdf_datazdata:application/pdf;base64,)rX   r   r   base64	b64encodefilecontentr   r   )r   ridresume_filefile_base64r   r   r   getResumeFile  s
   
r1  c              
   C   s   d d dd}z*| j dkr,t| jd}t| j}t||}||d< d|d< W t
|S W t
|S  tyG } zd|d< t	||d<  d }~ww )	Nr   r   r   r   r   r   z%Error in getting filtered resume datar   )r   r   r   r   r   r   r   r9   r   r   r   )r   r   r   	user_dataresumes_datar   r   r   r   getFilterResumes  s(   



r4  c              
   C   s   d d dd}z&| j dkr(t| jd}t|d  d|d< d|d< W t|S W t|S  tyC } zd	|d< t||d
<  d }~ww )Nr   r   r   r   	resume_idr4  r   r   Error in deleting Resumer   )	r   r   r   r   r   r:   r   r   r   r   r   r   r   deleteResume-  s&   

r7  c              
   C   r   )	Nr   r   r   r   r   r   r6  r   )r   r   r   r   r   r   r   rk   r   r   r   )r   r   r   r2  add_profiler   r   r   r   addResumeProfileE  s(   



r9  c              
   C      d d dd}z1| j dkr3t| jd}| jd}t| j}t||| d|d< d|d< W t|S W t|S  t	yN } zd	|d< t
||d
<  d }~ww )Nr   r   r   r   
attachmentr4  r   r   zError in saving Profile Detailsr   )r   r   r   r   r   rS  r   r   rj   r   r   r   r   r   r   rT  r2  r   r   r   r   
addProfile_  *   


r=  c              
   C      d d dd}z+| j dkr-t| jd}t| t|d d d|d< d|d	< W t	|S W t	|S  tyH } zd
|d< t||d<  d }~ww )Nr   r   r   r   r  
profile_idr4  r   r   z!Error in updating Profile Detailsr   )
r   r   r   r   r   rl   r|   r   r   r   r   r   r   r   updateProfileDetailsz  (   

rB  c              
   C   r?  )Nr   r   r   r   rA  r@  r4  r   r   z+Error in updating Profile Education Detailsr   )
r   r   r   r   r   rm   r|   r   r   r   r   r   r   r   updateProfileEducation  rC  rD  c              
   C   r?  )Nr   r   r   r   rA  r@  r4  r   r   z,Error in updating Profile Experience Detailsr   )
r   r   r   r   r   rn   r|   r   r   r   r   r   r   r   updateProfileExperience  rC  rE  c              
   C   r?  )Nr   r   r   r   rA  r@  r4  r   r   z*Error in updating Profile Projects Detailsr   )
r   r   r   r   r   ro   r|   r   r   r   r   r   r   r   updateProfileProjects  rC  rF  c              
   C   r?  )Nr   r   r   r   rA  r@  r4  r   r   z(Error in updating Profile Awards Detailsr   )
r   r   r   r   r   rp   r|   r   r   r   r   r   r   r   updateProfileAwards  rC  rG  c              
   C   r?  )Nr   r   r   r   rA  r@  r4  r   r   z-Error in updating Profile Certificate Detailsr   )
r   r   r   r   r   rq   r|   r   r   r   r   r   r   r   updateProfileCertificates  (   

rH  c              
   C   r?  )Nr   r   r   r   rA  r@  r4  r   r   z(Error in updating Profile Skills Detailsr   )
r   r   r   r   r   rr   r|   r   r   r   r   r   r   r   updateProfileSkills  rI  rJ  c              
   C   s   d d dd}z-| j dkr/t| j}|j}t| jd}t|| d|d< d|d< W t|S W t|S  t	yJ } zd|d< t
||d	<  d }~ww )
Nr   r   r   r   r4  r   r   z(Error in adding Profile Activity Detailsr   )r   r   r   r   r   r   r   r   rs   r   r   r   )r   r   r   useridr   r   r   r   r   addProfileActivity'  s*   



rL  c              
   C   s  d d dd}z| j dkr| j }| jd}t|d }tjj|dj}|rY|	 }t
j|jd  }|dv rHzt|}W n   |}Y n|dkrO|}ntd	|j}	|}
nd }	d }
d
}d|v rtjj||d d }|ru|j}nt||d |d d}|  |j}t||	d |dd}|  |
rt|j|	|
d}|  d|d< d|d< W t|S W t|S  ty } zd|d< t||d<  d }~ww )Nr   r   r   r;  r  r  )z.docz.docxz.pdfzUnsupported file formatr   zsource-code)r   r  )r   r  r  P)r  rD  mailidr   r  )r)  rD  r-  zResume uploaded successfullyr   r   r   zError in candidateProfiler   )r   r   dictrS  r   r   rI   r   r   r]  r8  r9  splitextr  lowerr   r   rT   r   r   r   r6  rY   rX   r   r   )r   r   r   fileObjr   r   file_binaryext
pdf_binaryrD  	file_datar  r  
new_source
new_resumer/  r  r   r   r   candidateProfileA  s~   


SrY  c              
   C   sp   d d dd}z| j dkrt  d|d< d|d< W t|S W t|S  ty7 } zd|d< t||d	<  d }~ww )
Nr   r   r   r4  r   r   r   z#Error in getting resume from emailsr   )r   r   r   r   r   )r   r   r   r   r   r   getMailResumes  s$   


rZ  c              
   C   sN  d d dd}z~| j d}|std d|d< t|W S tjj|d}|j}|j}|j}t	jj|d}t
 d d	 }d
}	t||	}
||||jd}tj|
|ddid }|ddkrdtd d|d< d|d< d|i|d< | j}tjj|dj}t|dd| W t|S  ty } ztdt| t||d< W Y d }~t|S d }~ww )Nr   r   rA  z Missing profile_idprofile_id missingr   r  r   r   z/api/get-welcome-mail)	companyIdtoEmail
first_namecompanyNameContent-Typeapplication/jsonr   headersr   r   z ACERT email process failedzACERT email process failedr   r   r  E1zThank you notez  Exception in sendwelcomemail():)r   r   r   r   rR   r   r  r   r   rW   r   r   r  r   r   r   r   rL   r   rz   r   r   )r   r   rA  r"  r^  to_emailr   r  r   r   r   payload	acert_resr   acvityuseridr   r   r   r   sendwelcomemail  sZ   

	ri  c              
   C   s   ddd}z(| j d}|sd|d< t|W S tjj|dd }||d	< d
|d< t|W S  tyI } zt||d< t|W  Y d }~S d }~ww )NFr   )
email_sentr   rA  r[  r   rd  )r  activitycoderj  r   r   )	r   r   r   rZ   r   r   r:  r   r   )r   r   rA  r:  r   r   r   r   check_welcome_mail_status	  s(   


rl  c              
   C   sF  d d dd}d }zz[| j dkrc| jd}t| j}t||}tj|d }t	|d d-}t
| dd}d	|d
  d|d< |W  d    W W |rYtj|rZt| S S S 1 s^w   Y  W n ty } zd|d< t||d< W Y d }~nd }~ww W |rtj|rt| t|S |rtj|rt| w w w )Nr   r   r   pidrE  rV  rW  r   rX  rY  rZ  r[  zError in downloading profiler   r   )r   r   r   r   r   r;   r8  r9  normpathr\  r   r]  r:  r>  r   r   r   )r   r   pdf_file_pathrA  r2  r_  r`  r   r   r   r   downloadBrandedProfile	  sF   



rp  c           
   
   C   s  d d dd}zht | jd}|d}|d}tjj||d}| s3g |d< d|d< t|W S g }|D ]}|	|j
|j|j|j|jrL|jd	nd |jd
 q7| }|j|d< |j|d< ||d< d|d< t|W S  ty }	 zt|	|d< t|W  Y d }	~	S d }	~	ww )Nr   r   r   user_idr   )rK  r   r   r   z%H:%M:%S)r   rK  r   startday	starttimehoursweekoff1weekoff2r   )r   r   r   r   r[   r   r   r:  r   r   r   rK  r   rr  rs  r  rt  r   ru  rv  r   r   )
r   r   r   rq  r   rowsr   rr   r   r   r   r   
getworkcal<	  sD   






ry  c              
   C   r  )
Nr   r   r   r   r4  r   r   zError in saving Detailsr   )	r   r   r   r   r   rt   r   r   r   r   r   r   r   saveworkcalt	  s&   

rz  c              
   C   s   d d dd}zt jj|d}|  d|d< d|d< W t|S  t jy3   d|d	< d|d< Y t|S  tyQ } zt||d	< d|d< W Y d }~t|S d }~ww )
Nr   r   r  r   r   zDeleted Successfullyr   zRecord not foundr   )r[   r   r   deleteDoesNotExistr   r   r   )r   r   r   objr   r   r   r   delete_work_cal	  s(   


r~  c              
   C   sX  dd d}zt | jd}|d}|d}|d}|dd}tjj|d	}|d
kr2||_||_||_|	  |d
krt
jj|jd	}t
jj|d	}	t d d }
d}t|
|}|j|	j|	j|j|j|jd}tj||ddid  }|ddkrd|d< t|W S d|d< W t|S  ty } zt||d< W Y d }~t|S d }~ww )Nr   )r   r   r   JdIDr  hiring_manager_idcommentsr   r  Fr   r   z/api/get-approval-mail)r\  r]  r^  jdTitlehrNamejdIdr`  ra  rb  r   r   zACERT approval mail failedr   )r   r   r   r   rI   r   hiringmanager_idapproval_statusr  r6  rL   r  r   r   r   r   r  r  r   r   r   r   r   r   )r   r   r   r   r  r  r  r  hrhiringmanagerr   r   r   rf  rg  r   r   r   r   update_jd_status	  sV   




	

r  c              
   C   s   d d dd}t d z$| jdkr*t| jd}t|}||d< d|d< W t	|S W t	|S  tyM } zd|d< t||d	< W Y d }~t	|S d }~ww )
Nr   r   scheduleCandidateInterviewr   r   r   r   zError in Scheduling Interviewr   )
r   r   r   r   r   r   rv   r   r   r   r  r   r   r   r  
  s(   


r  c              
   C   s   d d dd}z3| j dkr0t| jd}|d }t|}t| j}t||}||d< d|d< nt	dW S W t|S  t
yP } zd	|d< t||d
<  d }~ww )Nr   r   r   r   r^  r   r   r   r   r   )r   r   r   r   r   r   r   r   ru   r   r   r   r   )r   r   r   r^  enc_candidate_idr2  r   r   r   r   r   scheduleCandidateInterviewLink
  s,   




	r  c              
   C   r  )
Nr   r   r   r   r4  r   r   z"Error in assigning Recruiter to JDr   )	r   r   r   r   r   rw   r   r   r   r   r   r   r   jdRecruiterAssign9
  &   

r  c              
   C   s   d d dd}z$| j dkr&t| jd}t| d|d< d|d< W t|S W t|S  tyA } zd|d< t||d	<  d }~ww )
Nr   r   r   r   r4  r   r   zError in updating full profiler   )	r   r   r   r   r   rx   r   r   r   r   r   r   r   auto_fill_profileR
  s&   

r  c           
   
   C   s   dd d d}z2t | j}t| j}|j}|j}| jd}| jd}t|||||d}||d< d|d< W t
|S  tyS }	 zt	|	|d	< W Y d }	~	t
|S d }	~	ww )
Nr   r   r   r   	recruitermonthr   	user_rolelogged_recruiter_idselected_recruitermonth_valuer   r   r   r   )r   r   r   r   r   r   r   r<   r   r   r   
r   r   r   r2  r  r  r  r  r  r   r   r   r   recruiter_dashboard_filterj
  s4   


r  c              
   C   s   d d dd}z*| j dkr,t| jd}t| j}t|| d|d< d|d< W t
|S W t
|S  tyO } zd|d< t	||d	< W Y d }~t
|S d }~ww )
Nr   r   r   r   r4  r   r   zError in add new workspacer   )r   r   r   r   r   r   r   ry   r   r   r   )r   r   r   r2  r   r   r   r   addWorkspace
  s(   



r  c              
   C      d d dd}z*| j dkr,t| jd}t| j}t||}||d< d|d< W t
|S W t
|S  tyO } zd|d< t	||d< W Y d }~t
|S d }~ww )	Nr   r   r   r   r   r   z Error in getting jd Profile Datar   )r   r   r   r   r   r   r   r=   r   r   r   )r   r   r   r2  jd_profiles_datar   r   r   r   jdProfileData
  s(   



r  c              
   C   r  )	Nr   r   r   r   r   r   z!Error in shortlisting the Profiler   )r   r   r   r   r   r   r   r>   r   r   r   )r   r   r   r2  	shortlistr   r   r   r   shortlistProfile
  s(   



r  c           
   
   C   s   d d dd}zA| j dkrCt| j}t| j}|j}|j}| jd}| jd}td| t	|||||d}||d< d	|d
< W t|S W t|S  t
yf }	 zd|d< t|	|d< W Y d }	~	t|S d }	~	ww )Nr   r   r   r  r  r  r  r   r   r   z%Error in getDashBoardDataService viewr   )r   r   r   r   r   r   r   r   r   r?   r   r   r   r  r   r   r   dashBoardView
  s:   




r  c              
   C   s   zB| j d}tjj|d }|r:|jpd|jpd|jpd|j	p"d|j
p&d|jp*d|jp.dd}td|d dW S tdd ddW S  ty^ } ztdd t|dW  Y d }~S d }~ww )NrA  r  r   )r  educationscoreawardsscorecertificatesscoreexperiencescoreprojectsscoreskillsscorer  r   zProfile not found)r   r   rR   r   r   r   r  r  r  r  r  r  r  r   r   r   )r   rA  r"  statsr   r   r   r   get_profile_strength  s$   
 r  c              
   C   r  )
Nr   r   r   r   r4  r   r   zError in updating workspacer   )	r   r   r   r   r   r{   r   r   r   r   r   r   r   updateWorkspace2  r  r  c              
   C   r  r  )r   r   r   r   r   r   r@   r   r   r   r   r  r   r   r   addNewClientsM  r  r  c              
   C   r  r  )r   r   r   r   r   r   rA   r   r   r   r   r  r   r   r   changeClientStatusf  r  r  c              
   C      zG| j dkr?t| j}t| jdd}|d}|d}|j||d}td| t	|}t
d|d	 |d
 |d dW S t
dg ddW S  tyc } zt
dg t|dW  Y d }~S d }~ww Nr   r   r  r  r  )r   	from_dateto_dater   r   r  r  )r   r  r  r   r   zInvalid request methodr  )r   r   r   r   r   r   r   r   r   rB   r   r   r   r   r   r   r  r  r   resultr   r   r   r   recruiters_performance|  >   






r  c              
   C   s|   z#| j dd }tjj|dddd d }t|}t|ddW S  t	y= } ztd	t
|iW  Y d }~S d }~ww )
Nqr   r  r   r  
   F)safer   )r   r   stripr\   r   r   r   r$  r   r   r   )r   queryqsr   r   r   r   r   search_jd_library  s   r  c              
   C   s   z<| j d}tjj|d}|j|jpd|jpd|jpd|jp d|j	p$d|j
r*|j
ng |jr1|jng d}td|dW S  tjyM   tddd	 Y S  tyg } ztdt|d
W  Y d }~S d }~ww )Nr   r  r   )r  descriptionr   min_expmax_expwork_locationprimary_skillssecondary_skillsr   )r  r   r   zJD not found)r  message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   jd_library_detail  s8   
r  c              
   C   s  z| j dd }| j dd }| j dd }| j dd }| j dd }| j d}t| j}td| d	}d	}	d	}
d }d }d }|rktjj||d
}|r\|j	|d}|}|rkd}	t
|jddd}|rtjj||d}|r}|j	|d}|}|rd}
t
|jddd}|s|s|rtjj|dt|||dt|||dB }|r|j	|d}|}|rd}t
|jddd}t||	|
|||dW S  ty } ztdt|dW  Y d }~S d }~ww )Nr  r   
middlenamer  r   mobilerA  r   F)email__iexactr   r  Tr  r  )r  r   r  )firstname__iexactmiddlename__iexactlastname__iexact)name_existsemail_existsmobile_existsname_profile_codeemail_profile_codemobile_profile_coder   r  )r   r   r  r   r   r   rR   r   r   excluder$  r%  r   r   r   r   )r   r   middler   r   r  rA  r   r  r  r  r  r  r  	email_obj
mobile_objname_objr   r   r   r   validate_profile  s   



	r  c              
   C   s   d d dd}z+| j dkr-t| j}t| jd}t||j}||d< d|d< W t|S W t|S  t	yP } zd|d< t
||d< W Y d }~t|S d }~ww )	Nr   r   r   r   r   r   z!Error in getting Job Board Configr   )r   r   r   r   r   r   r   rC   r   r   r   r   )r   r   r   r   config_datar   r   r   r   jobBoardConfig>  (   


r  c              
   C   s   d d dd}z+| j dkr-t| j}t| jd}t||j d|d< d|d< W t|S W t|S  t	yP } zd|d< t
||d	< W Y d }~t|S d }~ww )
Nr   r   r   r   r4  r   r   z(Error in getting saving Job Board Configr   )r   r   r   r   r   r   r   r}   r   r   r   r   rI  r   r   r   saveJobBoardConfigY  r  r  c              
   C   rd  )
Nr   r   r   r   r4  r   r   zError in saving JD Job Boardsr   )r   r   r   r   r   r   r   r~   r   r   r   rI  r   r   r   saveJDJobBoardst  s(   



r  c              
   C   r:  )Nr   r   r   r   
resumefiler4  r   r   zError in adding Resumer   )r   r   r   r   r   rS  r   r   r   r   r   r   r<  r   r   r   	addResume  r>  r  c                 C   s  d d dd}z| j d}tjtdd}tj|dd tj|jd }|	d	d }| d
}tj||}t
jdddddddddd|gt
jt
jt
jd}| D ]}	| d ur] n|j|	 qS|j  |  |jdkr}|j  }
t|
tjtdd| d}tj|rt||}|rtt|d}d}|dk rd}n|dk rd}nd}nd }d }tjj|d}||_||_ |!  ||d< d|d < nd!|d< d|d < W t#|S W t#|S  ty } zt"||d"< W Y d }~t#|S d }~ww )#Nr   r   speaker_audior2  r3  T)exist_okr   r,  z.wavffmpegz-yz-fwebmz-izpipe:0z-ac1z-ar16000)stdinstdoutstderrz_profileaudio.wavr-  r   U   rl  Z   MHr  r   r   zProfile audio not foundr   )$rS  r   r8  r9  r   r
   makedirsrP  r  r5  
subprocessPopenPIPEDEVNULLchunkspollr  writeclosewait
returncoder  r]  r   r   r:  r   roundfloatrP   r   
audioscore
audiolevelr6  r   r   )r   r   
audio_filefolder_path	base_name
scheduleidwav_filenamewav_pathprocesschunkr   profile_file_pathresult_scorelevelcall_schr   r   r   r   uploadAudioFile  s   
	




r  c              
   C   r  r  )r   r   r   r   r   r   r   r   r   rD   r   r   r   r  r   r   r   source_performance  r  r  (  r   r8  r   r   r  timer  rer+  urllib.parser   r   django.httpr   r   app_api.functions.enc_decr   r   #app_api.functions.voice_comparisionr   hirelines.settingsr	   r
   rest_framework.decoratorsr   r   r   r   r   django.views.decorators.csrfr   allauth.account.utilsr   allauth.accountr   r   app_api.functions.masterdatar   r   r   django.db.modelsr   hirelines.metadatar   r   functions.servicesr   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   modelsrE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   functions.databaser]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   app_api.functions.constantsr   r   app_api.functions.email_resumer   functions.doc2pdfr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r)  r*  rF  rH  rJ  rN  rP  rR  rU  ra  rc  re  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(  r1  r4  r7  r9  r=  rB  rD  rE  rF  rG  rH  rJ  rL  rY  rZ  ri  rl  rp  ry  rz  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   <module>   s    h







@
4





3
y








C

#
8

M













{












]

K


7

6
@



#



7




*

#
_



Y