o
    hq7                     @   s   d dl Z d dl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 e dZG d	d
 d
eZG dd deZG dd dZdS )    N)PermissionDenied)get_all_child_relations)log)_copy_copy_m2m_relations)TranslatableMixin)page_publishedwagtailc                   @      e Zd ZdZdS )CopyPageIntegrityErrorzS
    Raised when the page copy cannot be performed for data integrity reasons.
    N__name__
__module____qualname____doc__ r   r   Y/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/actions/copy_page.pyr          r   c                   @   r
   )CopyPagePermissionErrorzX
    Raised when the page copy cannot be performed due to insufficient permissions.
    Nr   r   r   r   r   r      r   r   c                   @   sV   e Zd ZdZ										dddZdd	 Zdd
dZ	dddZdddZdS )CopyPageActionz&
    Copies pages and page trees.
    NFTwagtail.copyc                 C   sL   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
i | _d S )N)pagetoupdate_attrsexclude_fields	recursivecopy_revisions	keep_liveuserprocess_child_object
log_actionreset_translation_key_uuid_mapping)selfr   r   r   r   r   r   r   r   r   r    r!   r   r   r   __init__$   s   
zCopyPageAction.__init__c                 C   s"   || j vrt | j |< | j | S )z
        Generates a new UUID if it isn't already being used.
        Otherwise it will return the same UUID if it's already in use.
        )r"   uuiduuid4)r#   old_uuidr   r   r   generate_translation_keyA   s   

z'CopyPageAction.generate_translation_keyc                 C   s   | j jjr	td| jr"| jr"| jj| j jks| j| j r"td| jrU|sW| j}|d u r3| j 	 }| j 
| j|| jsCtd| jrY| j
| j}| s[tdd S d S d S d S )Nz%Page.copy() called on an unsaved pagez5You cannot copy a tree branch recursively into itselfz,You do not have permission to copy this pagez?You do not have permission to publish a page at the destination)r   _stateaddingr   r   r   idis_descendant_ofr   
get_parentpermissions_for_usercan_copy_tor   r   can_publish_subpage)r#   skip_permission_checksr   destination_permsr   r   r   checkK   s:   


zCopyPageAction.checkc           "      C   s  |j }|j|j |pg  }| jrdd i}n	ddd d d d d}| jr&| j|d< | jr/t |d< |r6|| t	|||d\}}	|	
 D ] \\}
}}| jrT| |||
| | jrct|trc| |j|_qC|rw|d |_|d	 |_|jdd
 n|r|j|d}n|j|d}|j|jf}t||||d | jr(|j D ]}|j|jk}d |_d |_|j|_|j}|j|d< t|D ]D}
|
  }z|| }W n	 t!y   Y qw |D ]+}|j||
j"j#< |	$|
|d f}|r|jnd |d< | jrd|v r| |d |d< qq|jD ]}||v rt%||rt&||d ||< q||_|  |r'||_'q|( }|r?|
 D ]\}}t)||| q3|j*| jddd}||_'| jrc||_+|j,|_-|j,|_.|jdg dd |j/rpt0j1|j2||d | j3r|4 }t5|| j3| j|j|6 |j7|j8j9dd|r|j|j:6 dnd |r|j|j:6 dnd |j/o| j|j7|j8j9ddd |j/r| jrt5|d| j|d t;<d|j=|j|j ddl>m?}m@} | jArd}|B   C D ] }|d	 d	 }|D|d |||f}|d	7 }| jE|||d q|dkr||_F|jddgd |r#|G }n| jH4 G }|I sR| jHjJ D ]} || jK| jL|d}!|!j| jd |!jMN| jM  q5|S )Nalias_ofFT)livehas_unpublished_changeslive_revisionfirst_published_atlast_published_atr4   ownertranslation_key)r   r   r      )clean)instancepk)r   changedr=   )r7   r9   r8   )r=   update_fields)senderr>   revision)r+   language_code)r+   titlelocale)r+   rE   )r   sourcedestinationr   source_locale)r>   actionr   datazwagtail.publish)r>   rJ   r   rC   zPage copied: "%s" id=%d from=%d)PagePageViewRestriction)r   _mpnode_attrsnumchild)restriction_typepasswordr   )r   )Ospecificdefault_exclude_fields_in_copyexclude_fields_in_copyr   r   r!   r%   r&   updater   itemsr   
isinstancer   r(   r;   pathdepthsave	add_childadd_siblingr   r   	revisionsallr?   latest_revision_idapproved_go_live_atr+   	object_idcontentr   get_accessor_nameKeyErrorfieldnamegethasattrgetattrlatest_revisionget_latest_revision_as_objectsetattrsave_revisionr7   
created_atr9   r8   r5   r   sendspecific_classr    r-   r   get_admin_display_title	locale_idrF   rD   specific_deferredloggerinforE   wagtail.modelsrL   rM   r   get_childreniterator	_get_path
_copy_pagerO   get_view_restrictionsr   existsview_restrictionsrP   rQ   groupsset)"r#   r   r   r   r   rN   specific_pagebase_update_attrs	page_copychild_object_mapchild_relationold_pkchild_objectrC   use_as_latest_revisionrevision_contentaccessor_namechild_objectscopied_child_objectexclude_fieldrj   re   value latest_revision_as_page_revisionparentrL   rM   rO   
child_pagenewdepthchild_mpnode_attrsparent_page_restrictionview_restrictionview_restriction_copyr   r   r   rz   n   sx  	







	 



zCopyPageAction._copy_pagec                 C   s&   | j |d | j| j| j| j| jdS )N)r1   )r   r   r   )r3   rz   r   r   r   r   )r#   r1   r   r   r   executep  s   zCopyPageAction.execute)
NNNFTTNNr   T)F)NNNN)	r   r   r   r   r$   r(   r3   rz   r   r   r   r   r   r      s(    


$
  r   )loggingr%   django.core.exceptionsr   modelcluster.modelsr   wagtail.log_actionsr   wagtail.models.copyingr   r   wagtail.models.i18nr   wagtail.signalsr   	getLoggerrt   RuntimeErrorr   r   r   r   r   r   r   <module>   s    
