U
    d                     @   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mZ ddl	mZmZmZmZmZ G dd	 d	ejZG d
d deZG dd dejZG dd de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 )    )MinValueValidatorMaxValueValidator)serializers)IncludeExcludeOnlyValidatordict_validator   
validators)QuestionQUESTION_TYPE_MULTIPLE_CHOICE)question_format_validatortags_validatorquestion_type_validatorquestions_sort_by_validatormeta_validatorc                   @   s   e Zd ZejdddddZe ZejdegdZej	e
gddZeje ddZejdegdZe	 Zej	egd	Zejdd
Zej	egddZdd ZdS )QuestionContentInputSerializeriX  FT)
max_lengthrequired
allow_nullallow_blank   )r   r	   r	   r   )childr   r   r   c                 C   s   | dtkr^| dd kr*tddi| dd krFtddit| d| d tj| d| d| dd |S )Nquestion_typechoicesz;choices is required when question_type is "multiple-choice"correct_choiceszCcorrect_choices is required when question_type is "multiple-choice"input_rules)r   r   )getr   r   ValidationErrorr	   Zchoices_validatorZinput_rules_validator)selfdata r"   0/var/www/wikiazma_server/question/serializers.pyvalidate(   s&     z'QuestionContentInputSerializer.validateN)__name__
__module____qualname__r   	CharFieldkeywordsquestion_textr   format	JSONFieldr   r   	ListFieldr   r   r   r   r   tagssolutionr   	meta_datar$   r"   r"   r"   r#   r      s>           r   c                   @   s   e Zd Ze ZdS ) CreateQuestionApiInputSerializerN)r%   r&   r'   r   	UUIDFieldquestion_bank_idr"   r"   r"   r#   r1   9   s   r1   c                   @   s   e Zd Ze ZeddZdS )$CreateQuestionBulkApiInputSerializerT)manyN)r%   r&   r'   r   r2   r3   r   	questionsr"   r"   r"   r#   r4   =   s   r4   c                   @   s   e Zd Ze ZdS )EditQuestionApiInputSerializerNr%   r&   r'   r   r2   question_idr"   r"   r"   r#   r7   B   s   r7   c                   @   s   e Zd Ze ZdS ) DeleteQuestionApiInputSerializerNr8   r"   r"   r"   r#   r:   F   s   r:   c                   @   s   e Zd Ze Ze 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ddZejddZejegdd	ZejegdZeje gdZd
S )QuestionsListApiInputSerializerr   r   r   d   FT)r   r   r   r   r   N)r%   r&   r'   r   r2   r3   context_institute_idIntegerFieldr   skipr   taker(   qr   archived_filterr,   tag_filtersold_tag_filtersr   r   r   sort_byauto_correctable_filterr"   r"   r"   r#   r;   J   s(    r;   c                   @   s   e Zd Ze Ze ZdS )QuestionsGetApiInputSerializerN)r%   r&   r'   r   r2   r9   r=   r"   r"   r"   r#   rG   ^   s   rG   c                   @   sf   e Zd Ze Ze Ze Zej	dddgdZ
ejddZejddZejddZejddZdS )"EditQuestionBulkApiInputSerializer)updateZUpdate)removeRemove)addAdd)r   Fr   N)r%   r&   r'   r   r2   r3   r=   BooleanFieldcommitChoiceFieldactionr(   current_keycurrent_valueincoming_keyincoming_valuer"   r"   r"   r#   rH   d   s   rH   c                   @   s   e Zd ZG dd dZdS )QuestionModelSerializerc                   @   s.   e Zd ZeZddddddddd	d
dddgZdS )zQuestionModelSerializer.Metaidr)   r.   auto_correctabler*   r+   r   r   r   r   
created_atmodified_atr/   N)r%   r&   r'   r
   modelfieldsr"   r"   r"   r#   Metaw   s        r]   N)r%   r&   r'   r]   r"   r"   r"   r#   rV   u   s   rV   N)Zdjango.core.validatorsr   r   rest_frameworkr   utils.validatorsr   r    r	   modelsr
   r   r   r   r   r   r   
Serializerr   r1   r4   r7   r:   r;   rG   rH   ModelSerializerrV   r"   r"   r"   r#   <module>   s   &