
    Bh                        d dl Z d dlZd dl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mZ d dlmZ d dlmZmZ d d	lmZmZmZmZ d d
lmZ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*m+Z, d dl-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@ d dlAmBZB d dlCmDZDmEZE d dlFmGZGmHZHmIZI d dlJmKZK d d lLmMZM d d!lNmOZO d d"lPmQZQmRZR d d#lSmTZTmUZUmVZV d d$lWmXZXmYZYmZZZ  e[       Z\e\fd%Z]d& Z^ G d' d(      Z_ G d) d*e_      Z` G d+ d,ej                        Zb G d- d.eb/      Zc e	j                  e:       G d0 d1e_e	j                               Zfy)2    N)	parse_qslurlparse)formsadmin)	AdminForm)flatten_fieldsetsget_deleted_objectsPermissionDenied)modelstransaction)HttpResponseHttpResponseBadRequestHttpResponseForbiddenHttpResponseNotFound)get_list_or_404get_object_or_404)TemplateResponse)includere_path)MultiValueDict)method_decorator)	force_str)conditional_escape)get_language_from_pathgettext)xframe_options_sameorigin)require_POST)
operations)PluginAddValidationForm)SLUG_REGEXP)PluginLimitReached)Placeholder)PlaceholderReference)	CMSPlugin)CMSPluginBase)plugin_pool)post_placeholder_operationpre_placeholder_operation)create_child_plugin_referencesget_plugin_contentget_plugin_tree)get_current_site)RemovedInDjangoCMS51Warning)get_cms_setting)get_language_codeget_language_list)copy_plugins_to_placeholderdowncast_pluginshas_reached_plugin_limit)render_object_editrender_object_previewrender_object_structurec                 d    |t         k(  rt        |       S 	 t        |       S # t        $ r |cY S w xY w)u  
    For convenience a get-like method for taking the int() of a string.
    :param int_str: the string to convert to integer
    :param default: an optional value to return if ValueError is raised.
    :return: the int() of «int_str» or «default» on exception.
    )_no_defaultint
ValueError)int_strdefaults     J/home/dcms/DCMS/lib/python3.12/site-packages/cms/admin/placeholderadmin.pyget_intr@   :   s9     +7|	w< 	N	s   
! //c                 P    t        |j                  |      }t        | |      }||k7  S )z\
    Returns True if instance overrides a method (method_name)
    inherited from base.
    )getattr	__class__)baseinstancemethod_namebound_methodunbound_methods        r?   _instance_overrides_methodrI   J   s-    
 8--{;LT;/N\))    c                        e Zd ZdZed        Zy)BaseEditableAdminMixinzX
    Base class for FrontendEditableAdminMixin to be reused by
    PlaceholderAdmin
    c                    | j                  ||      }|j                  j                  }d}|j                  j	                  dd      }|j
                  j	                  d      }| j                  |      }	t        |	dg       }
|j                  d      D cg c]	  }||
v s| }}|s|t        d      |z  d}t        |d|      S |j                  j                  |	j                  j                  j                   d	|	j                  j                  j                         s|t        d
      d}t        |d|      S |	j!                  |||      }|s]|j"                  dk(  rN |||j                        }|j%                         r3|j'                  d      }|	j)                  |||d       d}n	 ||      }t+        |dd|ifgi |       }|	j,                  |j,                  z   }t/        d      |j0                  dd|dd||ddddd}|rd|d<   t        |d|      S |s5|j"                  dk(  r&|r$t3        |	t4              r|	j7                  ||d      S t        |d|      S c c}w )z/Endpoint which manages frontend-editable fieldsF_canceledit_fieldsfrontend_editable_fields,zField %s not found)optsmessagez%admin/cms/page/plugin/error_form.htmlz.change_z,You do not have permission to edit this item)fieldsPOST)rE   data)commitT)change)rE   NrT   )	fieldsetsprepopulated_fieldsmodel_admin	MEDIA_URL
   )CMS_MEDIA_URLtitleplugin	plugin_id	adminformaddis_popupmediarR   rX   save_ashas_add_permissionwindow_close_timeoutcancel'admin/cms/page/plugin/confirm_form.htmlrX   )actionz&admin/cms/page/plugin/change_form.html)_get_object_for_single_fieldrC   _metarU   getGET_get_model_adminrB   split_r   userhas_permmodel	app_label
