
    ժiH                     8   d dl mZ d dlmZmZ ddlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlZd dlmZ  G d	 d
ej>                        Z  G d dej>                        Z! G d dej>                        Z" G d dej>                        Z# G d dej>                        Z$ G d dej>                        Z% G d dej>                        Z& G d dej>                        Z' G d dej>                        Z( G d dej>                        Z) G d dej>                        Z* G d d ej>                        Z+ G d! d"ej>                        Z, G d# d$ej>                        Z- G d% d&ej>                        Z. G d' d(ej>                        Z/ G d) d*ej>                        Z0 G d+ d,ej>                        Z1 G d- d.ej>                        Z2 G d/ d0ej>                        Z3 G d1 d2ej>                        Z4 G d3 d4ej>                        Z5y)5    )serializers)UserGroup   )	TblClientTblDepartment	TblVendorTblJobDescriptionTblImpDepartmentTblClientDocumentTblVendorDocument
UserClientAssignJdUserRecruiterMappingImplementerPortalConfigTblCandidateProfileTblCandidateResumeL0InterviewListL0InterviewSessionsTblMatchedProfilesTblMatchedProfilesCandidatecareer)ImplementerDetails)timezoneN)LogEntryc                        e Zd Z G d d      Zy) ImplementerDetailsLiteSerializerc                       e Zd ZeZdZy)%ImplementerDetailsLiteSerializer.Meta)idnamedisplay_namereference_idstatusN)__name__
__module____qualname__r   modelfields     ./var/www/auto_recruiter/masters/serializers.pyMetar      s    "
r+   r-   Nr%   r&   r'   r-   r*   r+   r,   r   r      s    
 
r+   r   c                   F    e Zd Z ej                  d      Z G d d      Zy)ClientDocumentSerializerTuse_urlc                       e Zd ZeZg dZy)ClientDocumentSerializer.Metar    documentuploaded_dateN)r%   r&   r'   r   r(   r)   r*   r+   r,   r-   r4   *       !4r+   r-   Nr%   r&   r'   r   	FileFieldr6   r-   r*   r+   r,   r0   r0   '       ${$$T2H5 5r+   r0   c                   D    e Zd Z ed      Z G d d      Zd Zd Zd Zy)	TblImpDepartmentSerializerT	read_onlyc                       e Zd ZeZdZdZy)TblImpDepartmentSerializer.Meta__all__)imp_department_idcreated_dateupdated_dateimplementerN)r%   r&   r'   r   r(   r)   read_only_fieldsr*   r+   r,   r-   rA   1   s     _r+   r-   c                     t         j                  j                  |      }| j                  r&|j	                  | j                  j
                        }|j                         rt        j                  d      |S )N)imp_department_name__iexactrC   Department Name already exists.	r   objectsfilterinstanceexcluderC   existsr   ValidationErrorselfvalueqss      r,   validate_imp_department_namez7TblImpDepartmentSerializer.validate_imp_department_name6   sb    %%,,,O==dmm.M.MNB99;--1  r+   c                     t         j                  j                  |      }| j                  r&|j	                  | j                  j
                        }|j                         rt        j                  d      |S )N)imp_dep_contact_email__iexactrJ    Department email already exists.rL   rS   s      r,   validate_imp_dep_contact_emailz9TblImpDepartmentSerializer.validate_imp_dep_contact_emailB   sb    %%,,5,Q==dmm.M.MNB99;--2  r+   c                    |j                  d| j                  r| j                  j                  nd      }|j                  d| j                  r| j                  j                  nd      }|r||rzt        j
                  j                  ||      }| j                  r&|j                  | j                  j                        }|j                         rt        j                  ddi      |S )D
        Validate country code + contact number combination
        imp_dep_country_codeNimp_dep_contact_number)r^   r_   rJ   @Department contact number already exists with this country code.)getrO   r^   r_   r   rM   rN   rP   rC   rQ   r   rR   rT   attrscountry_codecontact_numberrV   s        r,   validatez#TblImpDepartmentSerializer.validateN   s     yy"26--DMM..T
 $48MMDMM00t

 N!))00%1'5 1 B
 }}ZZ$--2Q2QZRyy{!11,Z3  
 r+   N)	r%   r&   r'   r   rF   r-   rW   r[   rf   r*   r+   r,   r=   r=   .   s'    2TBK` `


