o
    >h]                     @   s  d dl 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 d dlmZ d dlmZmZ d dl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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G dd dejZeeedddZ 	 G dd dejZ!	 G dd dejZ"G dd  d ejZ#eee	e#dd!dZ$G d"d# d#ejZ%eee
e%dd!dZ&G d$d% d%ejZ'eeee'dd!dZ(G d&d' d'ejZ)eeee)dd!dZ*G d(d) d)ejZ+eeee+dd!dZ,d*S )+    )forms)CompanyUserClient	CountriesClientFrequentFlyerAirlinesClientPassportAssocClientCompanyClientDocument
ClientVisaClientTravelInsurance)AuthenticationForm)modelformset_factoryinlineformset_factory)authenticatec                   @      e Zd ZG dd dZdS )UserFormc                   @   sf   e Zd ZeZg dZejdddddejdddddejdddddejddddddZ	d	S )
zUserForm.Meta)usernameemail
contact_nodesignationform-controlT2   )classrequired	maxlengthattrsd      N)
__name__
__module____qualname__r   modelfieldsr   	TextInput
EmailInputwidgets r)   r)   I/var/www/html/myvaluetrips/my_value_trip_new/my_value_trip/users/forms.pyMeta   s    
r+   Nr!   r"   r#   r+   r)   r)   r)   r*   r          r   c                   @   s   e Zd Ze ZdS )ForgotPasswordFormN)r!   r"   r#   r   
EmailFieldr   r)   r)   r)   r*   r.      s    r.   c                       s8   e Zd ZejejdZejejdZ fddZ  Z	S )ResetPasswordFormwidgetc                    s4   t   }|d}|d}||krtd|S )Nnew_passwordconfirm_passwordzPasswords do not match.supercleangetr   ValidationError)selfcleaned_datap1p2	__class__r)   r*   r7      s   



zResetPasswordForm.clean)
r!   r"   r#   r   	CharFieldPasswordInputr3   r4   r7   __classcell__r)   r)   r>   r*   r0      s    r0   c                       sV   e Zd ZejdejdddddZejdejddd	d
ddZ	 fddZ
  ZS )CustomLoginFormEmailr   zEnter your emailr   placeholderr   )labelr2   PasswordzEnter your passwordid_password)r   rF   idc                    sL   t   }|d}|d}|r$|r$t||d}|s td||d< |S )Nr   password)r   rK   zInvalid email or password.user)r6   r7   r8   r   r   r9   )r:   r;   r   rK   rL   r>   r)   r*   r7   E   s   



zCustomLoginForm.clean)r!   r"   r#   r   r/   r'   r   r@   rA   rK   r7   rB   r)   r)   r>   r*   rC   :   s    

rC   c                   @   s*   e Zd ZejddejdddddZdS )	OTPVerificationFormOTP   r   z	Enter OTPrE   r   )rG   
max_lengthr2   N)r!   r"   r#   r   r@   r&   otpr)   r)   r)   r*   rM   R   s
    rM   c                       sh   e Zd ZejejddiddZejejddiddZG dd dZ fddZ	d fd
d	Z
  ZS )RegisterFormr   r   r   r1   c                   @   s   e Zd ZeZddgZdS )zRegisterForm.Metar   r   Nr!   r"   r#   r   r$   r%   r)   r)   r)   r*   r+   \       r+   c                    s,   t   }|d|dkrtd|S )N	password1	password2zPasswords do not matchr5   )r:   r;   r>   r)   r*   r7   `   s   

