
    si                     Z   d 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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 ddlmZ ddlmZ ddlmZmZ ddl m!Z! ddl"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z< ddl=m>Z> ddl?m@Z@ ddlAmBZBmCZC ddlDmEZE ddlFmGZGmHZHmIZI ddlJmKZKmLZLmMZMmNZNmOZO e>ZPd ZQ e e3d       d!"       ee2d!"       G d# d$e<                    ZR ee2d!"       e eCd       d!"       G d% d&e:                    ZS ee2d!"       e eCd       d!"       G d' d(e7                    ZT ee2d!"       e eCd       d!"       G d) d*e;                    ZU ee2d!"       e eCd       d!"       G d+ d,e<                    ZV ee2d!"       e eCd       d!"       G d- d.e                    ZW ee2d!"       e eBd       d!"       G d/ d0e8                    ZX G d1 d2e9      ZY G d3 d4e9      ZZy)5z-
This module used for recruitment candidates
    N)Any)BeautifulSoup)forms)messages)HttpResponse)render)render_to_string)reversereverse_lazy)method_decorator)gettext_lazy)View)fields	resources)Workbook)	AlignmentBorderFontPatternFillSide)get_column_letter)pisa)BulkUpdateFieldForm)_thread_locals)export_xlsxlogin_requiredpermission_required)DynamicBulkUpdateForm)HorillaCardViewHorillaDetailedViewHorillaFormViewHorillaListViewHorillaNavViewTemplateView)getattribute)DynamicRejectReasonFormView)all_manager_can_entermanager_can_enter)CandidateFilter)CandidateExportFormRejectedCandidateFormToSkillZoneForm)	CandidateRecruitmentSurveyRecruitmentSurveyAnswerRejectedCandidateSkillZoneCandidatec                 P    t        j                  dd|       j                  dd      S )z
    Convert the question text into a safe attribute name by:
    - Replacing spaces with underscores
    - Removing special characters except underscores
    z[^\w\s]  _)resubreplace)questions    >/var/www/python-projects/worksol/recruitment/cbv/candidates.pyclean_column_namer;   ;   s$     66*b(+33C==    zrecruitment.view_candidate)permdispatch)namec                   0     e Zd ZdZdZdedef fdZ xZS )CandidatesViewz
    For page view

    zcbv/candidates/candidates.htmlkwargsreturnc                 D    t        |   di |}t               }||d<   |S )Nupdate_fields_form )superget_context_datar   )selfrB   contextupdate_fields	__class__s       r:   rH   zCandidatesView.get_context_dataP   s-    '*4V4+-(5$%r<   )	__name__
__module____qualname____doc__template_namer   dictrH   __classcell__rL   s   @r:   rA   rA   D   s'    

 5M   r<   rA   c                        e Zd ZdZeZeZdZg dZ	d Z
deddf fdZg d	ZeZd
dddZdddddddddddddd ed      dddgZdgZg dZdZdZdZd  Z xZS )!ListCandidatesz!
    List view of candidates
    z(cbv/employees_view/bulk_update_page.html)
genderjob_position_id
hired_datereferralcountrystatecityzipjoining_dateprobation_endc           	      ,   t        t        | j                        }t        j                  dt        j
                  dddd            |j                  d<   t        j                  dt        j
                  dddd            |j                  d	<   |S )
z-
        Bulk from generating method
        )
root_modelbulk_update_fieldsFzoh-select oh-select-2zwidth: 100%; height:45px;)classrequiredstyle)attrs)re   widgetr[   r\   )r   r-   rc   r   ChoiceFieldSelectr   )rI   forms     r:   get_bulk_formzListCandidates.get_bulk_formn   s    
 % T5L5L
 "'!2!2<<4 %8	"
I  %00<<4 %8	 
G r<   rB   rC   Nc                    t        |   di | g | _        t        d      | _        | j
                  j                  j                  d      rd| _        nd | _        t        j                  j                  dd      j                         }i | _        |D ]W  }|dt        |       f}|| j                  dt        |       <   || j                  vs=| j                  j                  |       Y y )	Nlist-candidatezrecruitment.change_candidateoptionsr9   Tflat	question_rF   )rG   __init__export_fieldsr
   
