Пример #1
0
def options_delete(question_id, option_id):
    o = Option.query.get(option_id)
    db.session.query(UsersChoice).filter_by(option_id=o.id).delete()
    db.session().delete(o)
    db.session().commit()
    answer = Option.query.filter_by(quest_id=question_id, correct=True).first()
    if not answer:
        q = Question.query.get(question_id)
        q.active = False
        db.session().commit()
        quizquestions = QuizQuestion.query.filter_by(question_id=q.id)
        for qq in quizquestions:
            quiz = Quiz.query.get(qq.quiz_id)
            db.session().delete(qq)
            db.session().commit()
            if quiz.active == True:
                questions = Quiz.findAllQuestions(quiz.id)
                if len(questions) < 2:
                    quiz.active = False
                    db.session().commit()
        return render_template(
            "questions/modify.html",
            question=Question.query.get(question_id),
            options=Option.query.filter_by(quest_id=question_id).all(),
            opt_form=OptionForm(),
            q_form=ModifyQuestionForm(),
            c_form=ModifyCategoryForm(),
            d_form=ModifyDifficultyForm(),
            act_error=
            "Question was deactivated because it has no correct answer")

    return redirect(url_for('questions_modify', question_id=question_id))
Пример #2
0
def questions_modifyDifficulty(question_id):
    d_form = ModifyDifficultyForm(request.form)

    q = Question.query.get(question_id)
    q.difficulty = d_form.difficulty.data

    db.session().commit()

    return redirect(url_for('questions_modify', question_id=question_id))
Пример #3
0
def question_activate(question_id):
    q = Question.query.get(question_id)
    if q.active == True:
        q.active = False
        quizquestions = QuizQuestion.query.filter_by(question_id=q.id)
        for qq in quizquestions:
            quiz = Quiz.query.get(qq.quiz_id)
            db.session().delete(qq)
            db.session().commit()
            if quiz.active == True:
                questions = Quiz.findAllQuestions(quiz.id)
                if len(questions) < 2:
                    quiz.active = False
                    db.session().commit()
    else:
        answer = Option.query.filter_by(quest_id=question_id,
                                        correct=True).first()
        if not answer:
            return render_template(
                "questions/modify.html",
                question=Question.query.get(question_id),
                options=Option.query.filter_by(quest_id=question_id).all(),
                opt_form=OptionForm(),
                q_form=ModifyQuestionForm(),
                c_form=ModifyCategoryForm(),
                d_form=ModifyDifficultyForm(),
                act_error=
                "Question has no correct answer and cannot be activated")
        reports = Report.query.filter_by(question_id=question_id,
                                         checked=False).all()
        if len(reports) > 0:
            return render_template(
                "questions/modify.html",
                question=Question.query.get(question_id),
                options=Option.query.filter_by(quest_id=question_id).all(),
                opt_form=OptionForm(),
                q_form=ModifyQuestionForm(),
                c_form=ModifyCategoryForm(),
                d_form=ModifyDifficultyForm(),
                act_error="Question has been reported and cannot be activated")
        q.active = True
    db.session().commit()

    return redirect(url_for('questions_modify', question_id=question_id))
Пример #4
0
def questions_modify(question_id):
    q = Question.query.get(question_id)
    if q.account_id != current_user.id and current_user.role != "ADMIN":
        return login_manager.unauthorized()
    return render_template(
        "questions/modify.html",
        question=Question.query.get(question_id),
        options=Option.query.filter_by(quest_id=question_id).all(),
        opt_form=OptionForm(),
        q_form=ModifyQuestionForm(),
        c_form=ModifyCategoryForm(),
        d_form=ModifyDifficultyForm())
Пример #5
0
def questions_modifyQuestion(question_id):
    q_form = ModifyQuestionForm(request.form)
    if not q_form.validate():
        return render_template(
            "questions/modify.html",
            question=Question.query.get(question_id),
            options=Option.query.filter_by(quest_id=question_id).all(),
            opt_form=OptionForm(),
            q_form=q_form,
            c_form=ModifyCategoryForm(),
            d_form=ModifyDifficultyForm())

    q = Question.query.get(question_id)
    q.name = q_form.name.data

    db.session().commit()

    return redirect(url_for('questions_modify', question_id=question_id))
Пример #6
0
def options_add(question_id):
    opt_form = OptionForm(request.form)

    if not opt_form.validate():
        return render_template(
            "questions/modify.html",
            question=Question.query.get(question_id),
            options=Option.query.filter_by(quest_id=question_id).all(),
            opt_form=OptionForm(),
            q_form=ModifyQuestionForm(),
            c_form=ModifyCategoryForm(),
            d_form=ModifyDifficultyForm())

    o = Option(opt_form.name.data, opt_form.correct.data)
    o.quest_id = question_id

    db.session().add(o)
    db.session().commit()

    return redirect(url_for('questions_modify', question_id=question_id))