Beispiel #1
0
def submit_answer():
    student = get_current_student()
    question_id = request.form['question_id']

    qions = Question.select().where(Question.id == question_id)

    for qion in qions:
        qion_type = qtype2str(qion.typ)

        text_answer = request.form.get('text_answer')
        if text_answer and text_answer != '':
            Answer.create(text=text_answer, question=qion, student=student)

        option_ids = request.form.getlist('option_ids[]')
        if len(option_ids) > 0:
            if qion_type == 'single':
                option_ids = option_ids[:1]

            final_opts = []

            for oid in option_ids:
                opts = Option.select().where(Option.question == qion).where(Option.id == oid)
                for opt in opts:
                    final_opts.append(opt)
                    break
                else:
                    return response_error('wrong_option')

            for opt in final_opts:
                    Answer.create(option=opt, question=qion, student=student)

        return response_success()

    return response_error('question_not_found')
Beispiel #2
0
def results_texts():
    user = auth.get_logged_in_user()
    question_id = request.form['question_id']

    qions = Question.select().join(Questionnaire).join(Category).where(
        Category.teacher == user).where(Question.id == question_id)

    for qion in qions:
        strtype = qtype2str(qion.typ)

        ret = {'question_type': strtype, 'question_answers': []}

        answers = Answer.select(Answer, Student).where(Answer.question == qion)

        for answer in answers:
            if answer.text:
                ret['question_answers'].append({
                    'text': answer.text,
                    'student': answer.student.name,
                    'id': answer.id
                })

        return json.dumps(ret)

    return response_error('question_not_found')
Beispiel #3
0
def results_texts():
    user = auth.get_logged_in_user()
    question_id = request.form['question_id']

    qions = Question.select().join(Questionnaire).join(Category).where(Category.teacher == user).where(Question.id == question_id)

    for qion in qions:
        strtype = qtype2str(qion.typ)

        ret = {'question_type': strtype, 'question_answers': []}

        answers = Answer.select(Answer, Student).where(Answer.question == qion)

        for answer in answers:
            if answer.text:
                ret['question_answers'].append({'text': answer.text, 'student': answer.student.name, 'id': answer.id})


        return json.dumps(ret)

    return response_error('question_not_found')