U
     bdQ                     @   s  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
mZ d dlmZ d dlmZmZmZmZmZmZmZ d dlmZmZ d d	lmZ d
d Zdd Zdd 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)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-Z.G d,d- d-e.Z/G d.d) d)ej#Z-G d/d0 d0ejZ0G d1d2 d2ejZ1G d3d4 d4ejZ2G d5d6 d6ejZ3G d7d8 d8ejZ4d9d: Z5G d;d< d<ejZ6G d=d> d>ejZ7G d?d@ d@e6Z8G dAdB dBejZ9G dCdD dDe6Z:G dEdF dFejZ;G dGdH dHejZ<G dIdJ dJejZ=G dKdL dLe=Z>G dMdN dNe=Z?G dOdP dPe=Z@G dQdR dRe=ZAG dSdT dTe=ZBG dUdV dVejZCG dWdX dXejZDG dYdZ dZejZEG d[d\ d\ejZFG d]d^ d^ejZGG d_d` d`ejZHG dadb dbejZIdcdddedfdgdhgZJG didj djej#ZKG dkdl dlej#ZLdmS )n    )MinValueValidatorMaxValueValidator)Q)serializers)PublicUserSerializer)%InstituteStudentSerializerForExamStat5InstituteSerializerForExamAndInstituteAndQuestionBank)conf)Quiz	QuizSheetQuizTemplate!QUIZ_SHEET_STATE_SCORES_PUBLISHEDQUIZ_SHEET_STATE_NOT_ATTENDEDQuestionScore
QUIZ_TYPES)user_inputs_validator4token_quiz_id_quiz_sheet_id_entrance_token_validator
validatorsc                 C   s:   ddl m} | }| |kr6tddd| i| S )Nr   )list_quiz_sort_by_switchersort_bysort_by should be one of , )
quiz.utilsr   keysr   ValidationErrorjoin)r   r   allowed_sort_by_items r   ,/var/www/wikiazma_server/quiz/serializers.pyquiz_sort_by_validator   s    r    c                 C   s4   dd t D }| |kr0tddd| i| S )Nc                 S   s   g | ]}|d  qS )r   r   ).0Zquiz_type_tupler   r   r   
<listcomp>'   s     z'quiz_type_validator.<locals>.<listcomp>	quiz_typezquiz_type should be one of r   )r   r   r   r   )r#   r   r   r   r   quiz_type_validator&   s     r$   c                 C   s:   ddl m} | }| |kr6tddd| i| S )Nr   ) list_quiz_sheet_sort_by_switcherr   r   r   )r   r%   r   r   r   r   )r   r%   r   r   r   r   quiz_sheet_sort_by_validator1   s    r&   c                   @   s   e Zd Ze ZejddddZejddddZej	e
dgdZej	e
dedgdZejegdZeje gdZeje gdZeje gdZeje gdZeje gdZeje gdZdS )	QuizListInputSerializerd   FT
max_lengthrequired
allow_nullr   r      N)__name__
__module____qualname__r   	UUIDFieldcontext_institute_id	CharFieldqqidIntegerFieldr   skipr   taker    r   main_validatorsIncludeExcludeOnlyValidatorreanswerable_filtershuffle_questions_filtershuffle_choices_filter single_question_at_a_time_filterarchived_filterexpired_filterr   r   r   r   r'   <   s4   r'   c                   @   s   e Zd Ze ZejddddZeje	dgdZ
eje	dedgdZejegdZeje gdZeje gdZeje gdZeje gdZeje gdZdS )	QuizTemplateListInputSerializerr(   FTr)   r   r   r-   N)r.   r/   r0   r   r1   r2   r3   r4   r6   r   r7   r   r8   r    r   r9   r:   r;   r<   r=   r>   r?   r   r   r   r   rA   Z   s,   rA   c                   @   s   e Zd ZejddddZejedgdZejede	dgdZ
ejegdZeje gdZeje gdZeje gdZeje gdZeje gdZdS )	!QuizTemplateMarketInputSerializerr(   FTr)   r   r   r-   N)r.   r/   r0   r   r3   r4   r6   r   r7   r   r8   r    r   r9   r:   r;   r<   r=   r>   r?   r   r   r   r   rB   s   s*   rB   c                   @   s   e Zd ZG dd dZdS )$QuizSheetForInstituteModelSerializerc                   @   s"   e Zd ZeZdddddddgZdS )	z)QuizSheetForInstituteModelSerializer.Meta
referer_idallowed_start_atallowed_finish_atdurationfinal_scorestateentrance_tokenNr.   r/   r0   r   modelfieldsr   r   r   r   Meta   s   rN   Nr.   r/   r0   rN   r   r   r   r   rC      s   rC   c                   @   s   e Zd ZG dd dZdS )"QuizSheetModelSerializerForHistoryc                   @   s"   e Zd ZeZdddddddgZdS )	z'QuizSheetModelSerializerForHistory.MetarD   entrance_daterE   rF   rG   rH   rI   NrK   r   r   r   r   rN      s   rN   NrO   r   r   r   r   rP      s   rP   c                   @   s   e Zd ZG dd dZdS )QuizModelBasicSerializerc                   @   s   e Zd ZeZdddddgZdS )zQuizModelBasicSerializer.Metaidnameposterposter_thumbnailr#   Nr.   r/   r0   r
   rL   rM   r   r   r   r   rN      s   rN   NrO   r   r   r   r   rR      s   rR   c                   @   s   e Zd ZG dd dZdS )!QuizModelForReportSheetSerializerc                   @   s    e Zd ZeZddddddgZdS )z&QuizModelForReportSheetSerializer.MetarS   rT   rU   rV   r#   custom_report_cardNrW   r   r   r   r   rN      s   rN   NrO   r   r   r   r   rX      s   rX   c                   @   s\   e Zd ZejddZejddZejddZe Z	dd Z
