
    sit%                        d 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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mZmZ ddlmZ  G d de      Z G d de      Z G d de      Z G d de      Z  G d de      Z! G d de      Z" G d de      Z# G d dej                        Z$ G d dej                        Z% G d de      Z&y )!a  
forms.py

This module contains the form classes used in the application.

Each form represents a specific functionality or data input in the
application. They are responsible for validating
and processing user input data.

Classes:
- YourForm: Represents a form for handling specific data input.

Usage:
from django import forms

class YourForm(forms.Form):
    field_name = forms.CharField()

    def clean_field_name(self):
        # Custom validation logic goes here
        pass
    )Any)formsrender_to_string)	ModelForm)filtersubordinatesemployeemodelis_reportingmanager)
DepartmentJobPosition)MultipleFileField)Employee)FAQ
AttachmentCommentDepartmentManagerFAQCategoryTicket
TicketType)horilla_middlewaresc                   2    e Zd ZddddZ G d d      Zd Zy)TicketTypeForm   )titletypeprefixc                   H    e Zd ZeZdZdgZd ej                  ddi      iZ	y)TicketTypeForm.Meta__all__	is_activer   classoh-select oh-select-2attrsN)
__name__
__module____qualname__r   modelfieldsexcluder   Selectwidgets     2/var/www/python-projects/worksol/helpdesk/forms.pyMetar   2   s5    -LELL0( 
r-   r/   c                 &    d| i}t        d|      }|S zS
        Render the form fields as HTML table rows with Bootstrap styling.
        formzhorilla_form.htmlr   selfargskwargscontext
table_htmls        r.   as_pzTicketTypeForm.as_p<         4.%&97C
r-   N)r$   r%   r&   colsr/   r9   r,   r-   r.   r   r   .   s    r2D
 
r-   r   c                   >     e Zd ZddddZ G d d      Z fdZ xZS )FAQFormr   )questionanswertagsc                   j    e Zd ZeZdZdgZ ej                          ej                  ddd      dZ
y)	FAQForm.Metar   r   /oh-select oh-select-2 select2-hidden-accessiblezupdateTag(this)r    onchanger"   )categoryr@   N)r$   r%   r&   r   r'   r(   r)   r   HiddenInputSelectMultipler+   r,   r-   r.   r/   rB   I   sC    -)))+(E((N 1
r-   r/   c                     t        |   |i | t        | j                  d   j                        | j                  d   _        | j                  d   j                  j                  d       y)
        Initializes the Ticket tag form instance.
        If an instance is provided, sets the initial value for the form's .
        r@   create_new_tagzCreate new tagN)super__init__listr(   choicesappend)r4   r5   r6   	__class__s      r.   rN   zFAQForm.__init__W   sZ    
 	$)&)&*4;;v+>+F+F&GF#F##**+OPr-   r$   r%   r&   r;   r/   rN   __classcell__rR   s   @r.   r=   r=   E   s%    b"5D
 
Q Qr-   r=   c                        e Zd ZdddZ ej
                   ej                  ddi            Z G d d      Zd	 Z	d
 Z
 fdZ xZS )
TicketFormr   )descriptionr@   r   dater"   )widgetc                   b   e Zd ZeZg dZ ej                  ddi       ej                  ddi       ej                  ddi       ej                  ddi       ej                  ddi       ej                  ddi       ej                  ddd       ej                  ddd      d	Z
y
)TicketForm.Meta)idr   employee_idrX   ticket_typepriorityassigning_type	raised_ondeadlinestatusr@   r    r!   r"   truer    requiredT)zdata-summernotehidden)r^   rd   r@   r_   r`   ra   rb   rX   N)r$   r%   r&   r   r'   r(   r   r*   rH   Textarear+   r,   r-   r.   r/   r\   f   s    
 (5<< 78 #ell 78 )E((4
 (5<< 78 % 78 +ell 78 & 7VL *5>>'+"1
r-   r/   c                 &    d| i}t        d|      }|S r1   r   r3   s        r.   r9   zTicketForm.as_p   r:   r-   c                     | j                   j                  d      }|0ddlm} |j	                         }||k  rt        j                  d      |S )z;
        Validate that deadline is not in the past
        rc   r   )rY   zDeadline cannot be in the past)cleaned_datagetdatetimerY   todayr   ValidationError)r4   rc   rY   ro   s       r.   clean_deadlinezTicketForm.clean_deadline   sM     $$((4%JJLE%++,LMMr-   c                    t        |   |i | | j                  r3| j                  j                  r| j                  j                  dd        nt        dd      | j                  d<   t        t        j                  dd       }|j                  d      }|r|j                  }n|j                  j                  }t        |t        j                   j#                  d      d	
      t        j                   j#                  |j                        z  | j                  d   _        || j                  d   _        t)        |      s|j                  j+                  d      r4t-        | j                  d   j.                        | j                  d   _        ddlm} |j                   j#                  d      | j                  d   _        y )N
