U
    c0                     @   s  d dl mZmZ 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mZ dd
l
mZ ddl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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!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'G d*d+ d+ejZ(G d,d- d-ej"Z)G d.d/ d/ejZ*G d0d1 d1ej"Z+d2S )3    )MinValueValidatorMaxValueValidator)serializers)5InstituteSerializerForExamAndInstituteAndQuestionBank6ListInstituteSerializerForCollaboratorsAndQuestionBank)conf
validators)compress_image)IncludeExcludeOnlyValidator   )QuestionBankQuestionBankDefaultIcon)filters_template_validator)question_bank_sort_by_validatorc                   @   s`   e Zd Ze Ze ZejdddZe	 Z
ejddZejejgddZdd Zdd	 Zd
S )!CreateQuestionBankInputSerializer  F
max_lengthrequiredr   r	   r   c                 C   s*   t j|tjtjtjd t|tjd}|S N)imageimage_size_as_MBformatmax_side)max_side_sizemain_validatorsimage_validetorr   Z&maximum_size_for_question_bank_icon_MGZ&allowed_formats_for_question_bank_iconZ(maximum_side_size_for_question_bank_iconr
   Z1maximum_side_size_compress_for_question_bank_iconselfvaluecompress r%   5/var/www/wikiazma_server/question_bank/serializers.pyvalidate_icon   s    
 z/CreateQuestionBankInputSerializer.validate_iconc                 C   s   t j|ddd |S N   d   )name
min_lengthr   r   name_validatorr"   r#   r%   r%   r&   validate_name"   s      z/CreateQuestionBankInputSerializer.validate_nameN)__name__
__module____qualname__r   	UUIDFieldcontext_institute_id	CharFieldr+   descriptionBooleanFieldpublic
ImageFieldiconr   uuid_validatordefault_icon_idr'   r0   r%   r%   r%   r&   r      s    	r   c                   @   s   e Zd ZejdddZejdddZejejgdZ	ejddZ
ejdddddZejddZejddZejejgdd	Zd
d Zdd ZdS )EditQuestionBankInputSerializer  Fr   r   r   r   T)r   r   
allow_nullallow_blankr   c                 C   s*   t j|tjtjtjd t|tjd}|S r   r   r!   r%   r%   r&   r'   5   s    
 z-EditQuestionBankInputSerializer.validate_iconc                 C   s   t j|ddd |S r(   r-   r/   r%   r%   r&   r0   =   s      z-EditQuestionBankInputSerializer.validate_nameN)r1   r2   r3   r   r6   tokenapi_keyr   r<   question_bank_idr+   r7   r8   r9   r:   r;   r=   r'   r0   r%   r%   r%   r&   r>   (   s(       r>   c                   @   sF   e Zd ZejdddZejdddZejejgdZ	ej
egdZdS )&EditQuestionBankFiltersInputSerializerr?   Fr   r   N)r1   r2   r3   r   r6   rB   rC   r   r<   rD   	JSONFieldr   filters_templater%   r%   r%   r&   rE   C   s   rE   c                   @   s   e Zd Ze Ze ZdS )"ArchiveQuestionBankInputSerializerN)r1   r2   r3   r   r4   rD   r5   r%   r%   r%   r&   rH   J   s   rH   c                   @   s,   e Zd ZejejgdZejejgdZdS )&UnsubscribeQuestionBankInputSerializerr   N	r1   r2   r3   r   r6   r   r<   rD   r5   r%   r%   r%   r&   rI   O   s   rI   c                   @   sH   e Zd ZejdddZejdddZejejgdZ	ejejgdZ
dS )GetQuestionBankInputSerializerr?   Fr   r   Nr1   r2   r3   r   r6   rB   rC   r   r<   rD   r5   r%   r%   r%   r&   rK   V   s   rK   c                   @   st   e Zd ZejejgdZeje	dgdZ
eje	dedgdZejddddZejegdZeje gdZdS )	QuestionBankListInputSerializerr   r   r   r*   FTr   r   r@   N)r1   r2   r3   r   r6   r   r<   r5   IntegerFieldr   skipr   takeqr   sort_byr   archived_filterr%   r%   r%   r&   rM   _   s   rM   c                   @   sH   e Zd ZejdddZejdddZejejgdZ	ejejgdZ
dS )&TagsListOfAQuestionBankInputSerializerr?   Fr   r   NrL   r%   r%   r%   r&   rU   h   s   rU   c                   @   s   e Zd ZejdddZejdddZejejgdZ	ejejgdZ
ejedgdZejededgdZejdddd	Zd
S )*TagsKeysListOfAQuestionBankInputSerializerr?   Fr   r   r   r   r*   TrN   N)r1   r2   r3   r   r6   rB   rC   r   r<   rD   r5   rO   r   rP   r   rQ   rR   r%   r%   r%   r&   rV   q   s   rV   c                   @   s   e Zd ZejdddZejdddZejejgdZ	ejejgdZ
ejddZejedgdZejeded	gdZejd	dd
dZdS ),TagsValuesListOfAQuestionBankInputSerializerr?   Fr   r   2   )r   r   r   r*   TrN   N)r1   r2   r3   r   r6   rB   rC   r   r<   rD   r5   keyrO   r   rP   r   rQ   rR   r%   r%   r%   r&   rW   ~   s   rW   c                   @   s4   e Zd Ze ZejddZdd ZG dd dZ	dS )QuestionBankModelSerializer
get_pickedmethod_namec                 C   s(   | j dr | j d|jS d S d S Ncontext_institutecontextgetquestion_bank_is_pickedidr"   instancer%   r%   r&   r[      s    z&QuestionBankModelSerializer.get_pickedc                   @   s2   e Zd ZeZddddddddd	d
dddddgZdS )z QuestionBankModelSerializer.Metard   r+   	instituter7   pickedpricequestions_countaccessibilityratesarchivedr;   posterfeaturedmodified_at
created_atNr1   r2   r3   r   modelfieldsr%   r%   r%   r&   Meta   s          ru   N)
r1   r2   r3   r   rg   r   SerializerMethodFieldrh   r[   ru   r%   r%   r%   r&   rZ      s   rZ   c                   @   s\   e Zd Ze ZejddZejddZejddZ	dd Z
dd Zd	d
 ZG dd dZdS )QuestionBankGetSerializerr[   r\   get_filtersget_tagsc                 C   s(   | j dr | j d|jS d S d S r^   r`   re   r%   r%   r&   r[      s    z$QuestionBankGetSerializer.get_pickedc                 C   s   |j S N)_filtersre   r%   r%   r&   rx      s    z%QuestionBankGetSerializer.get_filtersc                 C   s   |j S rz   )_tagsre   r%   r%   r&   ry      s    z"QuestionBankGetSerializer.get_tagsc                   @   s8   e Zd ZeZddddddddd	d
