a
    DgT                     @   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 )NZrouterrequest)Zget_model_listing_urlpathr   )contextmodelZurl_path r   \/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/admin/api/serializers.pyget_model_listing_url
   s    r   c                   @   s    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   |S Nr   selfinstancer   r   r   get_attribute   s    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   Z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                   @   s    e Zd ZdZdd Zdd ZdS )PageChildrenFieldz
    Serializes the "children" field.

    Example:
    "children": {
        "count": 1,
        "listing_url": "/api/v1/pages/?child_of=2"
    }
    c                 C   s   |S r   r   r   r   r   r   r   5   s    zPageChildrenField.get_attributec                 C   s:   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
   Zchild_ofr!   r   r   stridr   r   r   r   r   8   s    
z#PageChildrenField.to_representationNr   r   r   r   r   r    *   s   
r    c                   @   s    e Zd ZdZdd Zdd ZdS )PageDescendantsFieldz
    Serializes the "descendants" field.

    Example:
    "descendants": {
        "count": 10,
        "listing_url": "/api/v1/pages/?descendant_of=2"
    }
    c                 C   s   |S r   r   r   r   r   r   r   Q   s    z"PageDescendantsField.get_attributec                 C   s:   t d| jd | fdt| jtd t|j fgS )Nr!   r"   r#   z?descendant_of=)r   r
   Zdescendant_ofr!   r   r   r$   r%   r   r   r   r   r   T   s    
z&PageDescendantsField.to_representationNr   r   r   r   r   r&   F   s   
r&   c                   @   s    e Zd ZdZdd Zdd ZdS )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   s   |S r   r   r   r   r   r   r   {   s    z PageAncestorsField.get_attributec                 C   s4   t tg dg dtd}|| jdd}|| S )N)r%   type
detail_urlhtml_urltitleadmin_display_title)r(   r)   r*   Zmeta_fieldsbaseTr
   many)r   r   AdminPageSerializerr
   r   Zget_ancestorsr   r   Zserializer_class
serializerr   r   r   r   ~   s    z$PageAncestorsField.to_representationNr   r   r   r   r   r'   b   s   r'   c                   @   s    e Zd ZdZdd Zdd ZdS )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   s   |S r   r   r   r   r   r   r      s    z#PageTranslationsField.get_attributec                 C   s4   t tg dg dtd}|| jdd}|| S )N)r%   r(   r)   r*   localer+   r,   )r(   r)   r*   r5   r-   Tr/   )r   r   r1   r
   r   Zget_translationsr2   r   r   r   r      s    	z'PageTranslationsField.to_representationNr   r   r   r   r   r4      s   r4   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 )r1   T)Z	read_onlyZget_admin_display_title)sourceN)r   r   r   r   r   r    childrenr&   Zdescendantsr'   Z	ancestorsr4   Ztranslationsr   r,   r   r   r   r   r1      s   




r1   N)collectionsr   Zrest_framework.fieldsr   r   Zwagtail.api.v2.serializersr   r   Zwagtail.api.v2.utilsr   Zwagtail.modelsr   r   r   r    r&   r'   r4   r1   r   r   r   r   <module>   s   '1