zRegisterForm.cleanTc                    s.   t  jdd}|| jd  |r|  |S )NFcommitrU   )r6   saveset_passwordr;   )r:   rX   rL   r>   r)   r*   rY   f   s
   zRegisterForm.saveT)r!   r"   r#   r   r@   rA   rU   rV   r+   r7   rY   rB   r)   r)   r>   r*   rR   X   s    rR   c                   @   r   )UserCreateFormc                   @      e Zd ZeZg dZdS )zUserCreateForm.Meta)r   r   r   r   rK   NrS   r)   r)   r)   r*   r+   o   rT   r+   Nr,   r)   r)   r)   r*   r\   n   r-   r\   c                       s2   e Zd ZG dd dZ fddZdd Z  ZS )UserUpdateFormc                   @   r]   )zUserUpdateForm.Meta)r   r   r   r   	is_activeNrS   r)   r)   r)   r*   r+      rT   r+   c                    s0   t  j|i | | jr| jj| _d S d | _d S N)r6   __init__instancepkinstance_idr:   argskwargsr>   r)   r*   ra      s   zUserUpdateForm.__init__c                 C   sD   | j d}|s
|S tjj|dj| jjd}| r t	
d|S )Nr   r   )rc   z$User with this Email already exists.)r;   r8   r   objectsfilterexcluderb   rc   existsr   r9   )r:   r   qsr)   r)   r*   clean_email   s   
zUserUpdateForm.clean_email)r!   r"   r#   r+   ra   rn   rB   r)   r)   r>   r*   r^      s    r^   c                   @   r   )CompanyFormc                   @   s   e Zd ZeZdZdS )zCompanyForm.Meta__all__N)r!   r"   r#   r   r$   r%   r)   r)   r)   r*   r+      s    r+   Nr,   r)   r)   r)   r*   ro      r-   ro      F)formextra
can_deletec                       sV   e Zd Zejej dejddidddZ	G dd dZ
 fd	d
Zdd Z  ZS )
ClientFormzCountry Coder   r   r   rJ   )querysetrG   r2   to_field_namec                	   @   s  e Zd ZeZdZddgZi dejddddd	ejddddd
ej	dddddej	dddddejddiddej
ddiddej
ddiddej
ddiddej
ddiddej
ddiddej
ddiddej
ddiddej
ddiddej
ddiddej
ddiddej
ddiddej
ddidej
ddidej
ddidej
ddidej
ddidej
ddidej
ddiddZdS )zClientForm.Metarp   
created_by
updated_bydobdater   )typer   r   anniversary_date
created_atzdatetime-local
updated_atpassport_expiry_dater|   client_salutationr   form-selectcompanycountry_codegendermarital_statusreference_frompreferred_contact_methodresidential_cityresidential_stateresidential_countryref_preferred_airline_idseat_preference)meal_preferencefare_preferencestar_ratingstay_preferenceroom_preferenceref_frequent_airlineN)r!   r"   r#   r   r$   r%   rk   r   	DateInputDateTimeInputSelectr(   r)   r)   r)   r*   r+      s\    	
r+   c                    s   t  j|i | d| jv r tjd| jd _dd | jd _d| jv r7tjd| jd _dd | jd _d| jv rDdd | jd _d	| jv rW| jd	 jj	
d
di d S d S )Nrx   r   c                 S      | j S r`   rh   objr)   r)   r*   <lambda>      z%ClientForm.__init__.<locals>.<lambda>ry   c                 S   r   r`   rh   r   r)   r)   r*   r     r   r   c                 S   s   d| j  d| j dS )N+z ())r   namer   r)   r)   r*   r     s    r_   r   form-check-input)r6   ra   r%   r   ri   order_byrv   label_from_instancer2   r   updatere   r>   r)   r*   ra      s   




zClientForm.__init__c                 C   s   | j d}| j d}|rB|jpd}|jpd}|r-t||k r-td| d|j d|rBt||krBtd| d|j d|S )Ncontact_numberr   r   z Contact number must be at least z digits for .zContact number cannot exceed )r;   r8   
min_lengthrP   lenr   r9   r   )r:   r   countrymin_lenmax_lenr)   r)   r*   clean_contact_number  s   

