a
    DgG                     @   s(  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dlmZ G dd deZG dd dejZeeZG dd deZG dd deZdd ZG dd dej Z!G dd dejZ"G dd dej Z#G dd dej Z$dS )     )settings)Group
Permission)ContentType)models)format_html)	mark_safe)gettext_lazy)MP_Node)TreeQuerySet)index   )BaseViewRestrictionc                   @   s   e Zd Zdd Zdd ZdS )CollectionQuerySetc                 C   s   |  tdd pdS )NdepthZ
depth__min   )Z	aggregater   ZMinself r   S/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/models/media.pyget_min_depth   s    z CollectionQuerySet.get_min_depthc                    s   |     fdd| D S )a   
        Return a list of (id, label) tuples for use as a list of choices in a collection chooser
        dropdown, where the label is formatted with get_indented_name to provide a tree layout.
        The indent level is chosen to place the minimum-depth collection at indent 0.
        c                    s    g | ]}|j |j d dfqS )T)html)pkget_indented_name).0
collectionZ	min_depthr   r   
<listcomp>   s   z;CollectionQuerySet.get_indented_choices.<locals>.<listcomp>)r   r   r   r   r   get_indented_choices   s    
z'CollectionQuerySet.get_indented_choicesN)__name__
__module____qualname__r   r   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd ZdS )BaseCollectionManagerc                 C   s   t | jdS )Npath)r   modelorder_byr   r   r   r   get_queryset"   s    z"BaseCollectionManager.get_querysetN)r   r    r!   r&   r   r   r   r   r"   !   s   r"   c                   @   s6   e Zd ZejdeddejdZdZG dd dZ	dS )	CollectionViewRestriction
Collectionr   view_restrictionsverbose_namerelated_name	on_deleteZ#passed_collection_view_restrictionsc                   @   s   e Zd ZedZedZdS )zCollectionViewRestriction.Metazcollection view restrictionzcollection view restrictionsNr   r    r!   _r+   verbose_name_pluralr   r   r   r   Meta3   s   r1   N)
r   r    r!   r   
ForeignKeyr/   CASCADEr   Z$passed_view_restrictions_session_keyr1   r   r   r   r   r'   )   s   r'   c                   @   s   e Zd ZdZejdeddZe Z	dgZ
dd Zddd	Zdd
dZdddZdddZdddZdd Zd ddZG dd dZdS )!r(   zS
    A location in which resources such as images and documents can be grouped
       name)
max_lengthr+   c                 C   s   | j S N)r5   r   r   r   r   __str__C   s    zCollection.__str__Fc                 C   s   t j| |S r7   )r(   objectsZancestor_ofr   	inclusiver   r   r   get_ancestorsF   s    zCollection.get_ancestorsc                 C   s   t j| |S r7   )r(   r9   Zdescendant_ofr:   r   r   r   get_descendantsI   s    zCollection.get_descendantsTc                 C   s   t j| |S r7   )r(   r9   Z
sibling_ofr:   r   r   r   get_siblingsL   s    zCollection.get_siblingsc                 C   s   |  |j| jddS )N)Z	path__gter#   r>   filterr#   r%   r:   r   r   r   get_next_siblingsO   s    zCollection.get_next_siblingsc                 C   s   |  |j| jddS )N)Z	path__ltez-pathr?   r:   r   r   r   get_prev_siblingsR   s    zCollection.get_prev_siblingsc                 C   s   t jj| jdddS )zTReturn a query set of all collection view restrictions that apply to this collectionT)r;   )Zcollection__in)r'   r9   r@   r<   r   r   r   r   get_view_restrictionsW   s    
z Collection.get_view_restrictionsr   c                 C   sL   | j | }|dkr| jS |r:tdtd| td| jdS dd| | jS )u  
        Renders this Collection's name as a formatted string that displays its hierarchical depth via indentation.
        If indentation_start_depth is supplied, the Collection's depth is rendered relative to that depth.
        indentation_start_depth defaults to 2, the depth of the first non-Root Collection.
        Pass html=True to get an HTML representation, instead of the default plain-text.

        Example text output: "    ↳ Pies"
        Example HTML output: "&nbsp;&nbsp;&nbsp;&nbsp;&#x21b3 Pies"
        r   z{indent}{icon} {name}z&nbsp;&nbsp;&nbsp;&nbsp;z&#x21b3)indentZiconr5   u   {}↳ {}z    )r   r5   r   r   format)r   Zindentation_start_depthr   Zdisplay_depthr   r   r   r   ]   s    


