
    h                        d dl 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 d d	lmZ d d
lmZ d dlmZ dZdZ e j:                  ee j<                        Z ee       ed      k\  Z e rdZ!ndZ!defdZ"de#de#fdZ$d/dede%de&fdZ'efdZ(d e%d!e#d"ee)e      de%fd#Z*d e%d$ed"e)e   de%fd%Z+d e%d$ed"e)e   de%fd&Z,d e%de%fd'Z-efd e%d(e%de%fd)Z.efd*Z/d+ Z0d, Z1d- Z2y# e$ r d dlmZ d dlmZ dZd.dZY w xY w)0    N)OrderedDict)WRAPPER_ASSIGNMENTSwraps)Optional)force_escape)Context)render_to_string)__version__	CMSPluginadmin_reverse)Modelreverse0c                 $    t        d|  |||      S )Nzadmin:r   )viewnameargskwargscurrent_apps       D/home/dcms/DCMS/lib/python3.12/site-packages/djangocms_text/utils.pyr   r      s    z*D&+FF    )Versionz5<cms-plugin .*?\bid="(?P<pk>\d+)".*?>.*?</cms-plugin>zB<cms-plugin .*?\bid="(?P<pk>\d+)".*?>(?P<content>.*?)</cms-plugin>)flagsz3.9999cms_placeholder_add_plugincms_page_add_pluginpluginc                 ~    t        t        |dd             r|j                         }| |d<   t        d||d         }|S )Nflattenr   z&cms/plugins/render_plugin_preview.htmlrequest)r!   )callablegetattrr    r	   )r   contextresponses      r   _render_cms_pluginr&   (   sJ    D12//#GH  0	"H
 Or   	view_funcreturnc                 <      fd} t         t              |      S )Nc                  &     | i |}d|_         |S )NT)_random_comment_exempt)r   r   r%   r'   s      r   wrapped_viewz+random_comment_exempt.<locals>.wrapped_viewE   s    d-f-*.'r   )assigned)r   r   )r'   r,   s   ` r   random_comment_exemptr.   A   s    
 :5%89,GGr   objcontentadminc                     t        | j                  t        | j                               |      }|r<| j	                         }t        |dd      }d}|rdnd|d<   |j                  |d<   ||z  S d	}||z  S )
