
    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mZ ddlmZ ddlmZ dd	lmZ dd
lmZ  eed       e ed      d       G d dej*                                      Z eed       e ed      d       G d dej.                                      Z eed       e ed      d       G d dej2                                      Z eed       e ed      d       G d dej6                                      Z eed       e ed      d       G d dej:                                      Zy)z#
horilla_automations/views/cbvs.py
    )messages)reverse_lazy)method_decorator)gettext_lazy)login_requiredpermission_required)models)AutomationFilter)AutomationForm)viewsdispatch)namez&horilla_automation.view_mailautomationc                   >    e Zd ZdZ ed      Z ed      ZdZdgZdZ	y)AutomationSectionViewz
    AutomationSectionView
    zmail-automations-navmail-automations-list-viewlistContainerz/automation/automation.jsz%horilla_automations/section_view.htmlN)
__name__
__module____qualname____doc__r   nav_urlview_urlview_container_idscript_static_pathstemplate_name     2/var/www/horilla/horilla_automations/views/cbvs.pyr   r      s9    
 12G89H' 	$ <Mr   r   c                   H     e Zd ZdZd fdZ ed      Z ed      ZdZ	 xZ
S )AutomationNavViewz
    AutomationNavView
    c                 L    t        |   |i | dt        d       d| _        y )Nz
            hx-get="zcreate-automationz"
            hx-target="#genericModalBody"
            data-target="#genericModal"
            data-toggle="oh-modal-toggle"
        )super__init__r   create_attrs)selfargskwargs	__class__s      r   r#   zAutomationNavView.__init__.   s5    $)&)!!"567 8	r   Automationsr   z#listContainer)returnN)r   r   r   r   r#   _trans	nav_titler   
search_urlsearch_swap_target__classcell__r(   s   @r   r    r    %   s*    
 }%I:;J)r   r    z(horilla_automation.change_mailautomationc                   z     e Zd ZdZeZej                  Z e	d      Z
dZ fdZdedej                  f fdZ xZS )AutomationFormViewz
    AutomationFormView
    zNew Automationz(horilla_automations/automation_form.htmlc                     t         |          }t        j                  j                  j                  | j                  d         j                         }||d<   |S )Npk)r4   instance)r"   get_form_kwargsr	   MailAutomationobjectsfilterr'   first)r%   r'   r5   r(   s      r   r6   z"AutomationFormView.get_form_kwargsJ   sP    (*((00774;;t;L7MSSU%zr   formr*   c                    |j                         rcd}|j                  j                  rd}|j                          t	        j
                  | j                  t        |             | j                         S t        | )  |      S )NzNew automation addedzAutomation updated)is_validr5   r4   saver   successrequestr+   HttpResponser"   
form_valid)r%   r;   messager(   s      r   rB   zAutomationFormView.form_validQ   sc    ==?,G}}.IIKT\\6'?;$$&&w!$''r   )r   r   r   r   r   
form_classr	   r7   modelr+   new_display_titler   r6   r   rA   rB   r/   r0   s   @r   r2   r2   <   sN    
  J!!E/0>M	(~ 	(%2D2D 	( 	(r   r2   c                   h    e Zd ZdZdZej                  Z ed      Z	e
Zdddddd	d
dgZddiZg dZy)AutomationListViewz
    AutomationListView
    z
            hx-get="{detailed_url}?instance_ids={ordered_ids}"
            hx-target="#genericModalBody"
            data-toggle="oh-modal-toggle"
            data-target="#genericModal"
        r   Editcreate-outlinea  
                class="oh-btn oh-btn--light-bkg w-100"
                hx-get="{edit_url}?instance_ids={ordered_ids}"
                hx-target="#genericModalBody"
                data-target="#genericModal"
                data-toggle="oh-modal-toggle"
            actioniconattrsDeletetrash-outlinez
            class="oh-btn oh-btn--light-bkg w-100 tex-danger"
            onclick="
                event.stopPropagation();
                confirm('Do you want to delete the automation?','{delete_url}')
            "
            rL   zstyle='width:100px;'))TitletitleModelrE   )zEmail Mappingget_mail_to_displayN)r   r   r   r   	row_attrsr	   r7   rE   r   r-   r
   filter_classactionsheader_attrscolumnsr   r   r   rH   rH   ]   sj    
I !!E:;J#L $
	
 #
	
G0 45LGr   rH   c                   X    e Zd ZdZej
                  ZdZddddZg dZ	ddd	d
dddd
gZ
y)AutomationDetailedViewz 
    AutomationDetailedView
    zDetailed ViewrR   
get_avatar)rR   subtitleavatar)rS   )zMail Templatesmail_template)zMail TorU   )zMail Ccget_mail_cc_display)Triggertrigger_displayrI   rJ   z
            hx-get="{edit_url}?instance_ids={ordered_ids}"
            hx-target="#genericModalBody"
            data-toggle="oh-modal-toggle"
            data-target="#genericModal"
            class="oh-btn oh-btn--info w-50"
            rK   rO   rP   z
            class="oh-btn oh-btn--danger w-50"
            onclick="
                confirm('Do you want to delete the automation?','{delete_url}')
            "
            N)r   r   r   r   r	   r7   rE   rR   headerbodyrX   r   r   r   r\   r\      s[    
 !!EEF
D $
	
 #		
Gr   r\   N)r   django.contribr   django.urlsr   django.utils.decoratorsr   django.utils.translationr   r+   horilla.decoratorsr   r   horilla_automationsr	   horilla_automations.filtersr
   horilla_automations.formsr   horilla_views.generic.cbvr   HorillaSectionViewr   HorillaNavViewr    HorillaFormViewr2   HorillaListViewrH   HorillaDetailedViewr\   r   r   r   <module>rt      sh   $ $ 4 ; B & 8 4 + .z2@A
<E44 < 3<  .z2@A
*,, * 3*& .z2BC*(.. ( 3(: .z2@A
-.. - 3-` .z2@A
)U66 ) 3)r   