search_urlrequestuserhas_permoption_methodr.   objectsvalues_listdistinctsurvey_question_mappingr;   append)rI   rB   unique_questionsr9   survey_questionrL   s        r:   rs   zListCandidates.__init__   s    "6"!"23<<%%&DE!*D!%D,44@@T A 

(* 	 (*$( 	;H'95Fx5P4Q)RSO ((95Fx5P4Q)RS #d&8&88""))/:	;r<   )
Candidatesr?   
get_avatar)EmailemailPhonemobile)RatingratingRecruitmentrecruitment_idJob PositionrX   )z
Hired DaterY   )Resume
resume_pdfzJ
                   style ="width : 230px !important;"
                   zJ
                   style ="width : 200px !important;"
                   )optionactionr   Editcreate-outlinezclass="oh-btn oh-btn--light-bkg w-100"
            onclick="event.stopPropagation()
            window.location.href='{get_update_url}' "
             r   iconrg   Archivez,recruitment.cbv.accessibility.archive_statusarchivez
                class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
                onclick="event.stopPropagation()
                archiveCandidate({get_archive_url});  "
            )r   accessibilityr   rg   z
Un-archivez.recruitment.cbv.accessibility.unarchive_statusDeletetrash-outlineaU  
                    class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
                    hx-get="{get_delete_url}?model=recruitment.candidate&pk={pk}"
                    data-toggle="oh-modal-toggle"
                    data-target="#deleteConfirmation"
                    hx-target="#deleteConfirmationBody"
                r   )zcanceled--dotCanceledz
            onclick="
                $('#applyFilter').closest('form').find('[name=canceled]').val('true');
                $('#applyFilter').click();
            "
            )znothired--dotz	Not Hiredz
            onclick="
                $('#applyFilter').closest('form').find('[name=hired]').val('false');
                $('#applyFilter').click();
            "
            )z
hired--dotHiredz
            onclick="$('#applyFilter').closest('form').find('[name=hired]').val('true');
                $('#applyFilter').click();
            "
            
   !hired-{hired} canceled-{canceled}z
                {is_employee_converted}
                onclick="window.location.href='{get_individual_url}?instance_ids={ordered_ids}'"
                c                 $	  #$% t        t        dd      }t        j                  |j                  d         }t        j                  |j                  d         #| j
                  j                  j                  |      }| j                  %|j                  j                  dd      }| j
                  $ G #$%fdd	t        j                        } |       }|j                  |      }	|d
k(  r[t        j                  |	j                  d
            }
t        t        j                   |
d      d      }d| j"                   d|d<   |S |dk(  r3|	j                  d      }t        |d      }d| j"                   d|d<   |S |dk(  r|	j$                  }|	j&                  }t)        d||d      }t+        j,                         }t/        j0                  ||      }|j2                  rt        dd      S t        |j5                         d      }d| j"                   d|d<   |S t        j                  |	j                  d
            }
|
rt7        |
d   j9                               ng }t;               }|j<                  }d|_        tA        d d d!"      }tC        d#$      }tE        tG        d%&      tG        d%&      tG        d%&      tG        d%&      '      }tI        d(d#)      }tK        |d*+      D ]A  \  }}|jM                  d*||,      }||_'        ||_(        ||_)        tI        d-d-d#.      |_*        C tK        |
d/+      D ]  \  }}tK        |d*+      D ]  \  }}|j                  |d0      }tW        |t6              rd1jY                  d2 |D              }n'tW        |t&              rt        j                   |d34      }|jM                  |||,      }||_)        ||_*          |jZ                  D ]M  }t]        d5 |D              } t_        |d   j`                        }!tc        | d6z   d7      |jd                  |!   _3        O t+        j,                         }"|ji                  |"       |"jk                  d       t        |"jm                         d8      }d9|d<   |S ):z8
        Export with survey answer and question
        rv   Nidscolumns)id__informatxlsxc                   N    e Zd ZdZ ej
                  d      Zi Z G fdd      Z fdZ	 fdZ