zClientForm.clean_contact_number)r!   r"   r#   r   ModelChoiceFieldr   ri   allr   r   r+   ra   r   rB   r)   r)   r>   r*   ru      s    ru   c                       s,   e Zd ZG dd dZd fdd	Z  ZS )FrequentFlyerFormc                   @   sD   e Zd ZeZg dZejddidejddiddZ	dddZ
d	S )
zFrequentFlyerForm.Meta)ref_airlineff_no
ref_clientr   r   r   r   )r   r   r   zFF No.N)r!   r"   r#   r   r$   r%   r   r   r&   r(   labelsr)   r)   r)   r*   r+     s    
r+   Tc                    s8   t  jdd}d| jv r| jd }nd }|r|  |S )NFrW   airline)r6   rY   r;   )r:   rX   rb   r   r>   r)   r*   rY     s   
zFrequentFlyerForm.saver[   )r!   r"   r#   r+   rY   rB   r)   r)   r>   r*   r     s    r   c                   @   r   )ClientPassportFormc                   @   sR   e Zd ZeZg dZejdddddejddd	d
dej	dddddZ
dS )zClientPassportForm.Meta)passport_filepassport_nor   r   z%form-control alpha_numeric valid_pspt10z&this.value = this.value.toUpperCase();)r   r   onkeyupr   r{   form-control datetimepicker,{"dateFormat":"d/m/Y", "disableMobile":true})r|   r   data-optionsr   .image/jpg,image/jpeg,image/png,application/pdfr   accept)r   r   r   N)r!   r"   r#   r	   r$   r%   r   r&   r   	FileInputr(   r)   r)   r)   r*   r+     s$    
r+   Nr,   r)   r)   r)   r*   r     r-   r   Tc                   @   r   )AssocClientCompanyFormc                   @   sP   e Zd ZeZg dZejddidejddddej	ddide
 dZd	S )
zAssocClientCompanyForm.Meta)ref_companyr   primary_companyr   r   zform-control select2r   zform-control alpha_numeric50)r   r   r   N)r!   r"   r#   r
   r$   r%   r   r   r&   CheckboxInputHiddenInputr(   r)   r)   r)   r*   r+     s    
r+   Nr,   r)   r)   r)   r*   r     r-   r   c                   @   r   )OtherDocumentFormc                   @   s>   e Zd ZeZg dZejddddejddddd	Z	d
S )zOtherDocumentForm.Meta)other_documentother_document_namer   zform-select select2z-- Select Document Type --)r   zdata-placeholderr   r   r   r   )document_typedocument_fileN)
r!   r"   r#   r   r$   r%   r   r   r   r(   r)   r)   r)   r*   r+     s    
r+   Nr,   r)   r)   r)   r*   r     r-   r   c                   @   r   )ClientVisaFormc                	   @   sn   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ddej	dd	d
ddej	dd	d
dddZ
dS )zClientVisaForm.Meta)ref_visa_country	visa_typepassport_size_photographvisa_from_datevisa_to_dater   r   r   r   r   r   r   r{   r   r   r|   r   N)r!   r"   r#   r   r$   r%   r   r   ClearableFileInputr   r(   r)   r)   r)   r*   r+     s(    	
r+   Nr,   r)   r)   r)   r*   r     r-   r   c                   @   r   )ClientTravelInsuranceFormc                   @   sR   e Zd ZeZg dZejddddejdddd	dejdddd	dd
Z	dS )zClientTravelInsuranceForm.Meta)insurance_documentinsurance_from_dateinsurance_to_dater   r   r   r   r   r   r{   r   r   )r   r   r   N)
r!   r"   r#   r   r$   r%   r   r   r   r(   r)   r)   r)   r*   r+   .  s$    
r+   Nr,   r)   r)   r)   r*   r   -  r-   r   N)-djangor   users.modelsr   r   r   r   r   r   r	   r
   r   r   r   django.contrib.auth.formsr   django.formsr   r   django.contrib.authr   	ModelFormr   Formr.   r0   rC   rM   rR   r\   r^   ro   CompanyFormSetru   r   r   PassportFormSetr   AssocClientCompanyFormSetr   OtherDocumentFormSetr   VisaFormSetr   TravelInsuranceFormSetr)   r)   r)   r*   <module>   s    4&On			