r+   r=   c                   
   e Zd Z ej                  ddd      Z edd      Z ej                  ddd      Z	 e
d      Z ej                  ej                  j                         dddd	      Z G d
 d      Zd Zd Zd Zy)ClientSerializerFTEnd)requiredallow_blankdefault)manyr?   r2   rj   
allow_nullr>   imp_department)querysetsourcerj   ro   
write_onlyc                       e Zd ZeZdZdZy)ClientSerializer.MetarB   )	client_idrD   rE   N)r%   r&   r'   r   r(   r)   rG   r*   r+   r,   r-   ru          Hr+   r-   c                     t         j                  j                  |      }| j                  r&|j	                  | j                  j
                        }|j                         rt        j                  d      |S )N)client_name__iexactrv   zClient name already exists.	r   rM   rN   rO   rP   rv   rQ   r   rR   rS   s      r,   validate_client_namez%ClientSerializer.validate_client_name   b    %%%%@==dmm&=&=>B99;---  r+   c                     t         j                  j                  |      }| j                  r&|j	                  | j                  j
                        }|j                         rt        j                  d      |S )N)client_contact_email__iexactrz   z$Client contact email already exists.r{   rS   s      r,   validate_client_contact_emailz.ClientSerializer.validate_client_contact_email   sb    %%5%I==dmm&=&=>B99;--6  r+   c                    |j                  d| j                  r| j                  j                  nd      }|j                  d| j                  r| j                  j                  nd      }|r||rzt        j
                  j                  ||      }| j                  r&|j                  | j                  j                        }|j                         rt        j                  ddi      |S )r]   client_country_codeNclient_contact_number)r   r   rz   z<Client contact number already exists with this country code.)ra   rO   r   r   r   rM   rN   rP   rv   rQ   r   rR   rb   s        r,   rf   zClientSerializer.validate        yy!15DMM--D
 #37==DMM//d

 N""))$0&4 * B
 }}ZZ$--*A*AZByy{!11+V3  
 r+   N)r%   r&   r'   r   	CharFieldclient_typer0   	documents
ImageFieldclient_logor=   rp   PrimaryKeyRelatedFieldr   rM   allrC   r-   r|   r   rf   r*   r+   r,   rh   rh   k   s    '+''K )ddCI(+((K 0$?N:::!))--/I I


