o
    'h7                     @   s   d dl mZ d dlmZ d dlmZmZ d dlmZ e Z	G dd dej
ZG dd dej
ZG d	d
 d
eZG dd deZd dl mZ d dlmZ d dlmZ ddlmZmZ G dd dejZG dd dej
ZdS )    )forms)get_user_model)PasswordResetFormSetPasswordForm)ValidationErrorc                   @   s   e Zd ZG dd dZdS )UserProfileFormc                   @   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UserProfileForm.Meta
first_name	last_nameemailclassform-controlattrsN
__name__
__module____qualname__Usermodelfieldsr   	TextInput
EmailInputwidgets r   r   ./var/www/html/optinet_system/accounts/forms.pyMeta
   s    
r   N)r   r   r   r   r   r   r   r   r   	   s    r   c                   @   &   e Zd ZdZG dd dZdd ZdS )ProfileUpdateFormz*Form for updating user profile informationc                   @   sN   e Zd ZeZg dZejddddejddddejdddddZ	dS )	zProfileUpdateForm.Metar   r   zEnter your first namer   placeholderr   zEnter your last nameEnter your email addressNr   r   r   r   r   r      s     
r   c                 C   s4   | j d }tjj|dj| jjd rtd|S )Nr   )r   )pkz%This email address is already in use.)	cleaned_datar   objectsfilterexcludeinstancer"   existsr   selfr   r   r   r   clean_email'   s   
zProfileUpdateForm.clean_emailN)r   r   r   __doc__r   r+   r   r   r   r   r      s    r   c                   @   s8   e Zd ZdZejddejdddddd	Zd
d ZdS )CustomPasswordResetFormz0Custom password reset form with enhanced stylingzEmail Address   form-control with-iconr!   r   r   r    autocompleter   )label
max_lengthwidgetc                 C   s$   | j d }tjj|dd s	 |S )Nr   T)r   	is_active)r#   r   r$   r%   r(   r)   r   r   r   r+   :   s   
z#CustomPasswordResetForm.clean_emailN)	r   r   r   r,   r   
EmailFieldr   r   r+   r   r   r   r   r-   .   s    
r-   c                   @   sR   e Zd ZdZejdejddddddd	d
ZejddejddddddZdS )CustomSetPasswordFormz.Custom set password form with enhanced stylingzNew Passwordr/   zEnter new passwordznew-passwordr0   r   Fz,Password must be at least 8 characters long.)r2   r4   strip	help_textzConfirm New PasswordzConfirm new password)r2   r8   r4   N)	r   r   r   r,   r   	CharFieldPasswordInputnew_password1new_password2r   r   r   r   r7   A   s*    

r7   )Group)
Department   )GroupPermissionManagerDepartmentPermissionAssignmentc                       sD   e Zd ZdZejejjddej	ddiddZ
 fdd	Z  ZS )
DepartmentPermissionFormz4Form to manage permissions for a specific departmentT)r5   r   form-selectr   )querysetr4   c           
   	      s   | dd }t j|i | |r || jd _d| jd jjd< tj}t	 }|r6t	t
jj|djddd}|D ]0\}}tjj|ddd}| rhd	| }	tj|tjd
|ddd||j|dd| j|	< q8d S )N
departmentTreadonly)rF   permission_id)flat)categoryr5   display_namepermissions_z$form-check-input permission-checkbox)r   zdata-categoryr   F)id__in)rE   r4   requiredr2   initial)popsuper__init__r   rO   r4   r   rA   PERMISSION_CATEGORIESsetrB   r$   r%   values_listorder_byr(   r   ModelMultipleChoiceFieldCheckboxSelectMultiple)
r*   argskwargsrF   
categoriesassigned_permissionscategory_keycategory_namepermissions
field_name	__class__r   r   rR   e   sH   

z!DepartmentPermissionForm.__init__)r   r   r   r,   r   ModelChoiceFieldr?   r$   r%   SelectrF   rR   __classcell__r   r   ra   r   rC   ^   s    rC   c                   @   r   )AddPermissionFormz"Form to add new system permissionsc                   @   s^   e Zd ZeZg dZejddddejddddejdddd	dej	d
diddZ
dS )zAddPermissionForm.Meta)namerK   descriptionrJ   r   z$e.g., view_customers, manage_billingr   r   z$e.g., View Customers, Manage Billing   z0Describe what this permission allows users to do)r   rowsr    r   rD   N)r   r   r   rA   r   r   r   r   Textareard   r   r   r   r   r   r      s$    
r   c                 C   s(   | j d }| rd|v rtd|S )Nrg    zIPermission name must be lowercase with underscores (e.g., view_customers))r#   islowerr   r   )r*   rg   r   r   r   
clean_name   s   

zAddPermissionForm.clean_nameN)r   r   r   r,   r   rn   r   r   r   r   rf      s    rf   N)djangor   django.contrib.authr   django.contrib.auth.formsr   r   django.core.exceptionsr   r   	ModelFormr   r   r-   r7   django.contrib.auth.modelsr>   	hr.modelsr?   modelsrA   rB   FormrC   rf   r   r   r   r   <module>   s   
-