
    si              
           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 g Zd	 ed
      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fgZ G d de      Zy)    )models)reverse)gettext_lazy)eval_validate)HorillaMailTemplate)Employee)HorillaModelrender_templateequalz
Equal (==)notequalzNot Equal (!=)ltzLess Than (<)gtzGreater Than (>)lezLess Than or Equal To (<=)gezGreater Than or Equal To (>=)	icontainsContainsc                       e Zd ZdZg dZg dZ ej                  dd      Z ej                  dd	      Z	 ej                  de
d
      Z ej                  d      Z ej                  d ed            Z ej                  dd      Z ej                  de      Z ej$                  eej(                  dd      Z ej,                  ed ed            Z ej                  dde ed            Z ej,                  edd      Z ej                  dd      Z ej                  dd      Z ej                         Zg dZ fdZd e fd!Z!d" Z"d# Z#d$ Z$d% Z%d& Z&d' Z'd( Z(d) Z) xZ*S )*MailAutomationz
    MailAutoMation
    ))	on_createz	On Create)	on_updatez	On Update)	on_deletez	On Delete))emailzSend as Email)notificationzSend as Notification)bothzSend as Email and Notification   T)
max_lengthuniqued   F)r   editable)r   choicesnullzMail to/Notify to)verbose_name   zcFill mail template details(reciever/instance, `self` will be the person who trigger the automation))r   	help_text )defaultr    
   )r   r!   )r   r"   blankzAlso Send to)r)   r#   r   2   zChoose Delivary Channel)r'   r   r!   r#   template_attachment)related_namer)   )r"   r    )condition_html	conditioncondition_querystringc                     | j                   s/| j                  j                  dd      j                         | _        t        |   |i |S )N _)pktitlereplacelowermethod_titlesupersave)selfargskwargs	__class__s      >/var/www/python-projects/worksol/horilla_automations/models.pyr9   zMailAutomation.saveT   s@    ww $

 2 23 < B B DDw|T,V,,    returnc                     | j                   S )Nr4   r:   s    r>   __str__zMailAutomation.__str__Y   s    zzr?   c                 &    d| j                    d}|S )zV
        Method will retun the api to the avatar or path to the profile image
        z!https://ui-avatars.com/api/?name=z&background=randomrB   )r:   urls     r>   
get_avatarzMailAutomation.get_avatar\   s     2$**=OP
r?   c                 0   t        | j                        }g }|D ]l  }|j                  d      }d}|D ]<  }|j                  dd      j                  dd      }|j	                         }|| dz   }> |dd }|j                  |       n t        d	| |d
      S )zS
        method that returns the display value for `mail_to`
        field
        __r&   _idr2   r1   z >Nz horilla_automations/mail_to.html)instancemappings)r   mail_tosplitr5   
capitalizeappendr   )r:   rN   rM   mappingdisplayrO   s         r>   get_mail_to_displayz"MailAutomation.get_mail_to_displayd   s    
  - 	%GmmD)GG  1eR088cB((*!ugRL01 crlGOOG$	% .Tx0X
 	
r?   c                 R    | j                   j                         }t        dd|i      S )Nz horilla_automations/mail_cc.html	employees)also_sent_toallr   )r:   rV   s     r>   get_mail_cc_displayz"MailAutomation.get_mail_cc_displayx   s-    %%))+	.i0H
 	
r?   c                 4    t        dd| j                  i      S )Nzautomation-detailed-viewr3   r<   r   r3   rC   s    r>   detailed_urlzMailAutomation.detailed_url~   s    14/JJr?   c                     t        dd| i      S )Nz#horilla_automations/conditions.htmlrL   r
   rC   s    r>   
conditionszMailAutomation.conditions   s    1J3E
 	
r?   c                 4    t        dd| j                  i      S )Nzdelete-automationr3   r[   r\   rC   s    r>   
delete_urlzMailAutomation.delete_url   s    *D$''?CCr?   c                 4    t        dd| j                  i      S )z
        Edit url
        zupdate-automationr3   r[   r\   rC   s    r>   edit_urlzMailAutomation.edit_url   s     *D$''?CCr?   c                 "    | j                         S )r&   )get_trigger_displayrC   s    r>   trigger_displayzMailAutomation.trigger_display   s    ''))r?   )+__name__
__module____qualname____doc__r!   SEND_OPTIONSr   	CharFieldr4   r7   MODEL_CHOICESmodel	TextFieldrN   r2   mail_detailsmail_detail_choicetrigger
ForeignKeyr   CASCADEmail_templateManyToManyFieldr   rW   delivery_channeltemplate_attachmentsr-   r/   r.   xss_exempt_fieldsr9   strrD   rG   rT   rY   r]   r_   ra   rc   rf   __classcell__)r=   s   @r>   r   r      s   G
L FD9E#6##sUCLF]OEf,?@G#6##q
L *))"uEf"g>G &F%%v~~DM *6))~&L
 (v''01	 2611*
 &V%%4%@N,F,,$G   "I-
 
(
K

DD*r?   r   N)	django.dbr   django.urlsr   django.utils.translationr   r2   base.methodsr   base.modelsr   employee.modelsr   horilla.modelsr	   horilla_views.cbv_methodsr   rm   
CONDITIONSr    r?   r>   <module>r      s      6 & + $ ' 5 ao#$%	1_	1 !	1)*+	1,-.!J- 
y*\ y*r?   