model_nameget_formmethodis_validsave
save_modelr   re   r0   verbose_name
isinstancer'   render_close_frame)selfrequest	object_idlanguageobjrR   saved_successfullycancel_clicked
raw_fields	admin_objallowed_fieldsfieldrT   context
form_classform
new_object
admin_formre   s                      r?   
edit_fieldz!BaseEditableAdminMixin.edit_fieldY   s    //	8D}}""" )))U;[[__]3
))#.	 ,FK%/%5%5c%:VEe~>U%VV12Z?G $G-TV]^^||$$	(=(=(G(G'HQZQ`Q`QfQfQqQqPr%stKLG $G-TV]^^ ''V'D
'..F":s>D}}!YYeY4
$$Wj$t$L%)"s+Dt&7I0J/Kac+/1
*"2"22,[9&&#"'$&
  $GH#G-VX_``'..F":?QV`ajlyVz//X/NN)QSZ[[c Ws   	IIN)__name__
__module____qualname____doc__r   r    rJ   r?   rL   rL   T   s     :\ :\rJ   rL   c                        e Zd ZdZdee   f fdZdej                  de	j                  fdZdededej                  fdZ xZS )	FrontendEditableAdminMixinz
    Adding ``FrontendEditableAdminMixin`` to  models admin class allows to open that admin
    in the frontend by double-clicking on fields rendered with the ``render_model`` template
    tag.
    returnc                       j                   j                  j                   d j                   j                  j                    fd} |dt        z   j
                        g}|t                  z   S )z:
        Register the url for the edit field view
        rr   c                 p    t        | j                  j                  |       d|j                         S Nrr   )namer   
admin_site
admin_viewr   regexfninfor   s     r?   patz0FrontendEditableAdminMixin.get_urls.<locals>.pat   4    5$//"<"<R"@$qQSQ\Q\P]G^__rJ   zedit-field/(%s)/([a-z\-]+)/$)ru   rm   rv   rw   r"   r   superget_urls)r   r   url_patternsr   rC   s   `  @r?   r   z#FrontendEditableAdminMixin.get_urls   so     **"",,-Qtzz/?/?/J/J.KL	` /+=tO
 eg.000rJ   r   c                     | S Nr   r   r   s     r?   rp   z+FrontendEditableAdminMixin._get_model_admin   s	     rJ   r   r   c                     	 | j                   j                  }	 |j	                  |      j                  |      S # t        $ r | j                   j                  }Y Cw xY w# t        $ r |j                  |      cY S w xY wNpk)ru   admin_managerAttributeErrorobjectsr   rn   )r   r   r   managers       r?   rl   z7FrontendEditableAdminMixin._get_object_for_single_field   s{    	)jj..G	-##H-11Y1??	  	)jj((G	)
  	-;;);,,	-s    :  A AAA=<A=)r   r   r   r   liststrr   r   Modelr   
ModelAdminrp   r;   rl   __classcell__rC   s   @r?   r   r      sS    
1$s) 1FLL U5E5E 
-c -S -V\\ -rJ   r   c                        e Zd Z fdZ xZS )PlaceholderAdminMixinBasec                     t         |   }|D cg c]  }t        |t              s| }}|s || |||      S t	        j
                  dt        d        || |||      S c c}w )NzTPlaceholderAdminMixin is no longer needed and thus will be removed in django CMS 5.0   )
stacklevel)r   __new__r~   r   warningswarnr/   )clsr   basesattrs	super_newbparentsrC   s          r?   r   z!PlaceholderAdminMixinBase.__new__   sk    GO	#Pz!5N'O1PPS$u55b'	

 dE511 Qs
   A A )r   r   r   r   r   r   s   @r?   r   r      s    2 2rJ   r   c                       e Zd ZdZy)PlaceholderAdminMixinzt
    .. warning::

        PlaceholderAdminMixin is deprecated. It is no longer needed and thus will be removed
    N)r   r   r   r   r   rJ   r?   r   r      s    
 	rJ   r   )	metaclassc                      e Zd ZdZd Zd*dZd*dZd Zd*dZde	e
   fd	Zd
ede
defdZdedej                   fdZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd*dZd Ze d        Z! e"e#      e e$jJ                  d                      Z&d Z'd  Z(d! Z)e d"        Z* e"e#      e e$jJ                  d#                      Z+	 d*d$Z,d% Z-d+d&Z.d' Z/e d(        Z0e d)        Z1y),PlaceholderAdminztPlaceholder admin manages placeholders and their plugins, as well as the preview, edit, and
    structure endpoints.c                      yNFr   r   r   s     r?   rg   z#PlaceholderAdmin.has_add_permission       rJ   Nc                      yr   r   r   r   r   s      r?   has_change_permissionz&PlaceholderAdmin.has_change_permission   r   rJ   c                      y)NTr   r   s      r?   has_delete_permissionz&PlaceholderAdmin.has_delete_permission   s     rJ   c                      yr   r   r   s     r?   has_module_permissionz&PlaceholderAdmin.has_module_permission   r   rJ   c                     t         r   r   )r   r   r   extra_contexts       r?   delete_viewzPlaceholderAdmin.delete_view   s
     rJ   r   c                      j                   j                  j                   d j                   j                  j                    fd}t	        dt        d             |d j                         |d j                         |d j                         |d j                         |d	 j                         |d
 j                         |d j                         |dt               |dt               |dt              g}|S )zO
        Register the plugin specific urls (add/edit/copy/remove/move)
        rr   c                 p    t        | j                  j                  |       d|j                         S r   r   r   s     r?   r   z&PlaceholderAdmin.get_urls.<locals>.pat   r   rJ   z^cms_wizard/zcms.wizards.urlsz^copy-plugins/$z^add-plugin/$z^edit-plugin/([0-9]+)/$z!^edit-field/([0-9]+)/([a-z\-]+)/$z^delete-plugin/([0-9]+)/$z^clear-placeholder/([0-9]+)/$z^move-plugin/$z ^object/([0-9]+)/edit/([0-9]+)/$z%^object/([0-9]+)/structure/([0-9]+)/$z#^object/([0-9]+)/preview/([0-9]+)/$)ru   rm   rv   rw   r   r   copy_plugins