attachmentAttachementsF)labelrg   requestinstanceT)r   zhelpdesk.add_ticket)perm)employee_user_idr^   zhelpdesk.add_tickettyper_   r   )Tagsr@   )rM   rN   rw   pkr(   popr   getattrr   _thread_localsrm   r^   useremployee_getr   r   objectsfilterquerysetinitialr	   has_permrO   rP   base.modelsrz   )r4   r5   r6   rv   rw   employeerz   rR   s          r.   rN   zTicketForm.__init__   sh   $)&)==T]]--KKOOL$/(9$u)DKK% -<<iN::j)++H||00H.MX%%,,t,<CX/
##W\\#B/CM"+ .6M"*w'7<<+@+@%,
 26M*222DKK&. 	%'+||':':T':'JF$r-   )r$   r%   r&   r;   r   	DateField	DateInputrc   r/   r9   rq   rN   rT   rU   s   @r.   rW   rW   a   sN    r*DuoeooVV<L&MNH-
 -
^
 K  Kr-   rW   c                   2     e Zd Z G d d      Z fdZ xZS )TicketTagFormc                   F    e Zd ZeZdgZd ej                  ddd      iZy)TicketTagForm.Metar@   rC   zupdateTag()rD   r"   N)	r$   r%   r&   r   r'   r(   r   rH   r+   r,   r-   r.   r/   r      s8    
 (E((N -
r-   r/   c                 `   t        |   |i | t        t        j                  dd      }t        |      s|j                  j                  d      r]t        | j                  d   j                        | j                  d   _
        | j                  d   j                  j                  d       yy)rJ   rv   Nzbase.add_tagsr@   rK   )rM   rN   r}   r   r~   r	   r   r   rO   r(   rP   rQ   )r4   r5   r6   rv   rR   s       r.   rN   zTicketTagForm.__init__   s    
 	$)&)-<<iNw'7<<+@+@+Q*.t{{6/B/J/J*KDKK'KK''../ST ,Rr-   )r$   r%   r&   r/   rN   rT   rU   s   @r.   r   r      s    
 
	U 	Ur-   r   c                        e Zd Z G d d      Zy)TicketRaisedOnFormc                   H    e Zd ZeZddgZd ej                  ddd      iZy)TicketRaisedOnForm.Metara   rb   r!   re   rf   r"   N)	r$   r%   r&   r   r'   r(   r   r*   r+   r,   r-   r.   r/   r      s0    "K0 7VL
r-   r/   Nr$   r%   r&   r/   r,   r-   r.   r   r      s    
 
r-   r   c                        e Zd Z G d d      Zy)TicketAssigneesFormc                       e Zd ZeZdgZy)TicketAssigneesForm.Metaassigned_toN)r$   r%   r&   r   r'   r(   r,   r-   r.   r/   r      s    
r-   r/   Nr   r,   r-   r.   r   r      s    
 
r-   r   c                   *    e Zd ZdddZ G d d      Zy)FAQCategoryFormr   )r   rX   c                       e Zd ZeZdZdgZy)FAQCategoryForm.Metar   r   N)r$   r%   r&   r   r'   r(   r)   r,   r-   r.   r/   r      s    -r-   r/   N)r$   r%   r&   r;   r/   r,   r-   r.   r   r      s    +D   r-   r   c                        e Zd Z G d d      Zy)CommentFormc                   B    e Zd ZeZdgZdgZd ej                         iZ	y)CommentForm.Metacommentr   r^   N)
r$   r%   r&   r   r'   r(   r)   r   rG   r+   r,   r-   r.   r/   r     s0    
 - "3%"3"3"56r-   r/   Nr   r,   r-   r.   r   r     s    7 7r-   r   c            	       t    e Zd Z ej                   ej
                  ddddd      d      Z G d	 d
      Zy)AttachmentFormfileFilezform-controlTrue)namer   r    multipler"    )rZ   ru   c                       e Zd ZeZg dZdgZy)AttachmentForm.Meta)r   r   ticketr   N)r$   r%   r&   r   r'   r(   r)   r,   r-   r.   r/   r     s    .-r-   r/   N)r$   r%   r&   r   	FileField	TextInputr   r/   r,   r-   r.   r   r     s@    5??u'"	
 
D   r-   r   c                   <     e Zd ZdddZ G d d      Z fdZ xZS )DepartmentManagerCreateFormr   
departmentmanagerc                   p    e Zd ZeZddgZ ej                  ddd       ej                  ddi      dZy	)
 DepartmentManagerCreateForm.Metar   r   zgetDepartmentEmployees($(this))r!   )rE   r    r"   r    r   N)	r$   r%   r&   r   r'   r(   r   r*   r+   r,   r-   r.   r/   r   $  sL    !	*&%,, A4 $u||4
r-   r/   c                    t        |   |i | | j                  j                  rdd|v r_|d   j                  }|j
                  j                  dd      }t        j                  j                  |      | j                  d   _        y y y )Nrw   r^   T)flat)id__inr   )rM   rN   rw   r{   r   employeeworkinformation_setvalues_listr   r   r   r(   r   )r4   r5   r6   r   	employeesrR   s        r.   rN   z$DepartmentManagerCreateForm.__init__5  s    $)&)==V##J/::
&BBNN! O 	 3;2B2B2I2I$ 3J 3I&/ $ r-   rS   rU   s   @r.   r   r      s!    ,D
 
" r-   r   N)'__doc__typingr   djangor   django.template.loaderr   
base.formsr   base.methodsr   r	   r   r
   r   employee.formsr   employee.modelsr   helpdesk.modelsr   r   r   r   r   r   r   horillar   r   r=   rW   r   r   r   r   r   r   r   r,   r-   r.   <module>r      s   .   3   M / , $   (Y .Qi Q8hK hKVUI U6
 

) 
 i  7%// 7 U__  &!) !r-   