d ZW D ]_  Zed	   j                  d
      rded	    ded	    dZ ee        e       ded	       Z ej
                  ed          e       ed	   <   a d Z xZS ):ListCandidates.export_data.<locals>.HorillaListViewResorcez0
            Instant Resource class
            ID)column_namec                   P    e Zd ZdZW ZW D  cg c]  }|d   	 c}} Zyc c}} w )?ListCandidates.export_data.<locals>.HorillaListViewResorce.MetazB
                Meta class for additional option
                   N)rM   rN   rO   rP   modelr   ).0field_columns_models   00r:   Metar   /  s&     089u%(99s   "r   c                     t        |   di | D ]D  }|d   j                  d      s|d   }t        j                  |   |d      | j                  |<   F y )Nr   rr   T)r   	attributereadonlyrF   )rG   rs   
startswithr   Field)rI   rB   field_tuplesafe_field_namerL   r   question_mappings       r:   rs   zCListCandidates.export_data.<locals>.HorillaListViewResorce.__init__7  sb     *6*#+ K"1~00=*5a.7=||(8(I&5%)8O4r<   c                    |j                   rt        j                  j                  |      j	                         }|r|j                   j                  d      r|j                  }t        |t              r	 t        j                  |      }|j                      }|j                  |d      }|s|j                  d|z   d      }|s|j                  d|z   d      }|s|j                  d|z   d      }|s|j                  d|z   d      }|s|j                  d|z   d      }|S t        | 9  ||      S # t        $ r i }Y w xY w)	zd
                Override this method to fetch the candidate's answers dynamically.
                candidate_idrr   r3   rating_percentage_file_date_multiple_choices_)r   r/   rz   filterfirstr   answer_json