add_pluginedit_pluginr   delete_pluginclear_placeholdermove_pluginr6   r8   r7   )r   r   r   r   s   `  @r?   r   zPlaceholderAdmin.get_urls   s     **"",,-Qtzz/?/?/J/J.KL	` OW-?%@A"D$5$56 $//2*D,<,<=4dooF,d.@.@A0$2H2HI!4#3#3435GH8:QR68MN
 rJ   r   r   c                 D    t        t        |      }|j                         S r   )r   r&   get_bound_plugin)r   r   r   r`   s       r?   rl   z-PlaceholderAdmin._get_object_for_single_field	  s     #9;&&((rJ   r   c                 :    |j                  | j                        S )Nr   )get_plugin_class_instancer   r   s     r?   rp   z!PlaceholderAdmin._get_model_admin  s     ,,4??,CCrJ   c                     t               }t        |j                  d         }t        t	        |j
                              }|j                  d      }|st        |j                        }t        ||j                        S )Ncms_pathr   )site_id)r.   r   ro   dictr   queryrn   r   pathr1   r   )r   r   site
parsed_urlqueriesr   s         r?   _get_operation_languagez(PlaceholderAdmin._get_operation_language  sd    
  !gkk*56
y!1!123;;z*-joo>H 477;;rJ   c                 F    t        |j                  d         j                  S )Nr   )r   ro   r   r   s     r?   _get_operation_originz&PlaceholderAdmin._get_operation_origin#  s    J/0555rJ   c                 6   t        t        j                               }|j                  j	                  d      st        j                  dt               |S t        j                  d| j                  ||| j                  |      || j                  |      d| |S )Nr   zAll custom placeholder admin endpoints require a "cms_path" GET query which points to the path where the request originates from.This backwards compatible shim will be removed on 3.5 and an HttpBadRequest response will be returned instead.sender	operationr   r   tokenoriginr   )r   uuiduuid4ro   rn   r   r   UserWarningr*   sendrC   r   r   )r   r   r   kwargsr   s        r?   _send_pre_placeholder_operationz0PlaceholderAdmin._send_pre_placeholder_operation&  s    DJJL!{{z*MM U
 &' L!&& 	
>>11':--g6	
 	
 rJ   c                     |j                   j                  d      sy t        j                  d| j                  ||| j                  |      || j                  |      d| y )Nr   r   r   )ro   rn   r)   r   rC   r   r   )r   r   r   r   r   s        r?    _send_post_placeholder_operationz1PlaceholderAdmin._send_post_placeholder_operation=  s^    {{z*"'' 	
>>11':--g6	
 	
rJ   c                     t         j                  j                  dd      }t        ||      d   }t	        j
                  |      }|j                         j                  dd      }t        ||      S )Nplugin_typeTflatr   r   parentplaceholder)	r&   r   values_listr   r(   
get_pluginget_render_querysetselect_relatedr   )r   ra   querysetr  plugin_classreal_querysets         r?   _get_plugin_from_idz$PlaceholderAdmin._get_plugin_from_idL  sg    $$00T0J%h9=a@"--k:$88:II(Tab 9==rJ   c                 :    |j                  |j                  |      S r   )has_add_plugin_permissionrs   )r   r   r  r  s       r?   r  z*PlaceholderAdmin.has_add_plugin_permissionT  s    44W\\;OOrJ   c                 R    |j                   }|j                  |j                  |      S r   )r  has_change_plugin_permissionrs   r   r   r`   r  s       r?   r  z-PlaceholderAdmin.has_change_plugin_permissionW  $    ((77fMMrJ   c                 R    |j                   }|j                  |j                  |      S r   )r  has_delete_plugin_permissionrs   r  s       r?   r  z-PlaceholderAdmin.has_delete_plugin_permission[  r  rJ   c                 f    |j                   j                  }|j                  |j                  |      S r   )toolbar	clipboardhas_add_plugins_permissionrs   )r   r   pluginsr  s       r?   has_copy_plugins_permissionz,PlaceholderAdmin.has_copy_plugins_permission_  s(    oo//55gllGLLrJ   c                 :    |j                  |j                  |      S r   r  rs   )r   r   r  r  s       r?   "has_copy_from_clipboard_permissionz3PlaceholderAdmin.has_copy_from_clipboard_permissiond  s    55gllGLLrJ   c                 t    |j                  |j                  |      sy|j                  |j                  |      S r   r  )r   r   source_placeholdertarget_placeholderr  s        r?   $has_copy_from_placeholder_permissionz5PlaceholderAdmin.has_copy_from_placeholder_permissiong  s0    !<<W\\7S!<<W\\7SSrJ   c                 T    |j                   }|j                  |j                  ||      S r   )r  has_move_plugin_permissionrs   )r   r   r`   r"  r  s        r?   r%  z+PlaceholderAdmin.has_move_plugin_permissionl  s'    ((55gllFL^__rJ   c                     |r|g}n9|j                   j                  dd      j                         j                         }|j	                  |j
                  |      S )Nr   Tr  )cmsplugin_setr  distinctorder_byhas_clear_permissionrs   )r   r   r  r   	languagess        r?    has_clear_placeholder_permissionz1PlaceholderAdmin.has_clear_placeholder_permissionp  sP    !
