
    vg                         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  G d de	      Zy)z
horilla_automations/forms.py
    )Any)forms)gettext_lazy)	ModelForm)EmployeeFilter)Employee)generate_choices)MODEL_CHOICESMailAutomation)HorillaMultiSelectField)HorillaMultiSelectWidgetc                        e Zd ZdZ ej
                   ej                               Z ej
                   ej                               ZddiZ	 fdZ
 G d d      Z fdZdd	ed
ef fdZ xZS )AutomationFormz
    AutomationForm
    )widgettemplate_attachments   c                    t        |   |i | t        t        j                  j                         dt        dt        dd| j                        dt        d            | j                  d	<   | j                  sg }g }g }| j                  j                  rDt        | j                  j                        d
   }t        | j                  j                        d   }t        j                   |      | j                  d<   t        j"                  |d      | j                  d<   || j                  d   _        | j                  d   j&                  j(                  }d|d<   | j                  d   j&                  j(                  }dgt+        t-        t.                    z   | j                  d   _        d|d<   d | j                  d   _        |j5                         }|d= || j                  d   j&                  _        | j                  j                  ry| j                  j6                  | j                  d   _        | j                  j6                  | j                  d   _        | j                  j8                  | j                  d   _        y 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      )choicesmail_tozcFill mail template details(reciever/instance, `self` will be the person who trigger the automation))r    r   mail_detailszoh-select oh-select-2 w-100classmodel) zSelect modelzgetToMail($(this))onchangemail_template	conditioncondition_htmlcondition_querystring)super__init__r   r   objectsallr   r   r   _fieldsdatapkr	   r$   r   MultipleChoiceFieldChoiceFieldinitialr   attrslistsetr
   r    empty_labelcopyr)   r*   )selfargskwargsr!   r5   mail_details_choicer6   	__class__s          -/var/www/horilla/horilla_automations/forms.pyr,   zAutomationForm.__init__   s   $)&)&=%%))++":+,/%< !ST'
N# yyGG"$}}*4==+>+>?B&6t}}7J7J&KA&N#%*%>%>w%ODKK	"*/*;*;++DKK' .5DKK	"*KK	*1177E:E'NG$++11(<'=SEW@X'XG$0j37O$0

*38N#**0==/3}}/K/KDKK$,48MM4P4PDKK()133 KK/08     c                       e Zd ZeZdZy)AutomationForm.Meta__all__N)__name__
__module____qualname__r   r$   r0    rA   r@   MetarC   J   s    rA   rI   c                 $   t         |          }t        | j                  d   t              rc| j
                  j                  dd        | j                  d   j                  j                  | j                  j                  d            }||d<   |S )Nr   )id__in)r+   clean
isinstancer0   r   errorspopr   filterr1   getlist)r;   cleaned_dataemployee_datar?   s      r@   rL   zAutomationForm.cleanN   s}    w}dkk.13JKKKOOND1 KK7@@GGyy((8 H M ,9L(rA   commitreturnc                 j   | j                   | _         | j                  d   }| j                  d   }| j                  j                  d      }t	        |      | j                   _        | j                  d   | j                   _        || j                   _        || j                   _        t        | )  |      S )Nr*   r)   r!   r"   )r   rR   r1   rQ   strr!   r"   r*   r)   r+   save)r;   rT   r*   r)   r!   r?   s        r@   rX   zAutomationForm.saveZ   s    (, $ 1 12I J**+;<))##I. #G%)YY~%>".C+'5$w|F##rA   ).)rE   rF   rG   __doc__r   	CharFieldHiddenInputr)   r*   colsr,   rI   rL   boolr   rX   __classcell__)r?   s   @r@   r   r      sz     %U__,=E,=,=,?@N+EOO3D53D3D3FG"B'D+Z 
	$4 	$# 	$ 	$rA   r   N)rY   typingr   djangor   django.utils.translationr   r/   
base.formsr   employee.filtersr   employee.modelsr   #horilla_automations.methods.methodsr	   horilla_automations.modelsr
   r   2horilla_widgets.widgets.horilla_multi_select_fieldr   &horilla_widgets.widgets.select_widgetsr   r   rH   rA   r@   <module>ri      s8      6   + $ @ D V KP$Y P$rA   