r+   rh   c                       e Zd Z ed      Z ej                  ej                  j                         dd      Z
 G d d      Zd Zd Zd	 Zy
)TblDepartmentSerializerTr>   client)rq   rr   rs   c                       e Zd ZeZdZdZy)TblDepartmentSerializer.MetarB   )department_idrD   rE   N)r%   r&   r'   r   r(   r)   rG   r*   r+   r,   r-   r      s    Lr+   r-   c                     t         j                  j                  |      }| j                  r&|j	                  | j                  j
                        }|j                         rt        j                  d      |S )N)department_name__iexactr   rK   	r   rM   rN   rO   rP   r   rQ   r   rR   rS   s      r,   validate_department_namez0TblDepartmentSerializer.validate_department_name   sb    ""))%)H==$--*E*EFB99;--1  r+   c                     t         j                  j                  |      }| j                  r&|j	                  | j                  j
                        }|j                         rt        j                  d      |S )N)dep_contact_email__iexactr   rZ   r   rS   s      r,   validate_dep_contact_emailz2TblDepartmentSerializer.validate_dep_contact_email   sb    ""))E)J==$--*E*EFB99;--2  r+   c                    |j                  d| j                  r| j                  j                  nd      }|j                  d| j                  r| j                  j                  nd      }|r||rzt        j
                  j                  ||      }| j                  r&|j                  | j                  j                        }|j                         rt        j                  ddi      |S )r]   dep_country_codeNdep_contact_number)r   r   r   r`   )ra   rO   r   r   r   rM   rN   rP   r   rQ   r   rR   rb   s        r,   rf   z TblDepartmentSerializer.validate   s     yy.2mmDMM**
  04DMM,,4

 N&&--!-#1 . B
 }}ZZdmm.I.IZJyy{!11(Z3  
 r+   N)r%   r&   r'   rh   r   r   r   r   rM   r   rv   r-   r   r   rf   r*   r+   r,   r   r      sQ    -F222""&&(I
M M


r+   r   c                   F    e Zd Z ej                  d      Z G d d      Zy)VendorDocumentSerializerTr1   c                       e Zd ZeZg dZy)VendorDocumentSerializer.Metar5   N)r%   r&   r'   r   r(   r)   r*   r+   r,   r-   r     r8   r+   r-   Nr9   r*   r+   r,   r   r     r;   r+   r   c                   \    e Zd Z ej                  ddd      Z G d d      Zd Zd Zd Z	y	)
VendorSerializerTFrn   c                       e Zd ZeZdZdZy)VendorSerializer.MetarB   )	vendor_idrD   rE   N)r%   r&   r'   r	   r(   r)   rG   r*   r+   r,   r-   r     rw   r+   r-   c                     t         j                  j                  |      }| j                  r&|j	                  | j                  j
                        }|j                         rt        j                  d      |S )N)vendor_name__iexactr   zVendor Name already exists.	r	   rM   rN   rO   rP   r   rQ   r   rR   rS   s      r,   validate_vendor_namez%VendorSerializer.validate_vendor_name  r}   r+   c                     t         j                  j                  |      }| j                  r&|j	                  | j                  j
                        }|j                         rt        j                  d      |S )N)vendor_contact_email__iexactr   zVendor email already exists.r   rS   s      r,   validate_vendor_contact_emailz.VendorSerializer.validate_vendor_contact_email!  sb    %%5%I==dmm&=&=>B99;--.  r+   c                    |j                  d| j                  r| j                  j                  nd      }|j                  d| j                  r| j                  j                  nd      }|r||rzt        j
                  j                  ||      }| j                  r&|j                  | j                  j                        }|j                         rt        j                  ddi      |S )r]   vendor_country_codeNvendor_contact_number)r   r   r   z<Vendor contact number already exists with this country code.)ra   rO   r   r   r	   rM   rN   rP   r   rQ   r   rR   rb   s        r,   rf   zVendorSerializer.validate-  r   r+   N)
r%   r&   r'   r   r   vendor_logor-   r   r   rf   r*   r+   r,   r   r   	  s8    (+((KI I


r+   r   c                   n    e Zd Z ej                         Z ej                  d      Z G d d      Zd Z	y)TblJobDescriptionSerializerTr>   c                       e Zd ZeZdZdZy) TblJobDescriptionSerializer.MetarB   )jd_idrD   rE   jd_display_idN)r%   r&   r'   r
   r(   r)   rG   r*   r+   r,   r-   r   N  s    !Ur+   r-   c                 v    t        t        j                  j                  |      j	                  dd            S )N)jduser__usernameT)flat)listr   rM   rN   values_listrT   objs     r,   get_assigned_recruitersz3TblJobDescriptionSerializer.get_assigned_recruitersS  s5    ##s#+[)[5
 	
r+   N)
r%   r&   r'   r   SerializerMethodFieldassigned_recruitersIntegerFieldlinkedin_posts_countr-   r   r*   r+   r,   r   r   K  s7    ;+;;=3;33dCV V

r+   r   c                        e Zd Z G d d      Zy)UserClientSerializerc                       e Zd ZeZdZy)UserClientSerializer.Metar   N)r%   r&   r'   r   r(   r)   r*   r+   r,   r-   r   Z  s    r+   r-   Nr.   r*   r+   r,   r   r   Y  s     r+   r   c                   z    e Zd Z ej                  ej                  j                         dd      Z G d d      Z	y)AssignJdSerializerTF)rq   rm   rj   c                       e Zd ZeZdZdZy)AssignJdSerializer.Meta)r    userr   r   departmentsr$   r   N)r%   r&   r'   r   r(   r)   rG   r*   r+   r,   r-   r   e  s    
 'r+   r-   N)
r%   r&   r'   r   r   r   rM   r   r   r-   r*   r+   r,   r   r   ^  s6    4+44&&**,K
' 
'r+   r   c                   H    e Zd Z ej                  dd      Z G d d      Zy)UserRecruiterMappingSerializerzrecruiter.usernameT)rr   r?   c                       e Zd ZeZdZy)#UserRecruiterMappingSerializer.Meta)	recruiterrecruiter_nameN)r%   r&   r'   r   r(   r)   r*   r+   r,   r-   r   w  s    $0r+   r-   N)r%   r&   r'   r   r   r   r-   r*   r+   r,   r   r   q  s$    *[**#N
1 1r+   r   c                   &    e Zd Z G d d      Zd Zy)!ImplementerPortalConfigSerializerc                       e Zd ZeZdZdZy)&ImplementerPortalConfigSerializer.MetarB   )access_tokenrefresh_token
expires_atportal_user_urnis_connected
created_at
updated_atN)r%   r&   r'   r   r(   r)   rG   r*   r+   r,   r-   r   |  s    '
r+   r-   c                 v   |j                  d      }|dk(  rH|j                  d      r"|j                  d      r|j                  d      st        j                  d      |dk(  r7|j                  d      r|j                  d	      st        j                  d
      |dv r7|j                  d      r|j                  d	      st        j                  d      |j                  d      du rP|j                  d      st        j                  ddi      |j                  d      st        j                  ddi      |S )Nportallinkedinrv   client_secretredirect_urizLinkedIn credentials requirednaukriportal_usernameportal_passwordzNaukri credentials required)founditmonsterz6Foundit (Monster) requires both username and password.	has_tokenTtokenzToken is requiredurnzURN is required)ra   r   rR   )rT   datar   s      r,   rf   z*ImplementerPortalConfigSerializer.validate  s$   (#Z88K(0IQUQYQYZhQi!112QRRX88-.dhh?P6Q!112OPP++88-.dhh?P6Q!112jkk88K D(88G$!1103   88E?!11,3   r+   N)r%   r&   r'   r-   rf   r*   r+   r,   r   r   {  s    
 
r+   r   c                        e Zd Z G d d      Zy)TblCandidateProfileSerializerc                       e Zd ZeZdZdZy)"TblCandidateProfileSerializer.MetarB   )r    
created_dt
updated_dtN)r%   r&   r'   r   r(   r)   rG   r*   r+   r,   r-   r     s    #=r+   r-   Nr.   r*   r+   r,   r   r     s    > >r+   r   c                        e Zd Z G d d      Zy)TblCandidateResumeSerializerc                       e Zd ZeZdZdZy)!TblCandidateResumeSerializer.MetarB   )	resume_idr   r   N)r%   r&   r'   r   r(   r)   rG   r*   r+   r,   r-   r     s    "Dr+   r-   Nr.   r*   r+   r,   r   r     s    E Er+   r   c                   H    e Zd Z ej                  dd      Z G d d      Zy)careerSerializerTF)r2   rj   c                        e Zd ZeZdZdddiiZy)careerSerializer.MetarB   db_passwordrs   TN)r%   r&   r'   r   r(   r)   extra_kwargsr*   r+   r,   r-   r     s    L$/
r+   r-   N)r%   r&   r'   r   r   logor-   r*   r+   r,   r   r     s     !;!!$?D
 
r+   r   c                   8   e Zd Z ej                         Z ej                         Z ej                         Z ej                         Z ej                         Z	 ej                         Z
 ej                         Z G d d      Zd Zd Zd Zd Zd Zd Zd	 Zy
)ResumeBasicSerializerc                       e Zd ZeZg dZy)ResumeBasicSerializer.Meta)r   locationtotalexpcandidate_namecandidate_emailcandidate_mobile_numbertitlecandidate_photoprimary_skillstools_and_frameworkstechnical_skills
l0_presentl0_completed_time	l0_resultN)r%   r&   r'   r   r(   r)   r*   r+   r,   r-   r    s    " Br+   r-   c                 `    |j                   j                   d|j                   j                   S )N )candidate_id
first_name	last_namer   s     r,   get_candidate_namez(ResumeBasicSerializer.get_candidate_name  s-    ""--.a0@0@0J0J/KLLr+   c                 0    |j                   j                   S N)r  emailr   s     r,   get_candidate_emailz)ResumeBasicSerializer.get_candidate_email  s    ""(()*r+   c                 0    |j                   j                   S r  )r  mobile_numberr   s     r,   get_candidate_mobile_numberz1ResumeBasicSerializer.get_candidate_mobile_number  s    ""0012r+   c                     |j                   j                  }|sy | j                  j                  d      }|r|j	                  |j
                        S |j
                  S )Nrequest)r  r  contextra   build_absolute_uriurl)rT   r   photor   s       r,   get_candidate_photoz)ResumeBasicSerializer.get_candidate_photo  sO      00,,""9---eii88yyr+   c                 :    | j                   j                  dd      S )Nr  Fr!  ra   r   s     r,   get_l0_presentz$ResumeBasicSerializer.get_l0_present  s    ||e44r+   c                 :    | j                   j                  dd       S )Nr  r'  r   s     r,   get_l0_completed_timez+ResumeBasicSerializer.get_l0_completed_time  s    || 3T::r+   c                 :    | j                   j                  dd       S )Nr  r'  r   s     r,   get_l0_resultz#ResumeBasicSerializer.get_l0_result  s    ||T22r+   N)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    s    6[668N7k779O?k??A7k779O2224J999;1113IB BM+3