ddddddddgZdS )zQuestionBankGetSerializer.Metard   r+   rg   r7   rh   filterstagsri   rG   rj   rk   rl   rm   r;   rn   ro   rp   rq   Nrr   r%   r%   r%   r&   ru      s          ru   N)r1   r2   r3   r   rg   r   rv   rh   r}   r~   r[   rx   ry   ru   r%   r%   r%   r&   rw      s   rw   c                   @   s    e Zd Ze ZG dd dZdS )/QuestionBankforPickedQuestionBankListSerializerc                   @   s0   e Zd ZeZddddddddd	d
ddddgZdS )z4QuestionBankforPickedQuestionBankListSerializer.Metard   r+   rg   r7   ri   rj   rk   rl   rm   r;   rn   ro   rp   rq   Nrr   r%   r%   r%   r&   ru      s   
       ru   N)r1   r2   r3   r   rg   ru   r%   r%   r%   r&   r      s   r   c                   @   s(   e Zd ZejejgdZejddZ	dS ))BookMarkQuestionBankPublicInputSerializerr   Tr   N)
r1   r2   r3   r   r6   r   r<   rD   r8   starr%   r%   r%   r&   r      s   r   c                   @   s    e Zd Ze ZG dd dZdS )ListQuestionBankSerializerc                   @   s0   e Zd ZeZddddddddd	d
ddddgZdS )zListQuestionBankSerializer.Metard   r+   rg   r7   ri   rj   rk   rl   rm   r;   rn   ro   rp   rq   Nrr   r%   r%   r%   r&   ru      s   
       ru   N)r1   r2   r3   r   rg   ru   r%   r%   r%   r&   r      s   r   c                   @   sr   e Zd ZejedgdZejededgdZej	ddZ
ej	e gdZej	e gdZej	ejgdZdS )&QuestionBankMarketPlaceInputSerializerr   r   r   r*   Fr   N)r1   r2   r3   r   rO   r   rP   r   rQ   r6   rR   r   featured_filterfree_filterr   r<   r5   r%   r%   r%   r&   r      s   r   c                   @   s2   e Zd Ze ZedZdd ZG dd dZ	dS )&QuestionBankMarketPlaceModelSerializerfetch_pickedc                 C   s   |j S rz   )rh   )r"   objr%   r%   r&   r      s    z3QuestionBankMarketPlaceModelSerializer.fetch_pickedc                   @   s2   e Zd ZeZddddddddd	d
dddddgZdS )z+QuestionBankMarketPlaceModelSerializer.Metard   rh   r+   rg   r7   ri   rj   rk   rl   rm   r;   rn   ro   rp   rq   Nrr   r%   r%   r%   r&   ru      s          ru   N)
r1   r2   r3   r   rg   r   rv   rh   r   ru   r%   r%   r%   r&   r      s   
r   c                   @   s,   e Zd ZejejgdZejejgdZdS )QuestionBankPickInputSerializerr   NrJ   r%   r%   r%   r&   r     s   r   c                   @   s   e Zd ZG dd dZdS )+QuestionBankDefaultIconsListModelSerializerc                   @   s   e Zd ZeZdZdS )z0QuestionBankDefaultIconsListModelSerializer.Meta)rd   r;   N)r1   r2   r3   r   rs   rt   r%   r%   r%   r&   ru     s   ru   N)r1   r2   r3   ru   r%   r%   r%   r&   r     s   r   N),Zdjango.core.validatorsr   r   rest_frameworkr   institute.serializersr   r   question_bankr   utilsr	   r   utils.utilsr
   utils.validatorsr   modelsr   r   r   Z
validetorsr   
Serializerr   r>   rE   rH   rI   rK   rM   rU   rV   rW   ModelSerializerrZ   rw   r   r   r   r   r   r   r   r%   r%   r%   r&   <module>   s8   			

