
    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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 ed        Ze ed      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)MailAutomation)REFRESH_METHODS)HorillaFormViewc                     | 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   C/var/www/python-projects/worksol/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   z)horilla_automations.delete_mailautomationc                 "   	 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_automationr6   /   sv    8""b")002"67 G./00  8aw 6778s   AA 	B#!B		Bz&horilla_automations.add_mailautomationc                 B   d}t        j                  d      rt        d           d}t        j                  d      rt        d           d}|r*t        j                  | d       t        j                         S t        j                  | d       t        j                         S )z/
    Method to  refresh automation signals
    Fclear_connectionTstart_connectionz#Automations refreshed successfully.z+Automation method not available to refresh.)r   r.   r   r0   r3   r   HttpResponse)r'   	refresheds     r   refresh_automationsr<   >   s     I-.*+-	-.*+-	"GH '')) 	w MN''))r   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   horilla_automations.signalsr   horilla_views.generic.cbv.viewsr   r*   r6   r<    r   r   <module>rI      s     # $ %  B @ @ 5 7 ;  6 @A
1 B 
1 =>* ? *r   