
    si                         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 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 ddlmZ  G d de	      Zy)z
horilla_automations/forms.py
    )Any)forms)gettext_lazy)	ModelForm)EmployeeFilter)Employee)generate_choices)MODEL_CHOICESMailAutomation)default_select_option_template)HorillaMultiSelectField)HorillaMultiSelectWidgetc                        e Zd ZdZ ej
                   ej                               Z ej
                   ej                               ZddiZ	 G d d      Z
 fdZ fdZdd	ed
ef fdZ xZS )AutomationFormz
    AutomationForm
    )widgettemplate_attachments   c                       e Zd ZeZdZy)AutomationForm.Meta__all__N)__name__
__module____qualname__r   modelfields     =/var/www/python-projects/worksol/horilla_automations/forms.pyMetar      s    r   r   c                 6   t        |   |i | t        t        j                  j                         dt        dt        dd| j                        dt        d            | j                  d	<   t        | j                  d
d       xs | j                  j                  d
      }g g }}|rt        |      }|d   |d   }}t        j                   || j                  j                  d      t        j"                  ddi            | j                  d<   t        j$                  |t        d            | j                  d<   ddi| j                  d   j&                  _        dgt+        t-        t.                    z   | j                  d
   _        d| j                  d
   j&                  j(                  d<   d| j                  d   _        t        | j                  dd       xs | j                  j                  d      | j                  d   _        t        | j                  dd       xs | j                  j                  d      | j                  d   _        t        | j                  dd       xs | j                  j                  d      | j                  d   _        | j                  j7                         D ]<  }t9        |j&                  t        j:                        s(t<        |j&                  _        > | j                  jA                  d      | j                  d<   y )NFzemployee-widget-filterfzemployee_filters.html)filter_route_namefilter_classfilter_instance_contex_namefilter_template_pathinstancezAlso Sent toz9The employees selected here will receive the email as Cc.)querysetrequiredr   label	help_textalso_sent_tor   r      mail_toclasszoh-select oh-select-2 w-100)attrs)choicesinitialr   zeFill mail template details (receiver/instance, `self` will be the person who triggers the automation))r0   r*   mail_details) zSelect modelzgetToMail($(this))onchangez
----------mail_template	conditioncondition_htmlcondition_querystring	is_active)!super__init__r   r   objectsallr   r   r&   _r   getattrdatagetr	   r   MultipleChoiceFieldSelectMultipleChoiceFieldr   r/   sortedsetr
   r0   empty_labelr1   values
isinstanceSelectr   option_template_namepop)	selfargskwargsr   r-   mail_details_choicer0   field	__class__s	           r   r;   zAutomationForm.__init__"   s   $)&) '>%%))++":+,/%< !ST'
N# w5Ow9O')2$&u-G+21:wqz(G "'!:!:IIMM),''w8U.VW"
I ',&7&7'w'
N# 24
N#**0
 )='=A
 (
G$ 9MG##))*5 4@O$0 ,3MM;,
 ,(YY]];' 	K ( 18MM+T1
 1-YY]]+, 	$%- 8?MM;8
 8-YY]]+, 	+,4
 [['') 	SE%,,54R1	S
 $(;;??;#?K r   c                 $   t         |          }t        | j                  d   t              rc| j
                  j                  dd        | j                  d   j                  j                  | j                  j                  d            }||d<   |S )Nr+   )id__in)r:   cleanrI   r   r   errorsrL   r'   filterr@   getlist)rM   cleaned_dataemployee_datarR   s      r   rU   zAutomationForm.cleanj   s}    w}dkk.13JKKKOOND1 KK7@@GGyy((8 H M ,9L(r   commitreturnc                 j   | j                   | _         | j                  d   }| j                  d   }| j                  j                  d      }t	        |      | j                   _        | j                  d   | j                   _        || j                   _        || j                   _        t        | )  |      S )Nr8   r7   r-   r2   )r&   rY   r@   rX   strr-   r2   r8   r7   r:   save)rM   r[   r8   r7   r-   rR   s        r   r_   zAutomationForm.savev   s    (, $ 1 12I J**+;<))##I. #G%)YY~%>".C+'5$w|F##r   ).)r   r   r   __doc__r   	CharFieldHiddenInputr7   r8   colsr   r;   rU   boolr   r_   __classcell__)rR   s   @r   r   r      s|     %U__,=E,=,=,?@N+EOO3D53D3D3FG"B'D F@P
	$4 	$# 	$ 	$r   r   N)r`   typingr   djangor   django.utils.translationr   r>   
base.formsr   employee.filtersr   employee.modelsr   #horilla_automations.methods.methodsr	   horilla_automations.modelsr
   r   horilla_widgets.formsr   2horilla_widgets.widgets.horilla_multi_select_fieldr   &horilla_widgets.widgets.select_widgetsr   r   r   r   r   <module>rq      s;      6   + $ @ D @ V Kk$Y k$r   