N)idicon_altr0   text_editor_previewTz<cms-plugin render-plugin=%(preview)s alt="%(icon_alt)s" title="%(icon_alt)s" id="%(id)d" type="%(type)s">%(content)s</cms-plugin>truefalsepreviewtypezX<cms-plugin alt="%(icon_alt)s" title="%(icon_alt)s" id="%(id)d">%(content)s</cms-plugin>)r   pkr   get_instance_icon_altget_plugin_classr#   __name__)r/   r0   r1   plugin_attrsplugin_classr8   
plugin_tags          r   plugin_to_tagrA   M   s    66c779:L ++-,(=tDX 	 -4&Y+44V $$ p
$$r   c                 X      fd} |       D cg c]  }t        |       c}S c c}w )Nc               3      K   j                        D ](  } | j                         j                  d      }|s%| * y w)Nr:   )finditer	groupdictget)tag	plugin_idregextexts     r   _find_pluginsz-plugin_tags_to_id_list.<locals>._find_pluginsd   s=     >>$' 	 C++D1I		 s
   6AA)int)rJ   rI   rK   _ids   ``  r   plugin_tags_to_id_listrN   c   s$      !.0CH000s   'rJ   output_funcchild_plugin_instancesc                     ||D ci c]  }|j                   | c}nt        |       fd}t        j                  ||       S c c}w )z
    Convert plugin object 'tags' into the form for public site.

    context is the template context to use, placeholder is the placeholder name
    c                     	 t        | j                         d         }|   }d|j                  _         ||       S # t        $ r Y yw xY w)Nr:   T )rL   rE   _render_metatext_enabledKeyError)mrH   r/   rO   plugins_by_ids      r   _render_tagz)_plugin_tags_to_html.<locals>._render_tagy   sZ    		'AKKM$/0I	*C -1C)sA&&  	 	s   !> 	A
	A
)r:   get_plugins_from_textOBJ_ADMIN_REsub)rJ   rO   rP   r   rY   rX   s    `   @r   _plugin_tags_to_htmlr]   n   sN     )9OPvF*P-d3
' K..! Qs   Ar$   c                 *    fd}t        | ||      S )Nc                     t        |       S N)r&   )r/   matchr$   s     r   _render_pluginz0plugin_tags_to_user_html.<locals>._render_plugin   s    !#w//r   rO   rP   r]   rJ   r$   rP   rb   s    `  r   plugin_tags_to_user_htmlrf      s    0  .Yoppr   c                 *    fd}t        | ||      S )Nc                 8    t        |       }t        | |d      S )NT)r0   r1   )r&   rA   )r/   ra   plugin_contentr$   s      r   rb   z1plugin_tags_to_admin_html.<locals>._render_plugin   s    +C9S.EEr   rc   rd   re   s    `  r   plugin_tags_to_admin_htmlrj      s    F  .Yoppr   c                 $    d }t        | |d       S )Nc                 4    t        |       j                         S r`   )rA   strip)r/   ra   s     r   _strip_plugin_contentz0plugin_tags_to_db.<locals>._strip_plugin_content   s    S!''))r   rc   rd   )rJ   rn   s     r   plugin_tags_to_dbro      s    *  2G`deer   rI   c                     ddl m} |j                  j                  j	                               fd}|j                  ||       S )Nr   r   c                     	 t        | j                         d         }|   }|   }t        |      S # t        $ r Y yw xY w)Nr:   rS   )rL   rE   rV   rA   )rW   rH   new_idr   id_dictrX   s       r   _replace_tagz)replace_plugin_tags.<locals>._replace_tag   sT    	AKKM$/0IY'F"6*F V$$  	 		s   &4 	A A )
cms.modelsr   objectsin_bulkvaluesr\   )rJ   rs   rI   r   rt   rX   s    `   @r   replace_plugin_tagsry      s;    $%%--gnn.>?M
% 99\4((r   c                     ddl m} ddlm} t	        | |      }|j
                  j                  |      j                  d      } ||d      }|D ci c]  }|j                  | c}S c c}w )Nr   r   )downcast_plugins)pk__inplaceholderT)select_placeholder)	ru   r   cms.utils.pluginsr{   rN   rv   filterselect_relatedr:   )rJ   rI   r   r{   
plugin_idspluginsplugin_listr   s           r   rZ   rZ      sa    $2'e4J&&j&9HHWG"7tDK,78&FIIv888s   A)c                      t        d      S )z?Get the url for rendering a text-enabled plugin for the toolbar'djangocms_text_textplugin_render_pluginr    r   r   get_render_plugin_urlr      s    BCCr   c                      t        d      S )(Get the url for cancelling a plugin edit*djangocms_text_textplugin_revert_on_cancelr   r   r   r   get_cancel_urlr      s    EFFr   c                      t        d      S )r   &djangocms_text_textplugin_get_messagesr   r   r   r   get_messages_urlr      s    ABBr   )NNN)rS   F)3recollectionsr   	functoolsr   r   typingr   django.template.defaultfiltersr   django.templater   django.template.loaderr	   cmsr
   ru   r   cms.utils.urlutilsr   ModuleNotFoundErrordjango.db.modelsr   django.urlsr   packaging.versionr   OBJ_ADMIN_RE_PATTERN!OBJ_ADMIN_WITH_CONTENT_RE_PATTERNcompileDOTALLr[   	is_cms_v4r   r&   r"   r.   strboolrA   rN   listr]   rf   rj   ro   ry   rZ   r   r   r   r   r   r   <module>r      s   	 # 0  7 # 3G$0 & P $i !rzz.bii@ K GH$55	!=!6y 2	HX 	H( 	H%y %3 %D %, (4 1/s / /S[\`aj\kSl /qt /4q3 q qRVW`Ra qfi qqC q' qSWXaSb qgj qfC fC f :F )c )3 )# )( '3 9D
G
Cq  G3#KGGs   C/ /D	D	