zCollection.get_indented_namec                   @   s   e Zd ZedZedZdS )zCollection.Metar   collectionsNr.   r   r   r   r   r1   y   s   r1   N)F)F)T)F)F)r   F)r   r    r!   __doc__r   Z	CharFieldr/   r5   CollectionManagerr9   Znode_order_byr8   r<   r=   r>   rA   rB   rC   r   r1   r   r   r   r   r(   8   s   





r(   c                   C   s
   t  jS r7   )r(   Zget_first_root_nodeidr   r   r   r   get_root_collection_id~   s    rJ   c                   @   sD   e Zd ZdZejeeeddej	dZ
edgZG dd dZdS )CollectionMemberzE
    Base class for models that are categorised into collections
    r   +)defaultr+   r,   r-   c                   @   s   e Zd ZdZdS )zCollectionMember.MetaTN)r   r    r!   Zabstractr   r   r   r   r1      s   r1   N)r   r    r!   rG   r   r2   r(   rJ   r/   r3   r   r   ZFilterFieldZsearch_fieldsr1   r   r   r   r   rK      s   	rK   c                   @   s   e Zd Zdd ZdS ) GroupCollectionPermissionManagerc                 C   s   | j |||dS )Ngroupr   
permission)get)r   rP   r   rQ   r   r   r   get_by_natural_key   s    z3GroupCollectionPermissionManager.get_by_natural_keyN)r   r    r!   rS   r   r   r   r   rN      s   rN   c                   @   sz   e Zd ZdZejeeddejdZ	eje
eddejdZejeedejdZd	d
 Zdd Ze ZG dd dZdS )GroupCollectionPermissionz
    A rule indicating that a group has permission for some action (e.g. "create document")
    within a specified collection.
    rP   Zcollection_permissionsr*   r   Zgroup_permissionsrQ   )r+   r-   c                 C   s    d| j j| j | j| jj| jf S )Nz;Group %d ('%s') has permission '%s' on collection %d ('%s'))rP   rI   rQ   r   r   r   r   r   r8      s    z!GroupCollectionPermission.__str__c                 C   s   | j | j| jfS r7   rO   r   r   r   r   natural_key   s    z%GroupCollectionPermission.natural_keyc                   @   s    e Zd ZdZedZedZdS )zGroupCollectionPermission.MetarO   zgroup collection permissionzgroup collection permissionsN)r   r    r!   Zunique_togetherr/   r+   r0   r   r   r   r   r1      s   r1   N)r   r    r!   rG   r   r2   r   r/   r3   rP   r(   r   r   rQ   r8   rU   rN   r9   r1   r   r   r   r   rT      s(   	rT   c                   @   sV   e Zd ZdZejeeddejddZ	ej
dddZejejed	ddd
ejdZdS )UploadedFileak  
    Temporary storage for media fields uploaded through the multiple image/document uploader.
    When validation rules (e.g. required metadata fields) prevent creating an Image/Document object from the file alone.
    In this case, the file is stored against this model, to be turned into an Image/Document object once the full form
    has been filled in.
    zfor content typeZuploadsT)r+   r,   r-   nullZwagtail_uploads   )Z	upload_tor6   zuploaded by userF)r+   rW   Zblankeditabler-   N)r   r    r!   rG   r   r2   r   r/   r3   Zfor_content_typeZ	FileFieldfiler   ZAUTH_USER_MODELZSET_NULLZuploaded_by_userr   r   r   r   rV      s"   rV   N)%Zdjango.confr   Zdjango.contrib.auth.modelsr   r   Z"django.contrib.contenttypes.modelsr   Z	django.dbr   Zdjango.utils.htmlr   Zdjango.utils.safestringr   Zdjango.utils.translationr	   r/   Ztreebeard.mp_treer
   Zwagtail.queryr   Zwagtail.searchr   r)   r   r   Managerr"   Zfrom_querysetrH   r'   r(   rJ   ZModelrK   rN   rT   rV   r   r   r   r   <module>   s(   
F*