o
    hG                     @   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depth
depth__min   )	aggregater   Minself r   T/var/www/html/ndineBlogger/venv/lib/python3.10/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	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                   @      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"      z"BaseCollectionManager.get_querysetN)r#   r$   r%   r+   r   r   r   r   r'   !       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_delete#passed_collection_view_restrictionsc                   @      e Zd ZedZedZdS )zCollectionViewRestriction.Metazcollection view restrictionzcollection view restrictionsNr#   r$   r%   _r2   verbose_name_pluralr   r   r   r   Meta3       r:   N)
r#   r$   r%   r   
ForeignKeyr8   CASCADEr   $passed_view_restrictions_session_keyr:   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_lengthr2   c                 C   s   | j S N)r@   r   r   r   r   __str__C   s   zCollection.__str__Fc                 C      t j| |S rB   )r/   objectsancestor_ofr   	inclusiver   r   r   get_ancestorsF      zCollection.get_ancestorsc                 C   rD   rB   )r/   rE   descendant_ofrG   r   r   r   get_descendantsI   rJ   zCollection.get_descendantsTc                 C   rD   rB   )r/   rE   
sibling_ofrG   r   r   r   get_siblingsL   rJ   zCollection.get_siblingsc                 C      |  |j| jddS )N)	path__gter(   rN   filterr(   r*   rG   r   r   r   get_next_siblingsO   s   zCollection.get_next_siblingsc                 C   rO   )N)	path__ltez-pathrQ   rG   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)rH   )collection__in)r.   rE   rR   rI   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)indenticonr@   u   {}↳ {}z    )r   r@   r   r   format)r   indentation_start_depthr   display_depthr   r   r   r   ]   s   


zCollection.get_indented_namec                   @   r6   )zCollection.Metar   collectionsNr7   r   r   r   r   r:   y   r;   r:   N)F)T)r   F)r#   r$   r%   __doc__r   	CharFieldr8   r@   CollectionManagerrE   node_order_byrC   rI   rL   rN   rS   rU   rW   r   r:   r   r   r   r   r/   8   s    





r/   c                   C   s
   t  jS rB   )r/   get_first_root_nodeidr   r   r   r   get_root_collection_id~   s   
rd   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   +)defaultr2   r3   r4   c                   @   s   e Zd ZdZdS )zCollectionMember.MetaTN)r#   r$   r%   abstractr   r   r   r   r:      s    r:   N)r#   r$   r%   r^   r   r<   r/   rd   r8   r=   r   r   FilterFieldsearch_fieldsr:   r   r   r   r   re      s    	re   c                   @   r&   ) GroupCollectionPermissionManagerc                 C   s   | j |||dS )Ngroupr   
permission)get)r   rm   r   rn   r   r   r   get_by_natural_key   r,   z3GroupCollectionPermissionManager.get_by_natural_keyN)r#   r$   r%   rp   r   r   r   r   rk      r-   rk   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.
    rm   collection_permissionsr1   r   group_permissionsrn   )r2   r4   c                 C   s    d| j j| j | j| jj| jf S )Nz;Group %d ('%s') has permission '%s' on collection %d ('%s'))rm   rc   rn   r   r   r   r   r   rC      s   z!GroupCollectionPermission.__str__c                 C   s   | j | j| jfS rB   rl   r   r   r   r   natural_key   r,   z%GroupCollectionPermission.natural_keyc                   @   s    e Zd ZdZedZedZdS )zGroupCollectionPermission.Metarl   zgroup collection permissionzgroup collection permissionsN)r#   r$   r%   unique_togetherr8   r2   r9   r   r   r   r   r:      s    r:   N)r#   r$   r%   r^   r   r<   r   r8   r=   rm   r/   r   r   rn   rC   rt   rk   rE   r:   r   r   r   r   rq      s*    	rq   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 typeuploadsT)r2   r3   r4   nullwagtail_uploads   )	upload_torA   zuploaded by userF)r2   rx   blankeditabler4   N)r#   r$   r%   r^   r   r<   r   r8   r=   for_content_type	FileFieldfiler   AUTH_USER_MODELSET_NULLuploaded_by_userr   r   r   r   rv      s$    
rv   N)%django.confr   django.contrib.auth.modelsr   r   "django.contrib.contenttypes.modelsr   	django.dbr   django.utils.htmlr   django.utils.safestringr   django.utils.translationr	   r8   treebeard.mp_treer
   wagtail.queryr   wagtail.searchr   r0   r   r   Managerr'   from_querysetr`   r.   r/   rd   Modelre   rk   rq   rv   r   r   r   r   <module>   s*    
F*