Пример #1
0
def create_question():
    form = QuestionForm(request.form)
    data = dict(request.form)
    data.pop('csrf_token', None)
    if form.validate():
        db.sqlalchemy_session.add(ormQuestion(question_text=data.get('question_text'), test_id=int(data.get('test_id'))))
        db.sqlalchemy_session.commit()
        return redirect('/questions')
    else:
        return 'errors'
Пример #2
0
def update_question(id):
    form = QuestionForm(request.form)
    data = dict(request.form)
    data.pop('csrf_token', None)
    if form.validate():
        question = db.sqlalchemy_session.query(ormQuestion).filter(ormQuestion.question_id == id).first()
        if question:
            question.question_text = data.get('question_text', question.question_text)
            db.sqlalchemy_session.commit()
            return redirect('/questions')
        else:
            return 'errors'
Пример #3
0
def student_certain_test(test_id):
    form = QuestionForm()
    db_session.global_init("db/database.sqlite")
    session = db_session.create_session()
    test = session.query(Tests).filter(Tests.id == test_id).first()
    testquestions = session.query(TestQuestions).filter(TestQuestions.test_id == test_id).all()
    questions = []
    for q in testquestions:
        questions.append(session.query(Questions).filter(Questions.id == q.id).first())
    len_q = len(questions)

    if form.is_submitted():
        answers = []
        for i in range(len_q):
            exec(f'answers.append(form.answer{i}.data)')

        correct_answers = []
        for question in questions:
            correct_answers.append(question.correct_answer)

        result = 0
        for count in range(len_q):
            if answers[count] == correct_answers[count]:
                result += 1

        if len_q != 0:
            if result // len_q * 100 > 85:
                mark = 5
            elif result // len_q * 100 > 70:
                mark = 4
            elif result // len_q * 100 > 50:
                mark = 3
            else:
                mark = 2

            post('https://ssstarsss.herokuapp.com/api/testresults', json={"test_id": test.id, "student_id": current_user.id,
                                                             "result": result, "mark": mark})
        return redirect('/student/results')

    return render_template('test.html', test=test, questions=questions, shuffle=shuffle, len_q=len_q, form=form)