dd Zd	d
 ZG dd dZdS ) QuizSheetModelForEnterSerializerget_solutions_sheetmethod_nameget_questions_sheetget_quizee_inputs_sheetc                 C   s   |j tkr|jS d S d S N)rI   r   _solutions_sheetselfinstancer   r   r   r[      s    
z4QuizSheetModelForEnterSerializer.get_solutions_sheetc                 C   s   |j tkr|jS d S d S r`   )rI   r   _questions_sheetrb   r   r   r   r^      s    
z4QuizSheetModelForEnterSerializer.get_questions_sheetc                 C   s   |j tkr|jS d S d S r`   )rI   r   _quizee_inputs_sheetrb   r   r   r   r_      s    
z8QuizSheetModelForEnterSerializer.get_quizee_inputs_sheetc                   @   s,   e Zd ZeZddddddddd	d
ddgZdS )z%QuizSheetModelForEnterSerializer.MetarD   solutions_sheetquestions_sheetquizee_inputs_sheetrQ   rE   rF   rG   rH   rI   report_cardquizNrK   r   r   r   r   rN      s   rN   N)r.   r/   r0   r   SerializerMethodFieldrg   rh   ri   rR   rk   r[   r^   r_   rN   r   r   r   r   rZ      s   rZ   c                   @   sz   e Zd Ze Ze ZejddZ	ejddZ
ejddZedZe Zdd Zdd	 Zd
d Zdd ZG dd dZdS )%QuizSheetModelForReportCardSerializerr[   r\   r^   r_   corrections_generatorc                 C   s   |j S r`   )ra   rb   r   r   r   r[      s    z9QuizSheetModelForReportCardSerializer.get_solutions_sheetc                 C   s   |j S r`   )re   rb   r   r   r   r^      s    z9QuizSheetModelForReportCardSerializer.get_questions_sheetc                 C   s   |j S r`   )rf   rb   r   r   r   r_      s    z=QuizSheetModelForReportCardSerializer.get_quizee_inputs_sheetc                 C   s   t jj|d}t|ddjS )N)
quiz_sheetT)many)r   objectsfilter#QuestionScoreModelForStatSerializerdata)rc   ro   correctionsr   r   r   rn     s    z;QuizSheetModelForReportCardSerializer.corrections_generatorc                   @   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*QuizSheetModelForReportCardSerializer.MetarD   rH   rI   rQ   finished_atrj   rg   rh   ri   userinstitute_studentru   rk   NrK   r   r   r   r   rN     s   rN   N)r.   r/   r0   r   rw   r   rx   r   rl   rg   rh   ri   ru   rX   rk   r[   r^   r_   rn   rN   r   r   r   r   rm      s$   
rm   c                   @   s   e Zd ZdS )QuizSheetModelForStatSerializerNr.   r/   r0   r   r   r   r   ry     s   ry   c                   @   s,   e Zd Ze Ze Ze ZG dd dZ	dS )GetQuizSheetForListSerializerc                   @   s$   e Zd ZeZddddddddgZd	S )
z"GetQuizSheetForListSerializer.MetarD   rI   rQ   rH   rG   rw   rx   rk   NrK   r   r   r   r   rN   "  s   rN   N)
r.   r/   r0   r   rw   r   rx   rR   rk   rN   r   r   r   r   r{     s   r{   c                   @   s   e Zd ZG dd dZdS )rs   c                   @   s   e Zd ZeZdddgZdS )z(QuestionScoreModelForStatSerializer.Metaquestion_idscoreblankN)r.   r/   r0   r   rL   rM   r   r   r   r   rN   1  s   rN   NrO   r   r   r   r   rs   0  s   rs   c                   @   s.   e Zd ZejddZdd ZG dd dZdS )QuizTemplateModelSerializerget_blueprintr\   c                 C   s   | j ddkr|jS d S d S Nwith_blueprintTcontextget
_blueprintrb   r   r   r   r   9  s    )QuizTemplateModelSerializer.get_blueprintc                   @   sH   e Zd ZeZddddddddd	d
ddddddddddddddddgZdS ) QuizTemplateModelSerializer.MetarS   rT   r#   single_question_at_a_timereanswerableshuffle_questionsshuffle_choicesapply_negative_scoresrU   rV   themedescriptionrG   questions_countfinish_messagearchived
created_atmodified_atprice	wage_freevax_freepublicfeaturedstartend	blueprintNr.   r/   r0   r   rL   rM   r   r   r   r   rN   ?  s8   rN   Nr.   r/   r0   r   rl   r   r   rN   r   r   r   r   r   6  s   r   c                   @   sB   e Zd ZejddZejddZdd Zdd ZG dd	 d	Z	d
S )QuizModelSerializerget_quiz_sheet_countr\   "get_not_corrected_quiz_sheet_countc                 C   s   t jj|d S )Nrk   )r   rq   rr   countrb   r   r   r   r   g  s    z(QuizModelSerializer.get_quiz_sheet_countc                 C   s    t jj|dttd  S )Nr   )rI   )r   rq   rr   r   r   r   rb   r   r   r   r   j  s    
z6QuizModelSerializer.get_not_corrected_quiz_sheet_countc                   @   s$   e Zd ZeZejjddddg ZdS )zQuizModelSerializer.Metacreatorlast_editorquiz_sheet_countnot_corrected_quiz_sheet_countN)r.   r/   r0   r
   rL   r   rN   rM   r   r   r   r   rN   q  s   rN   N)
r.   r/   r0   r   rl   r   r   r   r   rN   r   r   r   r   r   _  s   r   c                   @   s    e Zd Ze ZG dd dZdS )QuizGetModelSerializerc                   @   s   e Zd ZeZejjdg ZdS )zQuizGetModelSerializer.Meta	instituteN)r.   r/   r0   r
   rL   r   rN   rM   r   r   r   r   rN   ~  s   rN   N)r.   r/   r0   r   r   rN   r   r   r   r   r   {  s   r   c                   @   s.   e Zd ZejddZdd ZG dd dZdS )r   r   r\   c                 C   s   | j ddkr|jS d S d S r   r   rb   r   r   r   r     s    r   c                   @   s>   e Zd ZeZddddddddd	d
dddddddddddgZdS )r   rS   rT   r   r   r   r   r   rU   rV   r   r   rG   r   r   r   r   r   r   r   r   r   Nr   r   r   r   r   rN     s.   rN   Nr   r   r   r   r   r     s   c                   @   s   e Zd Ze ZdS )GetQuizInputSerializerNr.   r/   r0   r   r3   rS   r   r   r   r   r     s   r   c                   @   s   e Zd Ze ZdS )GetQuizTemplateInputSerializerNr   r   r   r   r   r     s   r   c                   @   sX   e Zd Ze ZejedgdZejede	dgdZ
ejegdZejddZdS )GetQuizSheetListInputSerializerr   r   r-   r(   Fr+   Nr.   r/   r0   r   r3   quiz_idr6   r   r7   r   r8   r&   r   name_filterr   r   r   r   r     s   r   c                   @   sP   e Zd ZejedgdZejededgdZej	e
gdZej	ddZdS )'GetQuizSheetAttendedListInputSerializerr   r   r-   r(   Fr   N)r.   r/   r0   r   r6   r   r7   r   r8   r3   r&   r   r   r   r   r   r   r     s   r   c                   @   sX   e Zd Ze ZejedgdZejede	dgdZ
ejegdZejddZdS )GetQuizStatInputSerializerr   r   r-   r(   Fr   Nr   r   r   r   r   r     s   r   c                 C   s   t j| tjtjtjd | S )N)imageimage_size_as_MBformatmax_side)r9   image_validetorr	   quiz_poster_maximum_size_mbquiz_poster_allowed_formatsquiz_poster_maximum_side_size)valuer   r   r   quiz_poster_valdator  s    r   c                   @   s   e Zd Ze ZejdddZe Ze	 Z
e	 Ze	 ZejegdZe	 Ze	 Ze	 ZejdegdZejddZejddZejddZejddd	d
ZejddZejddddZejdddZdS )CreateQuizInputSerializeri     )r*   
min_lengthr   F)r+   r   r   i  T)r*   r+   allow_blank   )r*   r   )r+   	min_valuedefaulti  )r+   r*   N)r.   r/   r0   r   r3   r2   rT   	JSONFieldruleBooleanFieldr   r   r   r$   r#   r   r   r   
ImageFieldr   rU   DateTimeFieldr   r   DurationFieldrG   r   r   r6   r   r   r   r   r   r   r     s,     r   c                   @   s   e Zd Ze ZdS )!CreateQuizTemplateInputSerializerNr.   r/   r0   r   r3   r   r   r   r   r   r     s   r   c                   @   s.   e Zd Ze ZejdddZejddZ	dS )EditQuizInputSerializerFr   r+   r   N)
r.   r/   r0   r   r3   r   r   remove_posterr   r   r   r   r   r   r     s   r   c                   @   s   e Zd Ze ZdS )!QuizReportCardTestInputSerializerNr   r   r   r   r   r     s   r   c                   @   s.   e Zd Ze ZejdddZejddZ	dS )EditQuizTemplateInputSerializerFr   r   N)
r.   r/   r0   r   r3   quiz_template_idr   r   r   r   r   r   r   r   r     s   r   c                   @   s   e Zd Ze Ze ZdS )ArchiveQuizInputSerializerN)r.   r/   r0   r   r3   r2   r   r   r   r   r   r     s   r   c                   @   s   e Zd Ze Ze ZdS )"ArchiveQuizTemplateInputSerializerN)r.   r/   r0   r   r3   r2   r   r   r   r   r   r   
  s   r   c                   @   sD   e Zd ZejddZejddZejddZejddZdd Z	dS )1BaseTokenQuizIDQuizSheetIDEntranceTokenSerializerFr   c                 C   s   t | |S r`   r   rc   rt   r   r   r   validate  s    z:BaseTokenQuizIDQuizSheetIDEntranceTokenSerializer.validateN)