I
 Zd3  //iHHrJ   c                      y r   r   )r   r   r  s      r?   get_placeholder_templatez)PlaceholderAdmin.get_placeholder_template  s    rJ   c                 >   t        |j                        }|j                         sFt        |j                  j                               d   d   }t        t        t        |                  S |j                  }|d   }|d   }| j                  |||      st        d      }t        |      S |j                  |j                        st        d      }t        |      S t        j                   |      } ||j"                  | j$                        }	|d   |d   |j'                  dd      |d   |d   d	|	_        |j*                  d
k(  r|j,                  s|	j/                  |d      }
t1        |
      } |	j3                  |dd|             }t5        |j6                  j9                         D ci c]Z  \  }}t;        |dd      H||j<                  vr:|t?        |j@                  tB        t        f      r|j@                  n|j@                  g\ c}}      }|jE                  |j<                         ||_        |	jG                  |      }t;        |	dd      }|	jH                  r8| jK                  |tL        jN                  |	jH                  ||jP                         |S c c}}w )a"  
        Shows the add plugin form and saves it on POST.

        Requires the following GET parameters:
            - cms_path
            - placeholder_id
            - plugin_type
            - plugin_language
            - plugin_position
            - plugin_parent (optional)
        r   placeholder_idr  z*You do not have permission to add a pluginplugin_languageplugin_parentNplugin_position)r   r  r  r  positionrU   )r   F)rX   rT   initialsaved_object)r   r   r`   r  ))r!   ro   rz   r   errorsvaluesr   r   r   cleaned_datar  rr   r   check_sourcers   r(   r  ru   r   rn   _cms_initial_attributesry   show_add_formget_fieldsetsr	   rx   r   rT   itemsrB   rU   r~   r5  tupleupdateadd_view_operation_tokenr   r    
ADD_PLUGINr  )r   r   r   errorplugin_datar  r  rS   r  plugin_instancerY   rT   initial_formr   r   
query_dictresponser`   s                     r?   r   zPlaceholderAdmin.add_plugin  st    'w{{3}} ++-.q1!4E)*<Yu=M*NOO''!"23!-0--g{KPDEG(11''5DEG(11"--k:&|'9'94??K $$56&'78!ooot<&}5#$563
/ >>V#L,F,F (55g45HI&y1F_?33GT%X^3_aL (#/#6#6#<#<#>)D%5)T2>4w||C[ z%--%'OemmV[VcVcUdd) J gll+%GL"++G4.$?++11$//%66".. 2  +)s   ,AJ
c                 Z   |j                   d   }|j                   d   }|j                   d   }t        t        |      }t        t        |      }|r|t               vrt	        t        d            S |j                  |j                  j                  j                  k(  }|j                   j                  dd      }|r|r| j                  ||      }	|	g}
n,|r| j                  |||      }	|	g}
n| j                  |||      }
t        ||
      }t        t        j                   |      d	      S )
z
        POST request should have the following data:

        - cms_path
        - source_language
        - source_placeholder_id
        - source_plugin_id (optional)
        - target_language
        - target_placeholder_id
        source_placeholder_idtarget_languagetarget_placeholder_idr   z-Language must be set to a supported language!source_plugin_idNapplication/jsoncontent_type)rU   r   r$   r2   r   rr   r   r  r  rn   _copy_plugin_to_clipboard_copy_placeholder_to_clipboard_add_plugins_from_placeholderr-   r   jsondumps)r   r   rK  rL  rM  r!  r"  copy_to_clipboardrN  