5;3r+   r  c                        e Zd Z G d d      Zy)L0InterviewListSerializerc                       e Zd ZeZdZy)L0InterviewListSerializer.MetarB   N)r%   r&   r'   r   r(   r)   r*   r+   r,   r-   r0    s    r+   r-   Nr.   r*   r+   r,   r.  r.         r+   r.  c                        e Zd Z G d d      Zy)L0InterviewSessionsSerializerc                       e Zd ZeZdZy)"L0InterviewSessionsSerializer.MetarB   N)r%   r&   r'   r   r(   r)   r*   r+   r,   r-   r5    s    #r+   r-   Nr.   r*   r+   r,   r3  r3    r1  r+   r3  c                   H    e Zd Z ej                         Z G d d      Zd Zy)TblMatchedProfilesSerializerc                       e Zd ZeZdZy)!TblMatchedProfilesSerializer.MetarB   N)r%   r&   r'   r   r(   r)   r*   r+   r,   r-   r9    s    "r+   r-   c                     |j                   sy t        j                         }||j                   z
  }t        dt	        j
                  |j                         dz              }| dS )Nr   iQ d)status_updated_atr   nowmaxmathceiltotal_seconds)rT   r   r=  diffdayss        r,   get_status_durationz0TblMatchedProfilesSerializer.get_status_duration  sX    $$llnS***1dii 2 2 4u <=>qzr+   N)r%   r&   r'   r   r   status_durationr-   rD  r*   r+   r,   r7  r7    s!    7k779O 	r+   r7  c                   p    e Zd Z ej                         Z ej                         Z G d d      Zd Zd Z	y)%TblMatchedProfilesCandidateSerializerc                       e Zd ZeZdZy)*TblMatchedProfilesCandidateSerializer.MetarB   N)r%   r&   r'   r   r(   r)   r*   r+   r,   r-   rI    s    +r+   r-   c                     t         j                  j                  |j                        j	                         }|r|j
                  S d S N)r   )r
   rM   rN   r   firstr   rT   r   jobs      r,   get_jd_display_idz7TblMatchedProfilesCandidateSerializer.get_jd_display_id  s;    ''..SYY.?EEG$'s  1T1r+   c                     t         j                  j                  |j                        j	                         }|r|j
                  S d S rK  )r
   rM   rN   r   rL  	job_titlerM  s      r,   get_job_titlez3TblMatchedProfilesCandidateSerializer.get_job_title  s9    ''..SYY.?EEG #s}}--r+   N)
