
    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mZ ddlmZ dd	lmZ dd
lmZ ed        Ze ed      d               Zy)z#
horilla_automation/views/views.py
    )forms)messages)JsonResponse)redirect)reverse)login_requiredpermission_required)generate_choices)serialize_form)MailAutomationc                     | j                   d   }t        |      \  }} G fddt        j                        }t	         |       d      }t        |||d      S )z3
    This method is to render `mail to` fields
    modelc                   *    e Zd ZdZ G  fdd      Zy)&get_to_field.<locals>.InstantModelFormz"
        InstantModelForm
        c                       e Zd ZW  ZdZy)+get_to_field.<locals>.InstantModelForm.Meta__all__N)__name__
__module____qualname__r   fieldsmodel_classs   3/var/www/horilla/horilla_automations/views/views.pyMetar      s    EF    r   N)r   r   r   __doc__r   r   s   r   InstantModelFormr      s    		 	r   r   automation_multiple_)choicesmail_details_choiceserialized_form)GETr
   r   	ModelFormr   r   )request
model_path	to_fieldsr!   r   r"   r   s         @r   get_to_fieldr(      sc    
 W%J2B:2N/I"K5??  %%5%79OPO #6.	
 r   horilla_automationc                 "   	 t         j                  j                  |      j                          t	        j
                  | d       t        t        d            S # t        $ r+}t        |       t	        j                  | d       Y d}~Cd}~ww xY w)z 
    Automation delete view
    )idzAutomation deletedzSomething went wrongNzmail-automations)r   objectsgetdeleter   success	Exceptionprinterrorr   r   )r%   pkes      r   delete_automationr5   -   sv    8""b")002"67 G./00  8aw 6778s   AA 	B#!B		BN)r   djangor   django.contribr   django.httpr   django.shortcutsr   django.urlsr   horilla.decoratorsr   r	   #horilla_automations.methods.methodsr
   %horilla_automations.methods.serializer   horilla_automations.modelsr   r(   r5    r   r   <module>r@      s]     # $ %  B @ @ 5  6 )*
1 + 
1r   