new_pluginnew_pluginsrV   s               r?   r   zPlaceholderAdmin.copy_plugins  s/    !(-D E!,,'89 '-D E.{?TU.{?TU/9J9L"L)!,[*\]].11W__5N5N5Q5QQ"<<++,>E!177"J &,K<<""J
 &,K<<""K
 w4DJJt,;MNNrJ   c                    |j                   d   }|j                   j                  d      }|j                   d   }t        t        ||      }|gt	        |j                               z   }| j                  ||      st        d      }t        |      |j                  |j                        st        d      }t        |      |j                          t        |||      }	|	d   S )Nsource_languagerN  rL  )r   r   1You do not have permission to copy these plugins.r  r   r   )rU   rn   r   r&   r   get_descendantsr  rr   r   r:  rs   clearr3   )
r   r   r"  r[  rN  rL  source_pluginold_pluginsrS   copied_pluginss
             r?   rR  z*PlaceholderAdmin._copy_plugin_to_clipboard  s    !,,'89"<<++,>?!,,'89)$

 %o]-J-J-L(MM//EKLG"7++!..w||<KLG"7++ 	  "4*$

 a  rJ   c                    |j                   d   }|j                   d   }|j                  |      }| j                  ||      st        d      }t	        |      |j                  |j                        st        d      }t	        |      |j                          t        j                  j                  |j                         d||      }t        ||j                  |       |S )Nr[  rL  r   z4You do not have permission to copy this placeholder.PlaceholderPlugin)r   r  r   r  r]  )rU   get_plugins_listr  rr   r   r:  rs   r_  r%   r   create	get_labelr3   placeholder_ref)	r   r   r!  r"  r[  rL  ra  rS   	references	            r?   rS  z/PlaceholderAdmin._copy_placeholder_to_clipboard%  s    !,,'89!,,'89 )99?9S//ENOG"7++!..w||<NOG"7++ 	  " )0077#--/+$*	 8 
	 	$!11$	

 rJ   c                    |j                   d   }|j                   d   }|j                  |      }| j                  ||||      }|st        d      }t	        |      |j                  |j                        st        d      }t	        |      |j                  |d       }	| j                  |t        j                  ||||||	      }
t        |||      }d |D        }|j                  |       t        j                  j                  |      }t!        |      }| j#                  |t        j                  |
||||||			       |S )
Nr[  rL  rd  r\  )r   	parent_id)r   r  r[  r!  rL  r"  target_orderc              3   4   K   | ]  }|j                     y wr   r   .0news     r?   	<genexpr>zAPlaceholderAdmin._add_plugins_from_placeholder.<locals>.<genexpr>s  s     ;S#&&;   pk__in)r   r   r  r[  r!  rL  r"  rm  )rU   rf  r#  rr   r   r:  rs   get_plugin_tree_orderr   r    ADD_PLUGINS_FROM_PLACEHOLDERr3   clear_cacher&   r   filterr   r   )r   r   r!  r"  r[  rL  ra  has_permissionsrS   target_tree_orderoperation_tokenrb  new_plugin_idsrY  s                 r?   rT  z.PlaceholderAdmin._add_plugins_from_placeholderI  sq    ",,'89!,,'89(99?9S CC	
 KLG"7++!..w||<KLG"7++.DD$ E 

 >> ==+1+1* ? 	
 5[BT_no;N;&&7''..n.E;'-- ==!+1+1* 	. 
	
 rJ   c                    	 t        |      }| j	                  |      }|j                  | j                        }| j                  ||      st        t        d            S |j                  j                  |j                        st        d      }t        |      S |j                  |t        |            }t        |dd       }|r%|j                  j                  |j                          |j"                  r9| j%                  |t&        j(                  |j"                  |||j                         |S # t        $ r t        t        d            cY S w xY w)NzPlugin not foundr   z.You do not have permission to edit this pluginr6  )r   r   
