Exemplo n.º 1
0
def check_quiz():
    engine = db_connect()
    create_deals_table(engine)
    Session = sessionmaker(bind=engine)
    sess = Session()

    if request.method == 'POST':
        category = request.form['category']
        answers = {}
        correct_answers = {}
        wrong_answers = {}
        if category == categories[1]:
            for r in request.form:
                if r != 'category':
                    answers[r] = request.form.getlist(r)
            for k, v in answers.items():
                answers[k] = '.,'.join(v)
                answers[k] += '.'

            for k, v in answers.items():
                q = sess.query(Question).filter(
                    Question.question_number == k).first()

                if v == q.correct_answer:
                    correct_answers[v] = q
                else:
                    wrong_answers[v] = q
        else:
            for r in request.form:
                if r != 'category':
                    answers[r] = request.form[r]

            for k, v in answers.items():
                q = sess.query(Question).filter(
                    Question.question_number == k).first()

                if v in q.correct_answer:
                    correct_answers[v] = q
                else:
                    wrong_answers[v] = q

        return render_template(
            'results.html',
            title='Results',
            correct_answers=correct_answers,
            wrong_answers=wrong_answers)
Exemplo n.º 2
0
def check_quiz():
    engine = db_connect()
    create_deals_table(engine)
    Session = sessionmaker(bind=engine)
    sess = Session()

    if request.method == 'POST':
        category = request.form['category']
        answers = {}
        correct_answers = {}
        wrong_answers = {}
        if category == categories[1]:
            for r in request.form:
                if r != 'category':
                    answers[r] = request.form.getlist(r)
            for k, v in answers.items():
                answers[k] = '.,'.join(v)
                answers[k] += '.'

            for k, v in answers.items():
                q = sess.query(Question).filter(
                    Question.question_number == k).first()

                if v == q.correct_answer:
                    correct_answers[v] = q
                else:
                    wrong_answers[v] = q
        else:
            for r in request.form:
                if r != 'category':
                    answers[r] = request.form[r]

            for k, v in answers.items():
                q = sess.query(Question).filter(
                    Question.question_number == k).first()

                if v in q.correct_answer:
                    correct_answers[v] = q
                else:
                    wrong_answers[v] = q

        return render_template('results.html',
                               title='Results',
                               correct_answers=correct_answers,
                               wrong_answers=wrong_answers)
Exemplo n.º 3
0
def get_data():
    engine = db_connect()
    create_deals_table(engine)
    Session = sessionmaker(bind=engine)
    sess = Session()

    if request.method == 'GET':
        section = int(request.args.get('section'))
        category = int(request.args.get('category'))
        q = sess.query(Question).filter(
            Question.section == sections[section],
            Question.type_of_quiz == categories[category]).order_by(
                Question.question_number).all()

        return render_template('quiz.html',
                               questions=q,
                               title=sections[section] + ': ' +
                               categories[category])
Exemplo n.º 4
0
def get_data():
    engine = db_connect()
    create_deals_table(engine)
    Session = sessionmaker(bind=engine)
    sess = Session()

    if request.method == 'GET':
        section = int(request.args.get('section'))
        category = int(request.args.get('category'))
        q = sess.query(Question).filter(
            Question.section == sections[section],
            Question.type_of_quiz == categories[category]
        ).order_by(Question.question_number).all()

        return render_template(
            'quiz.html',
            questions=q,
            title=sections[section]+': '+categories[category])
Exemplo n.º 5
0
def show_main():
    engine = db_connect()
    create_deals_table(engine)
    Session = sessionmaker(bind=engine)
    sess = Session()

    if request.method == 'POST':
        section = int(request.form['section'])
        category = int(request.form['category'])
        q = sess.query(Question).filter(
            Question.section == sections[section],
            Question.type_of_quiz == categories[category]).order_by(
                func.random()).all()[:20]

        return render_template('quiz_form.html',
                               questions=q,
                               title=sections[section] + ': ' +
                               categories[category])

    else:
        return render_template('start_form.html')
Exemplo n.º 6
0
def show_main():
    engine = db_connect()
    create_deals_table(engine)
    Session = sessionmaker(bind=engine)
    sess = Session()

    if request.method == 'POST':
        section = int(request.form['section'])
        category = int(request.form['category'])
        q = sess.query(Question).filter(
            Question.section == sections[section],
            Question.type_of_quiz == categories[category]
        ).order_by(func.random()).all()[:20]

        return render_template(
            'quiz_form.html',
            questions=q,
            title=sections[section]+': '+categories[category])

    else:
        return render_template('start_form.html')