o
    hT                     @   s   d dl mZ d dlmZmZ d dlmZmZ d dlm	Z	 d dl
mZ dd ZG dd	 d	eZG d
d deZG dd deZG dd deZG dd deZG dd deZdS )    )OrderedDict)FieldReadOnlyField)PageSerializerget_serializer_class)get_full_url)Pagec                 C   s$   | d  |}|rt| d |S d S )Nrouterrequest)get_model_listing_urlpathr   )contextmodelurl_path r   ]/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/admin/api/serializers.pyget_model_listing_url
   s   r   c                   @       e Zd ZdZdd Zdd ZdS )PageStatusFieldz
    Serializes the "status" field.

    Example:
    "status": {
        "status": "live",
        "live": true,
        "has_unpublished_changes": false
    },
    c                 C      |S Nr   selfinstancer   r   r   get_attribute      zPageStatusField.get_attributec                 C   s    t d|jfd|jfd|jfgS )Nstatuslivehas_unpublished_changes)r   status_stringr   r   r   pager   r   r   to_representation    s   z!PageStatusField.to_representationN__name__
__module____qualname____doc__r   r!   r   r   r   r   r      s    r   c                   @   r   )PageChildrenFieldz
    Serializes the "children" field.

    Example:
    "children": {
        "count": 1,
        "listing_url": "/api/v1/pages/?child_of=2"
    }
    c                 C   r   r   r   r   r   r   r   r   5   r   zPageChildrenField.get_attributec                 C   :   t d| jd | fdt| jtd t|j fgS )Ncountbase_querysetlisting_urlz
?child_of=)r   r   child_ofr)   r   r   stridr   r   r   r   r!   8      
z#PageChildrenField.to_representationNr"   r   r   r   r   r'   *       
r'   c                   @   r   )PageDescendantsFieldz
    Serializes the "descendants" field.

    Example:
    "descendants": {
        "count": 10,
        "listing_url": "/api/v1/pages/?descendant_of=2"
    }
    c                 C   r   r   r   r   r   r   r   r   Q   r   z"PageDescendantsField.get_attributec                 C   r(   )Nr)   r*   r+   z?descendant_of=)r   r   descendant_ofr)   r   r   r-   r.   r   r   r   r   r!   T   r/   z&PageDescendantsField.to_representationNr"   r   r   r   r   r1   F   r0   r1   c                   @   r   )PageAncestorsFielda  
    Serializes the page's ancestry.

    Example:
    "ancestry": [
        {
            "id": 1,
            "meta": {
                "type": "wagtailcore.Page",
                "detail_url": "/api/v1/pages/1/"
            },
            "title": "Root"
        },
        {
            "id": 2,
            "meta": {
                "type": "home.HomePage",
                "detail_url": "/api/v1/pages/2/"
            },
            "title": "Home"
        }
    ]
    c                 C   r   r   r   r   r   r   r   r   {   r   z PageAncestorsField.get_attributec                 C   4   t tg dg dtd}|| jdd}|| S )N)r.   type
detail_urlhtml_urltitleadmin_display_title)r5   r6   r7   meta_fieldsbaseTr   many)r   r   AdminPageSerializerr   r!   get_ancestorsr   r    serializer_class
serializerr   r   r   r!   ~   s   z$PageAncestorsField.to_representationNr"   r   r   r   r   r3   b   s    r3   c                   @   r   )PageTranslationsFielda"  
    Serializes the page's translations.

    Example:
    "translations": [
        {
            "id": 1,
            "meta": {
                "type": "home.HomePage",
                "detail_url": "/api/v1/pages/1/",
                "locale": "es"
            },
            "title": "Casa"
        },
        {
            "id": 2,
            "meta": {
                "type": "home.HomePage",
                "detail_url": "/api/v1/pages/2/",
                "locale": "fr"
            },
            "title": "Maison"
        }
    ]
    c                 C   r   r   r   r   r   r   r   r      r   z#PageTranslationsField.get_attributec                 C   r4   )N)r.   r5   r6   r7   localer8   r9   )r5   r6   r7   rE   r:   Tr=   )r   r   r?   r   r!   get_translationsrA   r   r   r   r!      s   	z'PageTranslationsField.to_representationNr"   r   r   r   r   rD      s    rD   c                   @   sH   e Zd ZeddZeddZeddZe	ddZ
eddZeddZdS )r?   T)	read_onlyget_admin_display_title)sourceN)r#   r$   r%   r   r   r'   childrenr1   descendantsr3   	ancestorsrD   translationsr   r9   r   r   r   r   r?      s    




r?   N)collectionsr   rest_framework.fieldsr   r   wagtail.api.v2.serializersr   r   wagtail.api.v2.utilsr   wagtail.modelsr   r   r   r'   r1   r3   rD   r?   r   r   r   r   <module>   s    '1