a
    Dg$                     @   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)TranslatableMixinZwagtailc                   @   s   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/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/actions/create_alias.pyr      s   r   c                   @   s   e Zd ZdZdS )CreatePageAliasPermissionErrorzf
    Raised when creating an alias of a page cannot be performed due to insufficient permissions.
    Nr   r   r   r   r   r      s   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   sZ   | j p| j }| jr4|| jks,|| jr4td| jrV|sV|| j sVt	d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   Zis_descendant_ofr   r   Zpermissions_for_userZcan_publish_subpager   )r   skip_permission_checksr   r   r   r   checkN   s$    
zCreatePageAliasAction.checkc                C   sr  |j }
g d}||j|j d}|r,||d< |r8||d< |rD||d< |rTt |d< t|
||d\}}| D ]&}t|trn|r||_	|rnt |_
qn|	r|	d |_|	d	 |_|jd
d n*|r|j|d}n|j|d}|j|jf}	t|
||d |rV|
 }t||||j| d|r0|j|j dnd |rJ|j|j dnd dd td|j|j|j ddlm}m} |rd}|    D ]L}|	d	 d	 }||	d |||f}|d	7 }| j|d|d |||||d	 q|dkr||_|jd
dgd |r|  }n|   }|! sn|j"# D ]8}||j$|j%|d}|j| j&d |j'(|j'#  q4|S )N)idpathdepthnumchildZurl_pathr!   Zindex_entriesZpostgres_index_entries)Zalias_ofZdraft_titleZhas_unpublished_changesZsluglocaleownertranslation_key)update_attrsexclude_fieldsr      F)clean)instance)r(   )r    title)r   sourceZdestination)r+   actionr   dataz&Page alias created: "%s" id=%d from=%d)PagePageViewRestrictionTr   r#   )r*   Zupdate_fields)restriction_typepasswordr   )r   ))Zspecificr,   Zliveuuiduuid4r   values
isinstancer   r$   r&   r!   r"   saveZ	add_childZadd_siblingr   r   r   r    Zget_admin_display_titleZspecific_deferredloggerinfoZwagtail.modelsr0   r1   Zget_childreniterator	_get_path_create_aliasr#   Zget_view_restrictionsexistsZview_restrictionsallr2   r3   r   groupsset)r   r   r   r   r   r   r   r   r   r   Zspecific_pager(   r'   aliasZchild_object_mapZchild_objectZsource_parentr0   r1   r#   Z
child_pageZnewdepthZchild_mpnode_attrsZparent_page_restrictionZview_restrictionZview_restriction_copyr   r   r   r=   `   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   r=   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   execute   s    zCreatePageAliasAction.execute)F)F)r	   r
   r   r   r   r   r=   rC   r   r   r   r   r      s   
 r   )loggingr4   Zdjango.core.exceptionsr   Zwagtail.log_actionsr   Zwagtail.models.copyingr   r   Zwagtail.models.i18nr   	getLoggerr9   RuntimeErrorr   r   r   r   r   r   r   <module>   s   
