U
    Vc                     @   s0   d dl mZmZ d dlT G dd dejjZdS )    )commit_all_dsrollback_all_ds)*c                   @   sP   e Zd ZdZejjdd Zejjdd Zejjdd Z	ejjdd	 Z
d
S )	FormsViewz
/pub/formsc                 C   s*   t jjtjd dddgd}| jd|dS )NtokenZsuccess_text
title_text
custom_cssfieldszwebform_success.htmlformmodelsCmfFormgetrequestargsZrender_with_paramsselfr    r   ./modules/crm/views/forms.pysuccess   s    zFormsView.successc                 C   s*   t jjtjd dddgd}| jd|dS )Nr   Zfailure_textr   r   r	   zwebform_failure.htmlr   r   r   r   r   r   failure   s    zFormsView.failurec                 C   s   t dtjd  dS )Nz/forms/r   z.html)redirectr   r   )r   r   r   r   r      s    zFormsView.getc              
   C   s  t jjddtjd gdgd}|rzJt j|jj|j|d}tjD ] }t	||r@t
||tj|  q@|  W nL tk
r } z.td t| tdtjd   W Y S d }~X Y nX |jd	r|jd
rtd|j t  tdtjd  S tdS )Nidz==r   z**)filterr
   )nameparentZchanneluB   Произошла ошибка при обработке лидаz?action=failure&token=Z723ad4b0z@carbonsoft.ruuE   Откатываем создание лида-автотеста %s.z?action=success&token=z?action=failure)r   r   r   r   r   ZCmfLeadr   r   r   hasattrsetattrZsave	ExceptionZloggingZ	exceptionr   r   Zlead_email_name
startswithendswithZwarningr   )r   r   ZleadZ
field_nameer   r   r   post   s"    


*zFormsView.postN)__name__
__module____qualname__Z__url__cmfviewsactionr   r   r   r$   r   r   r   r   r      s   


r   N)Zcmf.data_providers.baser   r   Zcmf.includer(   r)   ZBaseViewr   r   r   r   r   <module>   s   