r.   r/   r0   r   r3   tokenr   quiz_sheet_idrJ   r   r   r   r   r   r     s
   r   c                   @   s   e Zd ZdS )QuizGateWayInputSerializerNrz   r   r   r   r   r     s   r   c                   @   s   e Zd ZdS )QuizEnterInputSerializerNrz   r   r   r   r   r     s   r   c                       s$   e Zd Ze Z fddZ  ZS )SetAnswerInputSerializerc                    s2   t  | d|kr"tddit|d  |S )Nuser_inputszThis field is required)superr   r   r   r   r   	__class__r   r   r   &  s
    z!SetAnswerInputSerializer.validate)r.   r/   r0   r   r   r   r   __classcell__r   r   r   r   r   #  s   r   c                   @   s   e Zd ZdS )FinishQuizSheetInputSerializerNrz   r   r   r   r   r   .  s   r   c                   @   s   e Zd ZdS )QuizSheetReportInputSerializerNrz   r   r   r   r   r   2  s   r   c                   @   s   e Zd ZejddZdS )#QuizSheetAttendedGetInputSerializerTr   Nr.   r/   r0   r   r3   r   r   r   r   r   r   6  s   r   c                   @   s   e Zd ZejddZdS )QuizSheetGetInputSerializerTr   Nr   r   r   r   r   r   :  s   r   c                   @   s,   e Zd ZejddZejddZdd ZdS )InvoiceInputSerializerFr   c                 C   s   t | |S r`   r   r   r   r   r   r   F  s    zInvoiceInputSerializer.validateN)r.   r/   r0   r   r3   r   r   r   r   r   r   r   r   >  s   r   c                   @   s   e Zd ZejddZdS )!GetQuizIdFromExamIdInputValidatorTr   N)r.   r/   r0   r   r3   wikiazma_exam_idr   r   r   r   r   L  s   r   c                   @   sX   e Zd ZejddZejddZe ZejddZ	ejddZ
