U
    h}                     @   s   d 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mZmZmZ G dd	 d	ejZG d
d de
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 )z
Django Forms for Account Management

This module contains all forms used in the accounts app for user management,
profile updates, authentication, and role assignments.
    N)forms)ValidationError)gettext_lazy)PasswordChangeForm)UserProfileRoleUserRolec                       st   e Zd ZdZejdejdddddZejdejdddddZG d	d
 d
Z	 fddZ
d fdd	Z  ZS )ProfileUpdateFormz+Form for updating user profile information.   form-controlz
First Nameclassplaceholderattrs)
max_lengthwidgetz	Last Namec                   @   s   e Zd ZeZddddddddd	d
g
Zejddddejddddejdddddej	ddddej
ddidej
ddidej
ddidejddddejddidejddidejddiddZdS )zProfileUpdateForm.Meta	job_titlebiowebsitetimezonelanguagethemeavatarnotifications_enabledemail_notificationssms_notificationsr   zPhone Numberr   r   z	Job Title   i  )r   rows	maxlengthzWebsite URLr   form-selectzimage/*)r   acceptform-check-input)phone_numberr   r   r   r   r   r   r   r   r   r   N)__name__
__module____qualname__r   modelfieldsr   	TextInputTextareaURLInputSelect	FileInputCheckboxInputwidgets r1   r1   ./var/www/html/Focus/src/apps/accounts/forms.pyMeta&   s0          r3   c              
      s   | dd | _t j|| d| jd _dd tjD | jd _ddd	d
ddddddg
| jd _dddg| jd _| jr| jj	| jd _
| jj| jd _
d S )NuserFr$   c                 S   s   g | ]}||fqS r1   r1   ).0tzr1   r1   r2   
<listcomp>B   s     z.ProfileUpdateForm.__init__.<locals>.<listcomp>r   )enEnglish)esSpanish)frFrench)deGerman)itItalian)pt
Portuguese)ruRussian)jaJapanese)koKorean)zhChineser   )lightZLight)darkZDark)autoZAutor   
first_name	last_name)popr4   super__init__r)   requiredpytzcommon_timezoneschoicesrO   initialrP   selfargskwargs	__class__r1   r2   rS   ;   s,    zProfileUpdateForm.__init__Tc                    sV   t  jdd}| jrF| jdd| j_| jdd| j_|rF| j  |rR|  |S )NFcommitrO    rP   )rR   saver4   cleaned_datagetrO   rP   )rZ   r`   instancer]   r1   r2   rb   _   s    
zProfileUpdateForm.save)T)r%   r&   r'   __doc__r   	CharFieldr*   rO   rP   r3   rS   rb   __classcell__r1   r1   r]   r2   r
      s$   $r
   c                   @   s^   e Zd ZdZejejdddddZejejdddddZejejdddddZ	d	S )
CustomPasswordChangeFormz3Custom password change form with Bootstrap styling.r   zCurrent Passwordr   r   )r   zNew PasswordzConfirm New PasswordN)
r%   r&   r'   rf   r   rg   PasswordInputold_passwordnew_password1new_password2r1   r1   r1   r2   ri   o   s&   ri   c                       sl   e Zd ZdZejdejddiddZejdejddiddZG dd	 d	Z	d
d Z
d fdd	Z  ZS )UserCreateFormzForm for creating new users.Passwordr   r   r   )labelr   zConfirm Passwordc                   @   sz   e Zd ZeZddddddgZ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UserCreateForm.MetaemailusernamerO   rP   	is_activeis_staffr   r   r   r#   rq   rr   rO   rP   rs   rt   Nr%   r&   r'   r   r(   r)   r   
EmailInputr*   r/   r0   r1   r1   r1   r2   r3      s   r3   c                 C   s4   | j d}| j d}|r0|r0||kr0td|S )N	password1	password2zPasswords don't match)rc   rd   r   )rZ   rx   ry   r1   r1   r2   clean_password2   s
    zUserCreateForm.clean_password2Tc                    s.   t  jdd}|| jd  |r*|  |S )NFr_   rx   )rR   rb   set_passwordrc   )rZ   r`   r4   r]   r1   r2   rb      s
    zUserCreateForm.save)T)r%   r&   r'   rf   r   rg   rj   rx   ry   r3   rz   rb   rh   r1   r1   r]   r2   rn      s   rn   c                   @   s   e Zd ZdZG dd dZdS )UserUpdateFormz#Form for updating user information.c                   @   sz   e Zd ZeZddddddgZ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UserUpdateForm.Metarq   rr   rO   rP   rs   rt   r   r   r   r#   ru   Nrv   r1   r1   r1   r2   r3      s   r3   Nr%   r&   r'   rf   r3   r1   r1   r1   r2   r|      s   r|   c                       s.   e Zd ZdZG dd dZ fddZ  ZS )RoleAssignmentFormz"Form for assigning roles to users.c                   @   s`   e Zd ZeZddddgZejddidejdd	d
dejdd	d
dej	dddddZ
dS )zRoleAssignmentForm.Metarole
valid_fromvalid_untilnotesr   r!   r   r   zdatetime-local)r   typer   r   r   )r   r   r   r   N)r%   r&   r'   r	   r(   r)   r   r-   DateTimeInputr+   r0   r1   r1   r1   r2   r3      s   r3   c                    sL   t  j|| d| jd _tjjdd| jd _d| jd _d| jd _d S )NFr$   T)rs   r   r   r   )rR   rS   r)   rT   r   objectsfilterquerysetrY   r]   r1   r2   rS      s
    zRoleAssignmentForm.__init__)r%   r&   r'   rf   r3   rS   rh   r1   r1   r]   r2   r~      s   
r~   c                   @   s   e Zd ZdZG dd dZdS )RoleFormz$Form for creating or updating roles.c                   @   sL   e Zd ZeZdddgZejddidejddddej	dd	idd
Z
dS )zRoleForm.Metanamedescriptionrs   r   r   r   r   r   r#   )r   r   rs   N)r%   r&   r'   r   r(   r)   r   r*   r+   r/   r0   r1   r1   r1   r2   r3      s   
r3   Nr}   r1   r1   r1   r2   r      s   r   )rf   rU   djangor   django.core.exceptionsr   django.utils.translationr   _django.contrib.auth.formsr   apps.accounts.modelsr   r   r   r	   	ModelFormr
   ri   rn   r|   r~   r   r1   r1   r1   r2   <module>   s   \(