models.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:research-eGrader 作者: openstax 项目源码 文件源码
def get_parsed_exercise(exercise_id):
    """
    Get the JSON exercise data from the exercise.data field
    This is where the feedback, answers, and other info is located

    Parameters
    ----------
    exercise_id

    Returns
    -------

    """
    exercise = Exercise.get(exercise_id)

    subject = Subject.get(exercise.subject_id)
    answer_html = 'Question not supplied with a correct answer'

    if exercise.book_row_id:
        book_url = '{0}:{1}'.format(subject.book_url, exercise.book_row_id)
    else:
        book_url = subject.book_url

    e_data = exercise.data['questions'][0]

    # Create a list for the feedback_choices
    feedback_choices = []

    # Get the correct answer
    for answer in e_data['answers']:
        if 'feedback_html' in answer and answer['feedback_html']:
            feedback = (str(answer['id']), answer['feedback_html'])
            feedback_choices.append(feedback)
        if answer['correctness'] == '1.0':
            answer_html = answer['content_html']

    # Get number of responses

    return dict(id=exercise.id,
                exercise_html=e_data['stem_html'],
                answer_html=answer_html,
                feedback_choices=feedback_choices,
                uid=exercise.uid,
                book_url=book_url,
                chapter_id=exercise.chapter_id
                )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号