o
    h$                     @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZ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)log)_copy_copy_m2m_relations)TranslatableMixinwagtailc                   @      e Zd ZdZdS )CreatePageAliasIntegrityErrorza
    Raised when creating an alias of a page cannot be performed for data integrity reasons.
    N__name__
__module____qualname____doc__ r   r   \/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/actions/create_alias.pyr	          r	   c                   @   r   )CreatePageAliasPermissionErrorzf
    Raised when creating an alias of a page cannot be performed due to insufficient permissions.
    Nr
   r   r   r   r   r      r   r   c                	   @   sH   e Zd ZdZdddddddddddZdd	d
Zdd ZdddZdS )CreatePageAliasActionaC  
    Creates an alias of the given page.

    An alias is like a copy, but an alias remains in sync with the original page. They
    are not directly editable and do not have revisions.

    You can convert an alias into a regular page by setting the .alias_of attribute to None
    and creating an initial revision.

    :param recursive: create aliases of the page's subtree, defaults to False
    :type recursive: boolean, optional
    :param parent: The page to create the new alias under
    :type parent: Page, optional
    :param update_slug: The slug of the new alias page, defaults to the slug of the original page
    :type update_slug: string, optional
    :param update_locale: The locale of the new alias page, defaults to the locale of the original page
    :type update_locale: Locale, optional
    :param user: The user who is performing this action. This user would be assigned as the owner of the new page and appear in the audit log
    :type user: User, optional
    :param log_action: Override the log action with a custom one. or pass None to skip logging, defaults to 'wagtail.create_alias'
    :type log_action: string or None, optional
    :param reset_translation_key: Generate new translation_keys for the page and any translatable child objects, defaults to False
    :type reset_translation_key: boolean, optional
    FNzwagtail.create_aliasT	recursiveparentupdate_slugupdate_localeuser
log_actionreset_translation_key_mpnode_attrsc          
      C   s:   || _ || _|| _|| _|| _|| _|| _|| _|	| _d S )N)	pager   r   r   r   r   r   r   r   )
selfr   r   r   r   r   r   r   r   r   r   r   r   __init__7   s   
zCreatePageAliasAction.__init__c                 C   sb   | j p| j }| jr|| jks|| jrtd| jr+|s-|| j s/t	dd S d S d S )Nz5You cannot copy a tree branch recursively into itselfz?You do not have permission to publish a page at the destination)
r   r   
get_parentr   is_descendant_ofr	   r   permissions_for_usercan_publish_subpager   )r   skip_permission_checksr   r   r   r   checkN   s    zCreatePageAliasAction.checkc                C   sf  |j }
g d}||j|j d}|r||d< |r||d< |r"||d< |r*t |d< t|
||d\}}| D ]}t|trJ|rC||_	|rJt |_
q7|	r^|	d |_|	d	 |_|jd
d n|rg|j|d}n|j|d}|j|jf}	t|
||d |r|
 }t||||j| d|r|j|j dnd |r|j|j dnd dd td|j|j|j ddlm}m} |rd}|    D ]%}|	d	 d	 }||	d |||f}|d	7 }| j|d|d |||||d	 q|dkr||_|jd
dgd |r|  }n|   }|! s1|j"# D ]}||j$|j%|d}|j| j&d |j'(|j'#  q|S )N)idpathdepthnumchildurl_pathr'   index_entriespostgres_index_entries)alias_ofdraft_titlehas_unpublished_changessluglocaleownertranslation_key)update_attrsexclude_fieldsr      F)clean)instance)r5   )r&   title)r   sourcedestination)r8   actionr   dataz&Page alias created: "%s" id=%d from=%d)PagePageViewRestrictionTr   r)   )r7   update_fields)restriction_typepasswordr   )r   ))specificr9   liveuuiduuid4r   values
isinstancer   r1   r3   r'   r(   save	add_childadd_siblingr   r    r   r&   get_admin_display_titlespecific_deferredloggerinfowagtail.modelsr>   r?   get_childreniterator	_get_path_create_aliasr)   get_view_restrictionsexistsview_restrictionsallrA   rB   r   groupsset)r   r   r   r   r   r   r   r   r   r   specific_pager5   r4   aliaschild_object_mapchild_objectsource_parentr>   r?   r)   
child_pagenewdepthchild_mpnode_attrsparent_page_restrictionview_restrictionview_restriction_copyr   r   r   rT   `   s   






z#CreatePageAliasAction._create_aliasc                 C   s:   | j |d | j| j| j| j| j| j| j| j| j	| j
d	S )N)r$   r   )r%   rT   r   r   r   r   r   r   r   r   r   )r   r$   r   r   r   execute   s   zCreatePageAliasAction.execute)F)r   r   r   r   r   r%   rT   rf   r   r   r   r   r      s    
 r   )loggingrE   django.core.exceptionsr   wagtail.log_actionsr   wagtail.models.copyingr   r   wagtail.models.i18nr   	getLoggerrN   RuntimeErrorr	   r   r   r   r   r   r   <module>   s    