old_pluginrX  r  )r;   r<   r   rr   r  r   r   r  r   r  r:  rs   change_viewr   rB   rx  r   rB  r   r    CHANGE_PLUGIN)r   r   ra   r   rF  rS   rI  r`   s           r?   r   zPlaceholderAdmin.edit_plugin  s0   	?II &&y1 77doo7N00#>(+[)\]]++GLL9HIG(11"..wIG.$?**6??;++11$22%66!".. 2  ?  	?'*<(=>>	?s   D1 1EEc           	         	 t        |j                  j                  d            }| j                  |      }|j                  j                  d      rUt        |j                  j                  d            }t        j                  j                  |      }|j                  |k7  sJ d}t        |j                  j                  dd            }t        |j                  j                  dd	      d      }|j                  d
   }|j                  j                  d      }	|	xr |	dk7  xr |	j                         dk7  }	||j                  j                  k(  }
|j                  }|r1||k7  r,	 | j                  ||      }t        ||j                   ||       |	 xr |
 }|rG|j&                  |k7  r8|xs |j                  }|rt)        t*        |||      }n#t)        t*        |      }n|r|j,                  }nd}d}d}|	r*|j                   dk(  rd}d}| j/                  |||||      }nc|	r| j1                  ||||||      }nI|
r%|j,                  }| j3                  ||||      }|g}n"|j,                  }| j5                  |||||      }|r/|r-|j,                  xs |}|gt7        |j9                               z   }t;        ||d         }|r^||vrZd|v rVt7        t=        |gt7        |j9                               z   d            }t?        |       |dxx   tA        ||d         z  cc<   d|v rLtC        |d         dkD  r;|d   jD                  |jD                  k(  |d   d   d<   |
r|d   jG                  d       |jD                  |d<   tI        tK        jL                  |      d      S # t        $ r t	        d      w xY w# t"        $ r}t%        |      cY d}~S d}~ww xY w)uy  
        Performs a move or a "paste" operation (when «move_a_copy» is set)

        POST request with following parameters:
        - plugin_id
        - placeholder_id
        - target_position (optional)
        - plugin_language (optional)
        - plugin_parent (optional)
        - plugin_order (array, optional)
        - move_a_copy (Boolean, optional) (anything supplied here except a case-
                                        insensitive "false" is True)
        NOTE: If move_a_copy is set, the plugin_order should contain an item
              '__COPY__' with the desired destination of the copied plugin.
        ra   z$'plugin_id' is a required parameter.r0  r   Ntarget_position0r2   rL  move_a_copyfalse)template)r   r   r  Tre  F)r`   rL  r"  r  )r`   target_parentrL  r"  r  )r`   rL  r"  )r`   r  r  r"  r   )target_plugincontent)select_placeholderinsertrK  rO  rP  )'r@   rU   rn   	TypeErrorRuntimeErrorr  r$   r   r0  r;   lowerr  r  r  r.  r5   r  r#   r   rl  r   r&   r  _paste_placeholder_paste_plugin_cut_plugin_move_pluginr   r^  r-   r4   r+   r,   lenr   popr   rU  rV  )r   r   ra   r`   r0  r  r  rl  rL  r  move_to_clipboardr!  r  ermove_a_plugin	target_plr  
old_parent
fetch_treerX  rY  rootrV   old_parent_pluginss                           r?   r   zPlaceholderAdmin.move_plugin  s   *	G 0 0 =>I )))4<<,-$W\\%5%56F%GHN%--11^1DK((N:::K gll../@#FGGLL,,_bA4H	!,,'89ll&&}5QK3.Q;3D3D3F'3Q 	 (7??+D+DD#//;*<<288+N(f6H6H)88M (A0A,A))Y6#9v'9'9I 1 , )	! !2)	 J"MMM M

6--1DDJJ11 /#. / 2 K +++ /#. / , J J)) /#.	 * J "(KJ**+ /#. + J *%%3D&4(<(<(>#??Kw;q>R*K7I<M!%&6
|d:KeKeKgFh7h  ~B  'C  "D*+=>O1';Ma;PQQOT)_!5!9+6q>+<+<		+IDOAx( Y##A&(:(=(=$%DJJt,;MNNY  	GEFF	G8 & 2-b112s)   $N* )+O *N?	O 
OO O c           	         |gt        |j                               z   }| j                  |||      st        d      }t	        |      |j                  |j                        st        d      }t	        |      |r|j                  }	nd }	| j                  |t        j                  ||||	      }
|j                  |j                        }|r,|j                  t        |      z   }|j                  |||       t!        ||||||i      }|d   }|j#                  |       |j%                          | j'                  |t        j                  |j)                         |
|||	       |S )Nz+You have no permission to paste this plugin)r   r`   rL  r"  target_parent_idstartoffset)r  r   root_pluginstart_positionsr   )r   r`   r   rL  r"  r  )r   r^  r  rr   r   r:  rs   r   r   r    PASTE_PLUGINget_last_pluginr   r4  r  _shift_plugin_positionsr3   rx  refresh_from_dbr   r   )r   r   r`   rL  r"  r  r  r  rS   r  action_tokentarget_last_plugintarget_offsetrY  r  s                  r?   r  zPlaceholderAdmin._paste_plugin1  s   (T&"8"8":;;66w@RT[\EFG"7++!..w||<EFG"7++,//#;; --+1- < 
 0??P.77#g,FM66%$ 7  2*$%,o>
 "!n&&7 	##%-- --//1+1- 	. 	
 rJ   c                    |j                   j                         }| j                  |||      st        d      }t	        |      |j                  |j                        st        d      }t	        |      | j                  |t        j                  |||      }|j                  |j                        }	|	r,|	j                  t        |      z   }