isinstancestrastliteral_eval	ExceptiongetrG   export_field)rI   r   objsurvey_answersoriginal_questionanswerrL   r   s         r:   r   zGListCandidates.export_data.<locals>.HorillaListViewResorce.export_fieldC  sa   
 ??%<%D%D%K%K%( &L &eg # &%//*D*D[*Q)7)C)C%nc:4141A1A$22" -=U__,M)!/!3!34Er!J%%3%7%7 ),= =r&F  &%3%7%7 -0A A2&F  &%3%7%7BS8SUW%XF%%3%7%7BS8SUW%XF%%3%7%7 36G G&F  &w+E3775 $- 4134s   7D2 2E ?E c                     |j                   S )z?
                Dehydrate method for id field
                )pk)rI   instances     r:   dehydrate_idzGListCandidates.export_data.<locals>.HorillaListViewResorce.dehydrate_idp  s      {{"r<   r   rr   zdef dehydrate_zI(self, instance):return self.remove_extra_spaces(getattribute(instance, 'z'))
dehydrate_r   c                 f   t        t        |      d      }|j                  d      D ]#  }|j                  d       |j	                          % |j                         }|j                         }|D cg c]#  }|j                         s|j                         % }}dj                  |      }|S c c}w )zj
                Remove blank space but keep line breaks and add new lines for <li> tags.
                zhtml.parserli
)	r   r   find_allinsert_beforeunwrapget_text
splitlinesstripjoin)rI   textsoupr   lineslinenon_blank_linescleaned_texts           r:   remove_extra_spaceszNListCandidates.export_data.<locals>.HorillaListViewResorce.remove_extra_spaces}  s     %SY>---  B$$T*IIK  }})<A"RDTZZ\4::<"R"R#yy9## #Ss   1B.B.)rM   rN   rO   rP   r   r   idr9   r   rs   r   r   r   r   dynamic_fn_strexeclocals
dynamic_fnr   rS   )rL   r   r   r   s   @r:   HorillaListViewResorcer   '  s     $/BH: :
+8Z#  ( X"1~00='5k!n5E  FO  P[  \]  P^  O_  _b  &cN(!'J{1~6F*G!HJ/;v||TU/WFH[^,X$r<   r   json   )indentzapplication/json)content_typezattachment; filename="z.json"zContent-Dispositioncsvztext/csvz.csv"pdfzgeneric/export_pdf.html)headersrows)destzPDF generation failedi  )statuszapplication/pdfz.pdf"r   zExported DataFFD700solid)start_color	end_color	fill_typeT)boldthin)rf   )leftrighttopbottomr  )vertical	wrap_textr   )start)rowcolumnvaluecenter)
horizontalr  r     r3   r   c              3   2   K   | ]  }t        |        y w)N)r   )r   vs     r:   	<genexpr>z-ListCandidates.export_data.<locals>.<genexpr>  s     %<c!f%<s   F)ensure_asciic              3   `   K   | ]&  }t        t        |j                  xs d              ( yw)r3   N)lenr   r	  )r   cells     r:   r  z-ListCandidates.export_data.<locals>.<genexpr>  s#     K#c$**"234Ks   ,.   2   zAapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetz)attachment; filename="exported_data.xlsx")7getattrr   r   r   POSTr   rz   r   r}   r   r   ModelResourceexportr   loadsr   dumpsexport_file_namer   rR   r	   ioBytesIOr   	CreatePDFerrgetvaluelistkeysr   activetitler   r   r   r   r   	enumerater  fillfontborder	alignmentr   r   r   maxr   r  mincolumn_dimensionswidthsaveseekread)&rI   argsrB   rv   r   querysetexport_formatr   book_resourcedataset	json_dataresponsecsv_datar   r   html_stringresultpisa_statuswbwsheader_fill	bold_fontthin_borderwrap_alignmentcol_idxheaderr  row_idxitemkeyr	  	col_cellsmax_len
col_letteroutputr   r   r   s&                                      @@@r:   export_datazListCandidates.export_data  sT   
 .)T:w||E23##GLL$;<::%%,,C,877((6:b	$ b	$Y%<%< b	$H /0  &&x0 F"

7>>&#9:I#

9Q/>PH ))>)>(?vF *+ O e#~~e,H#H:FH()>)>(?uE *+ Oe#ooG<<D +)& K ZZ\F..6BK#$;CHH $FOO$5DUVH()>)>(?uE *+ O JJw~~f56	/8$y|((*+bZYY" " H
 dO	F#V$6"f%	
 #ETB  ): 	OGV77q7?D#DI!DI%DK&#h$DN	 'y: 	0MGT )' ; 0b)eT* II%<e%<<Et, JJEE ww77%wH)!/0	0  	JIKKKG*9Q<+>+>?J581b5IB  ,2	J 
AKKM\
 +V&'r<   )rM   rN   rO   rP   r-   r   r)   filter_classbulk_templaterc   rl   r   rs   r   default_columnsheader_attrsr5   actionssortby_mappingrow_status_indicationsrecords_per_pagerow_status_class	row_attrsrL  rS   rT   s   @r:   rV   rV   W   s     E"L>MB; ; ;*	G O
L $	
  K			
 #M			
 k#
	
;(GV 	-N@ :I
jr<   rV   c                        e Zd ZdZeZeZdeddf fdZ	dddd	Z
d
dddddddddddddddddddddddddddd dd!d"dg	Zg d#Zd$Zd%Zd&Z xZS )'CardCandidatesz
    For card view
    rB   rC   Nc                 D    t        |   di | t        d      | _        y )Ncard-candidaterF   )rG   rs   r
   ru   rI   rB   rL   s     r:   rs   zCardCandidates.__init__  s     "6"!"23r<   r   z{get_full_name}z{email} <br> {get_job_position})	image_srcr%  subtitlezConvert to Employeez)recruitment.cbv.accessibility.convert_empz
                onclick="event.stopPropagation()
                return confirm('Are you sure you want to convert this candidate into an employee?')"
                href='{get_convert_to_emp}'
                class="oh-dropdown__link"

            )r   r   rg   zAdd to Skill Zonez,recruitment.cbv.accessibility.add_skill_zonez
                data-toggle="oh-modal-toggle"
                data-target="#genericModal"
                hx-get="{get_add_to_skill}"
                hx-target="#genericModalBody"
                class="oh-dropdown__link"

            zView candidate self trackingz;recruitment.cbv.accessibility.check_candidate_self_trackingzf
                href="{get_self_tracking_url}"
                class="oh-dropdown__link"
            zRequest Documentz.recruitment.cbv.accessibility.request_documentz
                data-toggle="oh-modal-toggle"
                data-target="#genericModal"
                hx-get="{get_document_request_doc}"
                hx-target="#genericModalBody"
                class="oh-dropdown__link"
            zAdd to Rejectedz(recruitment.cbv.accessibility.add_rejecta  
                hx-target="#genericModalBody"
                hx-swap="innerHTML"
                data-toggle="oh-modal-toggle"
                data-target="#genericModal"
                hx-get="{get_add_to_reject}"
                class="oh-dropdown__link"

            zEdit Rejected Candidatez)recruitment.cbv.accessibility.edit_rejectzEdit Profilez
                onclick="event.stopPropagation()
                window.location.href='{get_update_url}' "
                class="oh-dropdown__link"

            r   rg   archive_statuszx
                class="oh-dropdown__link"
                onclick="archiveCandidate({get_archive_url});"


            r   z
                class="oh-dropdown__link oh-dropdown__link--danger"
                onclick="event.stopPropagation();
                deleteCandidate('{get_delete_url}'); "

            r   r   zr
                onclick="window.location.href='{get_individual_url}?instance_ids={ordered_ids}'"
                   )rM   rN   rO   rP   r-   r   r)   rM  r   rs   detailsrQ  card_status_indicationscard_status_class
card_attrsrT  rS   rT   s   @r:   rX  rX    s     E"L4 4 4
 ""5G ,H
	
 *K	
 5Z	
 )M
	
 (G	
 0H	
 %	
 '	
 	
o`GB> <J r<   rX  c                   R     e Zd ZdZdeddf fdZdZdZ e       Z	dZ
d	Zg d
Z xZS )CandidateNavz
    For nav bar
    rB   rC   Nc                 B   t        |   d i | t        d      | _        dt	        d       d| _        ddt        d       dd	d
