U
     hr                     @   s   d dl mZ d dlmZmZmZmZmZm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G dd dejZdS )    )serializers)ContentsAttachmentsContentVersionContentVersionAttachment
ContentTag
Categoriesc                   @   s   e Zd ZG dd dZdS )AttachmentSerializerc                   @   s    e Zd ZeZddddddgZdS )zAttachmentSerializer.Metapknamepath_typesize
is_deletedN)__name__
__module____qualname__r   modelfields r   r   CD:\Project\agus\mfile_papteng_new\webapp\api\fileman\serializers.pyMeta
   s   r   Nr   r   r   r   r   r   r   r   r	   	   s   r	   c                   @   s   e Zd ZG dd dZdS )"ContentVersionAttachmentSerializerc                   @   s    e Zd ZeZddddddgZdS )z'ContentVersionAttachmentSerializer.Metar
   r   r   content_typer   createdN)r   r   r   r   r   r   r   r   r   r   r      s   r   Nr   r   r   r   r   r      s   r   c                   @   s*   e Zd Ze ZG dd dZdd ZdS )ContentVersionSerializerc                   @   s    e Zd ZeZddddddgZdS )zContentVersionSerializer.Metar
   judul	deskripsistatus_kontenr   attachmentsN)r   r   r   r   r   r   r   r   r   r   r      s       r   c                 C   s   t jj|jd}t|ddjS )N)
pk_versionTmany)r   objectsfilterr
   r   dataselfobjqsr   r   r   get_attachments!   s    z(ContentVersionSerializer.get_attachmentsN)r   r   r   r   SerializerMethodFieldr    r   r+   r   r   r   r   r      s   r   c                   @   sZ   e Zd Ze Ze Ze Ze ZG dd dZ	dd Z
dd Zdd Zd	d
 ZdS )ContentSerializerc                   @   sD   e Zd ZeZddddddddd	d
dddddgZdddddddgZdS )zContentSerializer.Metar
   r   r   r   r   updatedpk_categoriescategory
pk_skpd_dgtahun
user_input
attributesr    versionstagsN)r   r   r   r   r   r   read_only_fieldsr   r   r   r   r   -   s2                   r   c                 C   s    t jj|jdd}t|ddjS )NF)pk_contentsr   Tr"   )r   r$   r%   r
   r	   r&   r'   r   r   r   r+   :   s    z!ContentSerializer.get_attachmentsc                 C   s$   t jj|jdd}t|ddjS )N)r8   z-createdTr"   )r   r$   r%   r
   order_byr   r&   r'   r   r   r   get_versions>   s    zContentSerializer.get_versionsc                 C   s   dd t jj|ddD S )Nc                 S   s   g | ]}|j jqS r   )tagr   ).0ctr   r   r   
<listcomp>C   s    z.ContentSerializer.get_tags.<locals>.<listcomp>)contentr;   )r   r$   r%   select_relatedr(   r)   r   r   r   get_tagsB   s    zContentSerializer.get_tagsc                 C   s   t |jtr|jjS d S )N)
isinstancer/   r   textrA   r   r   r   get_categoryG   s    zContentSerializer.get_categoryN)r   r   r   r   r,   r    r5   r6   r0   r   r+   r:   rB   rE   r   r   r   r   r-   '   s   r-   c                   @   sh   e Zd Ze ZejdddZe Ze Z	e Z
ejdddZejdddZeje ddZdS )ContentCreateSerializerFT)requiredallow_blank)childrG   N)r   r   r   r   	CharFieldr   r   IntegerFieldr2   r/   r1   r   r6   	ListField	FileFieldr    r   r   r   r   rF   N   s    rF   N)rest_frameworkr   webapp.models.koleksir   r   r   r   r   r   ModelSerializerr	   r   r   r-   
SerializerrF   r   r   r   r   <module>   s    '