|j                  |||
       t        |||||i      }d |D        }|j!                  |j                         t"        j$                  j'                  |      j)                  d      }t+        |      }| j-                  |t        j                  ||||       |S )	Nz0You have no permission to paste this placeholder)r   r  rL  r"  r  )r  r   r  c              3   4   K   | ]  }|j                     y wr   r   ro  s     r?   rr  z6PlaceholderAdmin._paste_placeholder.<locals>.<genexpr>  s     8S#&&8rs  rt  r  )r   r   r  rL  r"  )ri  rf  r  rr   r   r:  rs   r   r    PASTE_PLACEHOLDERr  r   r4  r  r  r3   rx  r&   r   ry  r
  r   r   )r   r   r`   rL  r"  r  r  rS   r  r  r  rY  r}  s                r?   r  z#PlaceholderAdmin._paste_placeholderm  s{   ((99;66w@RT[\JKG"7++!..w||<JKG"7++;; 22+1 < 
 0??P.77#g,FM66%$ 7  2*$,o>	
 9K8&&v7 WV>V*^M*	 	 ;'-- 22+1 	. 	
 rJ   c                 d   |j                   }|j                  }| j                  |||      st        d      }t	        |      |r)| j                  |||      st        d      }t	        |      |j                  |j                        st        d      }t	        |      |r1|j                  |j                        st        d      }t	        |      |r|j                  }	nd }	| j                  |t        j                  ||j                   ||j                  ||xs ||		      }
|j                  ||||       |j                         }|r|j                  |       |j                  |       | j                  |t        j                  |j!                         |
|||j                  ||xs ||	
       |S )Nz*You have no permission to move this plugin)r   r`   r[  r!  source_parent_idrL  r"  r  )r`   r  r"  r  )	r   r`   r   r[  r!  r  rL  r"  r  )r   r  r%  rr   r   r:  rs   r   r   r    MOVE_PLUGINrl  r   reloadrx  r   r   )r   r   r`   r  r"  r  r   r!  rS   r  r  updated_plugins               r?   r  zPlaceholderAdmin._move_plugin  s   ??#//..w@RSDEG"7++d&E&EgvWi&jDEG"7++!..w||<DEG"7++&8&E&Egll&SDEG"7++,//#;; ,,"OO1#--$ 2 H6H- < 

 	&&+1'	 	' 	
  **84&&x0-- ,,!224$1+55$ 2 H6H- 	. 	
 rJ   c                    |j                   }| j                  |||      st        d      }t        |      |j	                  |j
                        st        d      }t        |      | j                  |t        j                  ||||j                  ||j                  g 	      }|j                          |j                  |d|d        |j                  |j                         |j                         }| j                  |t        j                  ||j!                         |||j                  ||j                  g 
       |S )Nz)You have no permission to cut this plugin)r   r`   r  clipboard_languager[  r!  r  source_order   )r  r"  r  )	r   r   r`   r  r  r[  r!  r  r  )r  r%  rr   r   r:  rs   r   r    
CUT_PLUGINr   rl  r_  r   rx  r  r   r   )	r   r   r`   rL  r"  r!  rS   r  r  s	            r?   r  zPlaceholderAdmin._cut_plugin  s=   #//..w@RSCDG"7++!..w||<CDG"7++;; ++(."OO1#-- < 

 	  "&&1	 	' 	
 	&&v7-- ++!224(."OO1#-- 	. 	
 rJ   c           	         | j                  |      }| j                  ||      st        d      }t        |      S |j                  j                  |j                        st        d      }t        |      |j                  }d|i}t        |gfd| j                  i|\  }}}	}
|j                  rA|	rt        t        d            t        |      }|j                  }|j                         }|j                  }|j                  |j                         }| j#                  |t$        j&                  |||      }|j)                  |       |j+                  |j                          | j-                  |t        d      t        |j.                        t        |      dz         | j1                  |t$        j&                  ||||       |j3                  ||d	t5        d
|j6                              S t        |j9                         j:                        }|	s|
rt        d      d|iz  }nt        d      }|||||	|
||j<                  d}| j                  j:                  |_        tA        |d|      S )Nz0You do not have permission to delete this pluginr   r   rd  )r   r`   r  
tree_orderz7The %(name)s plugin "%(obj)s" was deleted successfully.)r   r   )r   r   r`   r  r  deleteT)deletedra   )rk   
extra_dataCannot delete %(name)sr   Are you sure?r_   object_nameobjectdeleted_objectsperms_lacking	protectedrR   rv   .admin/cms/page/plugin/delete_confirmation.html)!r  r  rr   r   r  r:  rs   r   rm   r
   r   rU   r   r   r  rv  r   r   r    DELETE_PLUGINr   rx  message_userr}   r   r   r   r   get_plugin_classr   rv   current_appr   )r   r   ra   r`   rS   rR   %get_deleted_objects_additional_kwargsr  __perms_neededr  obj_displayr  plugin_class_instancer2  plugin_tree_orderr|  plugin_namer_   r   s                       r?   r   zPlaceholderAdmin.delete_plugin  s{   )))400&AJKG(11!!..w||<JKG"7++||1:G0D-7JH8
!%8
38
4\9
 <<&q)['\]]#F+K ,,K$*$D$D$F!"MMM + A A6?? A ["BB$22', C O %%f-##FOO4gq)b'c!$"3"34Y{=SgU (U V 11$22%', 2  );;		B	 < D D   7 7 9 > >?9./6;2GGEo&E&.)"	
 #oo22Ew
 	
rJ   c           	         t        t        |      }|j                  j                  d      }|j                  |j
                  j                  j                  k(  r.|j                  |       t        |dddd|j                  di      S | j                  |||      st        d      }t        |      S |j                  |j                        st        d      }t        |      t        j                  }|j!                  |      }d	|i}t#        |fd
