U
    ÎbOd!  ã                   @   s¼   d dl mZ d dlmZmZmZmZ d dlmZ ej	r¸G dd„ dej
ƒZej ee¡ G dd„ dej
ƒZej ee¡ G dd	„ d	ej
ƒZej ee¡ G d
d„ dej
ƒZej ee¡ n dS )é    )Úadmin)ÚQuizTemplateÚQuizÚ	QuizSheetÚQuestionScore)Úsettingsc                   @   s   e Zd ZdZdZdS )ÚQuizTemplateAdmin)ÚnameÚ	instituteÚ
_blueprintÚsingle_question_at_a_timeÚreanswerableÚshuffle_questionsÚshuffle_choicesÚdescriptionÚcustom_report_cardÚ	quiz_typeÚmodified_atÚ
created_at© N)Ú__name__Ú
__module__Ú__qualname__Úlist_displayÚreadonly_fieldsr   r   r   ú&/var/www/wikiazma_server/quiz/admin.pyr      s   r   c                   @   s(   e Zd ZdZdZg Zdd„ Zdd„ ZdS )Ú	QuizAdmin)r	   r
   ÚstartÚendÚdurationÚpublicr   r   r   r   r   r   r   Úshort_first_questionÚcorrect_choicesr   r   )r	   r   c              
   C   sj   z4ddl m} ||jd d d d d ƒ}| ¡ W S  tk
rd } zt|ƒ W Y ¢dS d }~X Y nX d S )Nr   )ÚBeautifulSoupÚ
retrieversÚcontentsÚquestion_textzError parsing Blueprint)Zbs4r#   r   Zget_textÚ	ExceptionÚprint)ÚselfÚobjr#   ZsoupÚer   r   r   r!      s    
zQuizAdmin.short_first_questionc                 C   sz   |j d }g }|D ]b}|d D ]T}d|ks6|d d kr>  dS t|d ƒD ]&\}}|d d |krJ| |d ¡ qJqq|S )Nr$   r%   Úchoicesz)choices not found in one of the questionsr"   r   é   )r   Ú	enumerateÚappend)r)   r*   r$   r"   Z	retrieverÚcontentÚindexÚchoicer   r   r   r"   "   s    
zQuizAdmin.correct_choicesN)r   r   r   r   Úsearch_fieldsr   r!   r"   r   r   r   r   r      s
   	r   c                   @   s   e Zd ZdZdgZdZdZdS )ÚQuizSheetAdmin)ÚstateÚentrance_tokenÚquizÚfinal_scoreÚstatsÚentrance_dateÚallowed_start_atÚallowed_finish_atr   ÚuserÚinstitute_studentr   r   r5   r   )r6   N)r   r   r   r   Úlist_filterr   r3   r   r   r   r   r4   5   s   r4   c                   @   s   e Zd ZdZdZdZdS )ÚQuestionScoreAdmin)Ú	correctorÚ
quiz_sheetÚquestionÚblankÚscorer   r   )Úcorrector__last_nameÚcorrector__first_namer   N)r   r   r   r   r3   r   r   r   r   r   r@   A   s   r@   N)Zdjango.contribr   Úquiz.modelsr   r   r   r   Zwikiazmar   ÚDJANGO_ADMIN_IS_ENABLEDÚ
ModelAdminr   ÚsiteÚregisterr   r4   r@   r   r   r   r   Ú<module>   s    	