ejddZdd ZdS )GenerateQuizSheetInputValidatorFr   c                 C   sB   ddg}d}|D ],}||kr|r8t dd| d d}q|S )z;
        One out of many fields should be present.
        wikiazma_institute_student_id"referer_institute_student_identityFzOne of z and z is required.T)r   r   r   )rc   rt   rM   one_field_foundfieldr   r   r   r   X  s    z(GenerateQuizSheetInputValidator.validateN)r.   r/   r0   r   r3   r   r   wikiazma_quiz_idr   rE   rF   r   rG   r   r   r   r   r   r   P  s   r   c                   @   s   e Zd Ze ZdS )VerifyQuizSheetInputValidatorNr   r   r   r   r   r   h  s   r   c                   @   s<   e Zd Ze Ze Ze Z	ejddZ
ejddZdS )$QuizSheetCorrectionAddInputValidatorFr   N)r.   r/   r0   r   r3   r   r6   index
FloatFieldr}   comment_for_studentcomment_for_other_correctorsr   r   r   r   r   l  s
   r   rD   rI   rQ   rE   rF   rG   c                   @   s   e Zd ZG dd dZdS ),GetQuizSheetMinimumDataForStudentsSerializerc                   @   s   e Zd ZeZeZdS )z1GetQuizSheetMinimumDataForStudentsSerializer.MetaN)r.   r/   r0   r   rL   minimum_quiz_sheet_fieldsrM   r   r   r   r   rN     s   rN   NrO   r   r   r   r   r   ~  s   r   c                   @   s   e Zd ZG dd dZdS )"GetQuizSheetForInstituteSerializerc                   @   s   e Zd ZeZdddddgZdS )z'GetQuizSheetForInstituteSerializer.MetarD   rI   rQ   rH   rj   NrK   r   r   r   r   rN     s   rN   NrO   r   r   r   r   r     s   r   N)MZdjango.core.validatorsr   r   django.db.modelsr   rest_frameworkr   Zauthenticate.serializersr   institute.serializersr   r   rk   r	   quiz.modelsr
   r   r   r   r   r   r   Zquiz.validatorsr   r   utilsr   r9   r    r$   r&   
Serializerr'   rA   rB   ModelSerializerrC   rP   rR   rX   rZ   rm   ry   r{   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s|   $	0/)$
	

	