dt        d       dd	ddt        d       dd	ddd	ddd	ddd	g| _        ddt        d      ddddt        d      ddg| _        y )!Nrn   z#
                            href='zcandidate-createz'"
                            Exportzv
                 data-toggle="oh-modal-toggle"
                 data-target="#genericModal"
                 hx-get="r  zB"
                 hx-target="#genericModalBody"
                 r^  z	Bulk mailzs
                data-toggle="oh-modal-toggle"
                data-target="#genericModal"
                hx-get="z	send-mailz@"
                hx-target="#genericModalBody"
                zCreate document requestzx
                data-toggle="oh-modal-toggle"
                data-target="#objectCreateModal"
                hx-get="zcandidate-document-requestzG"
                hx-target="#objectCreateModalTarget"
                r   z9
                id="archiveCandidates"

                z
Un archivez;
                id="unArchiveCandidates"

                r   zx
                data-action = "delete"
                id="deleteCandidates"
                 new_init
                r"  zlist-outlinezF
                            title='List'
                            )typer   urlrg   cardzgrid-outlinerZ  zF
                            title='Card'
                            rF   )rG   rs   r
   ru   r   create_attrsrQ  
view_typesr[  s     r:   rs   zCandidateNav.__init__  s,   "6"!"23!##/0B#C"D E 
 # "(+, - & !-. / 4 !!=>? @ $ ' #U2
l &/0 	 &/0 	
r<   r   zcbv/candidates/filter.htmlrk   z#listContainer)
)r   r   )rX   r   )hiredr   )r[   Country)stage_idStage)r_   zDate joining)r`   zProbation End)offer_letter_statuszoffer Letter Status)$rejected_candidate__reject_reason_idzReject reason)skillzonecandidate_setz
Skill zone)rM   rN   rO   rP   r   rs   	nav_titlefilter_body_templater)   filter_instancefilter_form_context_namesearch_swap_targetgroup_by_fieldsrS   rT   s   @r:   rf  rf    sG    K
 K
 K
Z I7%'O%)Or<   rf  c                   ,     e Zd ZdZdZdef fdZ xZS )
ExportViewz
    For candidate export
    zcbv/candidates/export.htmlrB   c                     t        |   di |}t        j                  j	                  d      }t               }t        |      }||d<   ||d<   |S )zF
        Adds export fields and filter object to the context.
        T)	is_active)r3  export_columnexport_filterrF   )rG   rH   r-   rz   r   r*   r)   )rI   rB   rJ   
candidatesr  r  rL   s         r:   rH   zExportView.get_context_data  s[     '*4V4&&---=
+-'<#0 #0 r<   )rM   rN   rO   rP   rQ   r   rH   rS   rT   s   @r:   r|  r|  	  s      1M
 
 
r<   r|  c                        e Zd ZdZdZd Zd Zy)AddToRejectedCandidatesViewz+
    Class for Add to reject candidate
    zonboarding/rejection/form.htmlc                     |j                   j                  d      }d}|r.t        j                  j	                  |      j                         }t        d|i|      }t        || j                  d|i      S )z
        get method
        r   Nr   )initialr   rk   )	GETr   r0   rz   r   r   r+   r   rQ   rI   rv   r   r   rk   s        r:   r   zAddToRejectedCandidatesView.get(  sw     {{~6(0077) 8 eg  %#\2X
 gt11FD>BBr<   c                 ~   |j                   j                  d      }d}|r.t        j                  j	                  |      j                         }t        |j                  |      }|j                         r1|j                          t        j                  |d       t        d      S t        || j                  d|i      S )z
        post method
        r   Nr   )r   Candidate reject reason savedz)<script>window.location.reload()</script>rk   )r  r   r0   rz   r   r   r+   r  is_validr/  r   successr   r   rQ   r  s        r:   postz AddToRejectedCandidatesView.post7  s     {{~6(0077) 8 eg  %W\\HE==?IIKW&EF KLLgt11FD>BBr<   N)rM   rN   rO   rP   rQ   r   r  rF   r<   r:   r  r    s     5MCCr<   r  c                   F     e Zd ZdZdZeZddddZg dZdd	iZ	 fd
Z
 xZS )CandidateDetailz
    Candidate detail
    zCandidate Detailsget_full_name	get_emailr   )r%  r]  avatar))GenderrW   r   )rq  stage_drop_down)r   
rating_barr   r   )zInterview Tablecandidate_interview_viewTr     c           	          t        |   di | ddddddddg| _        | j                  j                  j                  d      r.| j                  j                  d	d
ddt        d       dd       y y )Nr   r   zy
            class="oh-btn oh-btn--info w-50"
            onclick="window.location.href='{get_update_url}' "
            r   r   zeye-outlinez
            class="oh-btn oh-btn--success w-50"
            onclick="window.location.href='{get_individual_url}'"
            zrecruitment.delete_candidater   r   z&recruitment.cbv.candidates.delete_candzD
            class="oh-btn oh-btn--danger w-50"
            hx-get="zgeneric-deletea  ?model=recruitment.Candidate&pk={pk}"
            hx-target="#deleteConfirmationBody"
            data-toggle="oh-modal-toggle"
            data-target="#deleteConfirmation"
            onclick="event.stopPropagation()
            deleteCandidate('{get_delete_url}'); "
            )r   r   r   rg   rF   )rG   rs   rQ  rv   rw   rx   r~   r   r[  s     r:   rs   zCandidateDetail.__init__f  s    "6" !( !%
& <<%%&DELL&+%M"!"234 5	 Fr<   )rM   rN   rO   rP   r%  r-   r   rD  bodycolsrs   rS   rT   s   @r:   r  r  I  s?    
  EE&K<XFD 	#BD% %r<   r  c                   V     e Zd ZdZeZeZdZ fdZ	de
def fdZdedef fdZ xZS )ToSkillZoneFormView
    Form View
    zAdd To Skill Zonec                 .   t        |   d
i |}| j                  j                  d      }t        j
                  j                  |      }| j                  |t        j
                  j                  |      j                  dd      d      }||d	<   |S )z?
        Returns context with form and candidate data.
        cand_idr   r   skill_zone_idTrp   r   skill_zone_idsr  rk   rF   )
rG   rH   rB   r   r-   rz   
form_classr1   r   r{   )rI   rB   rJ   r   	candidaterk   rL   s         r:   rH   z$ToSkillZoneFormView.get_context_data  s     '*4V4{{y1%%))\):	 )"4"<"<"C"C!* #D #+oD+9	  
 r<   rk   rC   c                    | j                  | j                  j                        }|j                         s>|j                  j                         }t        | j                  | j                  ||d      S t        | %  |      S )zJ
        Handles and renders form errors or defers to superclass.
        )rk   errors)
r  rv   r  r  r  as_datar   rQ   rG   form_invalid)rI   rk   r  rL   s      r:   r  z ToSkillZoneFormView.form_invalid  sm     t||001}}[[((*Fd00462R  w#D))r<   c                    |j                         rP| j                  j                  d      }t        j                  j                  |      }| j                  |t        j                  j                  |      j                  dd      d       | j                  j                  d	   }|D ]x  }t        j                  j                  ||
      j                         r3t               }||_        ||_        | j                  j                  d   |_        |j                          z d}t!        j"                  | j$                  t'        |             | j)                         S t*        | Y  |      S )T
        Handles valid form submission and saves rejected candidate reason.
        r  r  r   r  Trp   r  r  r  )r   r  reasonz*Candidate Added to skill zone successfully)r  rB   r   r-   rz   r  r1   r   r{   rk   cleaned_dataexistsr   r  r  r/  r   r  rv   r5   r   rG   
form_valid)	rI   rk   r   r  skill_zoneszonezone_candidatemessagerL   s	           r:   r  zToSkillZoneFormView.form_valid  sI    ==?;;??95L!))--->IOO$-&8&@&@&G&G%. 'H '!k/k=	   ))001ABK# *)1188!-T 9 &( &8%9N2;N/37N0,0II,B,B8,LN)"'')* CGT\\1W:6$$&&w!$''r<   )rM   rN   rO   rP   r1   r   r,   r  new_display_titlerH   r   r   r  r  rS   rT   s   @r:   r  r    sJ     E J+$
* 
* 
*( (< ( (r<   r  c                   f     e Zd ZdZeZeZdZde	fgZ
def fdZi i dd fd
Zd	edef fd
Z xZS )RejectReasonFormViewr  zRejected Candidatereject_reason_idrC   c                 t    t         |          }| j                  j                  j	                  d      |d<   |S )Nr   )rG   get_initialrv   r  r   )rI   r  rL   s     r:   r  z RejectReasonFormView.get_initial  s4    '%'"&,,"2"2"6"6~"Fr<   Ndatafilesr   c                    | j                   j                  j                  d      }t        j                  j                  |      j                         }t        |    ||||d|S )Nr   r   r  )	rv   r  r   r0   rz   r   r   rG   	init_form)rI   r  r  r   r2  rB   r   rL   s          r:   r  zRejectReasonFormView.init_form  sb    ||''++N;$,,333NTTVw EH
@F
 	
r<   rk   c                     |j                         rTt        d      }t        j                  | j                  t        |             |j                          | j                         S t        | !  |      S )r  r  )	r  r5   r   r  rv   r/  r   rG   r  )rI   rk   r  rL   s      r:   r  zRejectReasonFormView.form_valid  sY     ==?78GT\\1W:6IIK$$&&w!$''r<   )rM   rN   rO   rP   r0   r   r+   r  r  r&   dynamic_create_fieldsrR   r  r  r   r  rS   rT   s   @r:   r  r    s\     E&J,02MNOT 
 %'b4 
	(4 	( 	( 	(r<   r  )[rP   r   r  r   r6   typingr   bs4r   djangor   django.contribr   django.httpr   django.shortcutsr   django.template.loaderr	   django.urlsr
   r   django.utils.decoratorsr   django.utils.translationr   r5   django.viewsr   import_exportr   r   openpyxlr   openpyxl.stylesr   r   r   r   r   openpyxl.utilsr   	xhtml2pdfr   employee.formsr   horilla.horilla_middlewaresr   horilla_views.cbv_methodsr   r   r   horilla_views.formsr   horilla_views.generic.cbv.viewsr   r    r!   r"   r#   r$   3horilla_views.templatetags.generic_template_filtersr%   'recruitment.cbv.candidate_reject_reasonr&   recruitment.cbv_decoratorsr'   r(   recruitment.filtersr)   recruitment.formsr*   r+   r,   recruitment.modelsr-   r.   r/   r0   r1   _getattributer;   rA   rV   rX  rf  r|  r  r  r  r  rF   r<   r:   <module>r     sS    	  	    # $ # 3 - 4 6  +  F F ,  . 6 V V 5  M O O / 
  > 9: .z2\  3 .z2#)EFZXj_ j Y 3jZ .z2#)EFZXW_ W Y 3Wt .z2#)EFZXb> b Y 3bJ .z2#)EFZX  Y 3( .z2#)EFZX%C$ %C Y 3%CP .z2;<:>) > 3>BC(/ C(L(? (r<   