| j$                  i|\  }	}
}}t'        |      }|j(                  r|rt        d      }t        |      S | j+                  |t,        j.                  ||      }|j                  |       |j1                  |       | j3                  |t        d      d|iz         | j5                  |t,        j.                  |||       t        |dddd|j                  di      S |s|rt        d      d|iz  }nt        d      }|t        d      ||	||||j6                  d}| j$                  j8                  |_        t        |d|      S )Nr   r   rj   data_bridger   T)rk   r  r0  z4You do not have permission to clear this placeholderr   r   )r   r  r  z3The placeholder "%(obj)s" was cleared successfully.r   )r   r   r  r  r  r   r  r  r  r  )r   r$   ro   rn   r   r  r  r_  r   r,  rr   r   r:  rs   r   rm   rf  r
   r   r   rU   r   r    CLEAR_PLACEHOLDERrx  r  r   rv   r   r  )r   r   r0  r  r   rS   rR   r  r  r  r  r  r  r  r|  r_   r   s                    r?   r   z"PlaceholderAdmin.clear_placeholderb  s   'G;;??:.>>W__66999
 h'#G-V1#&1nn Y   44Wk8TNOG(11''5NOG"7++  ..x81:G0D-7J8
 $8
38
4\9
  ,<<RS,W55"BB$66'	 C O h'##H-gq)^'_{c$ ($ % 11$66%' 2  $G-V1#&1nn Y   9./6;2GGEo&E ]+!.)"	
 #oo22)Y[bccrJ   r   )NN)2r   r   r   r   rg   r   r   r   r   r   r   r   r;   r&   rl   r   r   rp   r   r   r   r   r  r  r  r  r  r  r#  r%  r,  r.  r   r   r   r   r   atomicr   rR  rS  rT  r   r   r  r  r  r  r   r   r   rJ   r?   r   r      s   

$s) 0)c )S )Y )DI D%2B2B D
<6.
>PNNM
MT
`I R Rh l#+O   $+OZ!<"H<| " "H l#@O   $@OF JN:x7r>@.` I
 I
V Wd WdrJ   r   )grU  r   r   urllib.parser   r   djangor   django.contribr   django.contrib.admin.helpersr   django.contrib.admin.utilsr	   r
   django.core.exceptionsr   	django.dbr   r   django.httpr   r   r   r   django.shortcutsr   r   django.template.responser   django.urlsr   r   django.utils.datastructuresr   django.utils.decoratorsr   django.utils.encodingr   django.utils.htmlr   django.utils.translationr   r   rr   $django.views.decorators.clickjackingr   django.views.decorators.httpr   cmsr    cms.admin.formsr!   cms.constantsr"   cms.exceptionsr#   cms.models.placeholdermodelr$   !cms.models.placeholderpluginmodelr%   cms.models.pluginmodelr&   cms.plugin_baser'   cms.plugin_poolr(   cms.signalsr)   r*   cms.toolbar.utilsr+   r,   r-   	cms.utilsr.   cms.utils.compat.warningsr/   cms.utils.confr0   cms.utils.i18nr1   r2   cms.utils.pluginsr3   r4   r5   	cms.viewsr6   r7   r8   r  r:   r@   rI   rL   r   MediaDefiningClassr   r   registerr   r   r   rJ   r?   <module>r     s      ,    2 M 3 )  @ 5 ( 6 4 + 0 I J 5  3 % - 3 B , ) ' M a a & A * ? 
  h )  *@\ @\F$-!7 $-N2 8 8 2	&? 	 cd-u/?/? cd cdrJ   