r%   r&   r'   r   r   r   rQ  r-   rO  rR  r*   r+   r,   rG  rG    s6    5K557M1113I 2.r+   rG  c                        e Zd Z G d d      Zy)JobSerializerc                       e Zd ZeZdZy)JobSerializer.MetarB   N)r%   r&   r'   r
   r(   r)   r*   r+   r,   r-   rV    s    !r+   r-   Nr.   r*   r+   r,   rT  rT    r1  r+   rT  c                       e Zd Z ej                         Z ej                         Z ej                         Z ej                         Z G d d      Z	d Z
d Zd Zd Zy)AuditLogSerializerc                       e Zd ZeZg dZy)AuditLogSerializer.Meta)r    actoractionr(   	object_idobject_reprchanges	timestampN)r%   r&   r'   r   r(   r)   r*   r+   r,   r-   rZ    s    	
r+   r-   c                 J    |j                   r|j                   j                  S dS )Nsystem)r[  usernamer   s     r,   	get_actorzAuditLogSerializer.get_actor(  s    %(YYsyy!!<H<r+   c                 F    dddd}|j                  |j                  d      S )NCREATEUPDATEDELETE)r   r      UNKNOWN)ra   r\  )rT   r   
action_maps      r,   
get_actionzAuditLogSerializer.get_action+  s)    


 ~~cjj)44r+   c                 .    |j                   j                  S r  )content_typer(   r   s     r,   	get_modelzAuditLogSerializer.get_model3  s    %%%r+   c                     |j                   sy g }|j                   j                         D ]  \  }}|\  }}|j                  |||d       ! |S )N)fieldoldnew)r_  itemsappend)rT   r   	formattedrq  valuesrr  rs  s          r,   get_changeszAuditLogSerializer.get_changes6  s^    {{	 [[..0 	ME6HC 	 r+   N)r%   r&   r'   r   r   r[  r(   r_  r\  r-   rd  rl  ro  rx  r*   r+   r,   rX  rX    s`    -K--/E-K--/E/k//1G.[..0F
 
=5&r+   rX  )6rest_frameworkr   django.contrib.auth.modelsr   r   modelsr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   admin_users.modelsr   django.utilsr   r?  auditlog.modelsr   ModelSerializerr   r0   r=   rh   r   r   r   r   r   r   r   r   r   r   r   r  r.  r3  r7  rG  rT  rX  r*   r+   r,   <module>r     s   & 2    ( 2 !  $	
{'B'B 	
5{:: 5<!<!< <zR{22 RhAk99 AF5{:: 5@{22 @D
+"="= 
;66 
'44 '&1[%@%@ 1&(C(C &P>K$?$? >E;#>#> E
{22 
)3K77 )3V ; ; 
K$?$? 
;#>#> $.K,G,G . K// 
044 0r+   