
    si                         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	 d dl
mZ d dlmZmZ d dl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j.                        Zy)    )formsrender_to_string)	ModelForm)reload_queryset)EmployeeFilter)Employee)DocumentDocumentRequest)HorillaMultiSelectField)HorillaMultiSelectWidgetc                   @     e Zd ZdZ G d d      Z fdZ fdZ xZS )DocumentRequestFormz%form to create a new Document Requestc                       e Zd ZeZdZdgZy)DocumentRequestForm.Meta__all__	is_activeN)__name__
__module____qualname__r   modelfieldsexclude     ;/var/www/python-projects/worksol/horilla_documents/forms.pyMetar      s    -r   r   c                    t         |          }t        | j                  d   t              r| j
                  j                  dd        t        | j                  j                  d            dk  rt        j                  ddi      | j                  d   j                  j                  | j                  j                  d            }||d<   |S )Nemployee_id   zThis field is required)id__in)superclean
isinstancer   r   errorspoplendatagetlistr   ValidationErrorquerysetfilter)selfcleaned_dataemployee_data	__class__s      r   r#   zDocumentRequestForm.clean   s    w}dkk-02IJKKOOM40499$$]34q8++]<T,UVV KK6??FFyy((7 G M +8L'r   c                     t        |   |i | t        t        j                  j                         t        dt        ddd| j                        d      | j                  d<   t        | j                         y )	Nzemployee-widget-filterfzemployee_filters.htmlT)filter_route_namefilter_classfilter_instance_contex_namefilter_template_pathrequiredinstancer	   )r+   widgetlabelr   )r"   __init__r   r	   objectsallr   r   r8   r   r   r-   argskwargsr0   s      r   r;   zDocumentRequestForm.__init__#   sk    $)&)%<%%))++":+,/%< &
M" 	$r   )r   r   r   __doc__r   r#   r;   __classcell__r0   s   @r   r   r      s    /   
% %r   r   c                   <     e Zd ZdZ G d d      Zd Z fdZ xZS )DocumentFormzform to create a new Documentc                       e Zd ZeZdZg dZ ej                          ej                  ddd       ej                  ddd      dZ
y)	DocumentForm.Metar   )document_request_idstatusreject_reasonr   dateoh-input  w-100typeclassattrs)r   
issue_dateexpiry_dateN)r   r   r   r
   r   r   r   r   HiddenInput	DateInputwidgetsr   r   r   r   rG   7   sV    Q,5,,.)%//%0AB +5??%0AB
r   r   c                 &    d| i}t        d|      }|S )zS
        Render the form fields as HTML table rows with Bootstrap styling.
        formzcommon_form.htmlr   )r-   context
table_htmls      r   as_pzDocumentForm.as_pE   s      4.%&8'B
r   c                     t        |   |i | | j                  d   j                  j                  j                  ddddd       y )NrS   z#id_notify_before_parent_divzload,change	innerHTMLz/employee/get-notify-field/)z	hx-targetz
hx-triggerzhx-swapzhx-get)r"   r;   r   r9   rQ   updater>   s      r   r;   zDocumentForm.__init__M   sI    $)&)M"))//66;+&7		
r   )r   r   r   rA   r   r[   r;   rB   rC   s   @r   rE   rE   4   s    '
 
	
 	
r   rE   c                   0    e Zd ZdZddiZdZ G d d      Zy)DocumentUpdateFormzform to Update a Documentdocument   r
   c                   t    e Zd ZeZdZdgZ ej                  ddd       ej                  ddd      dZ	y)	DocumentUpdateForm.Metar   r   rK   rL   rM   rP   )rR   rS   N)
r   r   r   r
   r   r   r   r   rU   rV   r   r   r   r   rd   `   sJ    -)%//%0AB +5??%0AB	
r   r   N)r   r   r   rA   colsverbose_namer   r   r   r   r`   r`   Y   s    #DL
 
r   r`   c                   >     e Zd ZdZddiZ G d d      Z fdZ xZS )DocumentRejectCbvFormz7form to add rejection reason while rejecting a DocumentrJ   rb   c                       e Zd ZeZdgZy)DocumentRejectCbvForm.MetarJ   N)r   r   r   r
   r   r   r   r   r   r   rj   s   s    !"r   r   c                 p    t        |   |i | d| j                  d   j                  j                  d<   y )NTrJ   r7   )r"   r;   r   r9   rQ   r>   s      r   r;   zDocumentRejectCbvForm.__init__w   s4    $)&)@DO$++11*=r   )r   r   r   rA   re   r   r;   rB   rC   s   @r   rh   rh   n   s&    AR D# #E Er   rh   c            	           e Zd Z e       j                  j                  d      j                  Z ej                   ej                  deddd      dde	      Z
y
)DocumentRejectFormrJ   zoh-input w-100   (   )rO   placeholderrowsre   rP      T)r9   
max_lengthr7   r:   N)r   r   r   r
   _meta	get_fieldrf   r   	CharFieldTextarearJ   r   r   r   rm   rm   |   sZ    :##--o>KKL#EOOu~~)+	
 Mr   rm   N)djangor   django.template.loaderr   
base.formsr   base.methodsr   employee.filtersr   employee.modelsr	   horilla_documents.modelsr
   r   2horilla_widgets.widgets.horilla_multi_select_fieldr   &horilla_widgets.widgets.select_widgetsr   r   rE   r`   rh   Formrm   r   r   r   <module>r      sd     3   ( + $ > V K$%) $%N"
9 "
J
 
*EI E r   