o
    h$                     @   s   d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	m
Z
mZ ddlmZmZ G dd dejZG d	d
 d
ejZG dd dejZG dd dejZdS )    )forms)timezone)
FormHelper)LayoutRowColumnSubmitHTML   )
JobPostingApplicationc                       s6   e Zd ZdZG dd dZ fddZdd Z  ZS )JobPostingFormz*Form for creating and editing job postingsc                   @   sH   e Zd ZeZg dZejddidejddidejddiddZ	dS )	zJobPostingForm.Meta)	titledescriptionrequirementslocationsalary_rangeemployment_typeexperience_levelapplication_deadlinestatusrows   attrstypezdatetime-local)r   r   r   N)
__name__
__module____qualname__r   modelfieldsr   TextareaDateTimeInputwidgets r$   r$   &/var/www/html/ictaz-jobs/jobs/forms.pyMeta   s    
r&   c                    s~   t  j|i | t | _tdttdddtdddddttdddtd	ddtd
dddddddtdddd| j_d S )Nr   r   form-group col-md-6 mb-0	css_classr   form-rowr   form-group col-md-4 mb-0r   r   r   r   r   submitzSave Job Postingbtn btn-primary)	super__init__r   helperr   r   r   r   layoutselfargskwargs	__class__r$   r%   r/      s(   




zJobPostingForm.__init__c                 C   s$   | j d }|t krtd|S )Nr   z+Application deadline must be in the future.)cleaned_datar   nowr   ValidationError)r3   deadliner$   r$   r%   clean_application_deadline.   s   

z)JobPostingForm.clean_application_deadline)r   r   r   __doc__r&   r/   r<   __classcell__r$   r$   r6   r%   r      s
    r   c                       s^   e Zd ZdZG dd dZ fddZdd Zdd	 Zd
d Zdd Z	dd Z
dd Z  ZS )ApplicationFormz3Form for job applications (requires authentication)c                   @   sR   e Zd ZeZg dZddiZejddddej	dd	idej
dd	idd
ZdS )zApplicationForm.Meta)applicant_nameapplicant_emailapplicant_phonemembership_numbercover_letterresumeictaz_certificateadditional_documentsrF   zICTAZ Certificate   z8Tell us why you are the perfect fit for this position...)r   placeholderr   readonlyT)rD   r@   rA   N)r   r   r   r   r   r    labelsr   r!   	TextInput
EmailInputr#   r$   r$   r$   r%   r&   8   s    
r&   c                    s8  | dd | _| dd | _t j|i | | jrC| j | jd _| jj| jd _| jj	r7| jj	| jd _| jj
rC| jj
| jd _d| jd _d| jd _d	| jd _t | _ttd
ttdddtdddddttdddtddddddttdddtdddtdddddtdtdddd| j_d S )Njobuserr@   rA   rC   rB   z5Phone number must start with 260 (e.g., 260971234567)Tz(Your ICTAZ membership number is requiredz<div class="alert alert-info"><i class="fas fa-info-circle"></i> All fields marked with * are required. Name and email are auto-filled from your profile.</div>r'   r(   r*   rD   rE   r+   rF   rG   z<div class="alert alert-warning mt-3"><i class="fas fa-exclamation-triangle"></i> Please ensure all uploaded files are in PDF format and do not exceed 10MB each. Additional documents should include NRC, Degree Results, etc. as a single PDF.</div>r,   zSubmit Applicationzbtn btn-primary btn-lg)poprN   rO   r.   r/   get_full_namer    initialemailrC   phone_number	help_textrequiredr   r0   r   r	   r   r   r   r1   r2   r6   r$   r%   r/   G   sH   






zApplicationForm.__init__c                 C   s4   | j d }| jrtjj| j|d rtd|S )NrA   )rN   rA   zCYou have already applied for this position with this email address.)r8   rN   r   objectsfilterexistsr   r:   )r3   rS   r$   r$   r%   clean_applicant_emailr   s   

z%ApplicationForm.clean_applicant_emailc                 C   s8   | j d }|dstdt|dk rtd|S )NrB   260z7Phone number must start with 260 (Zambia country code).   z?Please enter a valid Zambian phone number (e.g., 260971234567).)r8   
startswithr   r:   len)r3   phoner$   r$   r%   clean_applicant_phonex   s   



z%ApplicationForm.clean_applicant_phonec                 C   s   | j d}|std|S )NrC   z$ICTAZ membership number is required.)r8   getr   r:   )r3   
membershipr$   r$   r%   clean_membership_number   s   
z'ApplicationForm.clean_membership_numberc                 C   B   | j d}|r|jdkrtd|j dstd|S )NrE      z$Resume file size cannot exceed 10MB..pdfzResume must be in PDF format.r8   ra   sizer   r:   namelowerendswith)r3   rE   r$   r$   r%   clean_resume      


zApplicationForm.clean_resumec                 C   rd   )NrF   re   z/ICTAZ certificate file size cannot exceed 10MB.rf   z(ICTAZ certificate must be in PDF format.rg   )r3   certr$   r$   r%   clean_ictaz_certificate   rm   z'ApplicationForm.clean_ictaz_certificatec                 C   rd   )NrG   re   z2Additional documents file size cannot exceed 10MB.rf   z+Additional documents must be in PDF format.rg   )r3   docsr$   r$   r%   clean_additional_documents   rm   z*ApplicationForm.clean_additional_documents)r   r   r   r=   r&   r/   rZ   r`   rc   rl   ro   rq   r>   r$   r$   r6   r%   r?   5   s    +		r?   c                       s.   e Zd ZdZG dd dZ fddZ  ZS )ApplicationNotesFormz;Form for updating application notes (Admin/Stakeholder use)c                   @   s*   e Zd ZeZdgZdejddidiZdS )zApplicationNotesForm.Metaadmin_notesr      r   N)	r   r   r   r   r   r    r   r!   r#   r$   r$   r$   r%   r&      s
    r&   c                    s6   t  j|i | t | _tdtdddd| j_d S )Nrs   r,   zUpdate Notesr-   r(   )r.   r/   r   r0   r   r   r1   r2   r6   r$   r%   r/      s   zApplicationNotesForm.__init__)r   r   r   r=   r&   r/   r>   r$   r$   r6   r%   rr      s    rr   c                       s   e Zd ZdZdgejdj Zdgejdj Z	e
jdde
jdd	id
dZe
jeddZe
je	ddZe
jdde
jddid
dZ fddZ  ZS )JobSearchFormz-Form for searching and filtering job postings) z	All Typesr   )rv   z
All Levelsr      FrI   z1Search jobs by title, description, or location...r   )
max_lengthrV   widget)choicesrV   Locationc                    st   t  j|i | t | _d| j_tttdddtdddtdddtdddttd	d
dddddd| j_	d S )Nra   searchr+   r(   r   zform-group col-md-2 mb-0r   r   r,   Searchr-   r*   )
r.   r/   r   r0   form_methodr   r   r   r   r1   r2   r6   r$   r%   r/      s   



zJobSearchForm.__init__)r   r   r   r=   r   _meta	get_fieldrz   EMPLOYMENT_TYPE_CHOICESEXPERIENCE_LEVEL_CHOICESr   	CharFieldrL   r|   ChoiceFieldr   r   r   r/   r>   r$   r$   r6   r%   ru      s.    ru   N)djangor   django.utilsr   crispy_forms.helperr   crispy_forms.layoutr   r   r   r   r	   modelsr   r   	ModelFormr   r?   rr   Formru   r$   r$   r$   r%   <module>   s    -m