예제 #1
0
def newQuiz():
    available_posts = db.session.query(Article).all()
    post_list = [(i.id, i.name) for i in available_posts]

    form = QuizForm()
    form.help_link.choices = post_list

    if form.validate_on_submit():
        question = Quiz(question=form.question.data,
                        answer1=form.answer1.data,
                        answer2=form.answer2.data,
                        answer3=form.answer3.data)
        if form.good_answer.data == 'Odpowiedź 1':
            question.good_answer = form.answer1.data
        elif form.good_answer.data == 'Odpowiedź 2':
            question.good_answer = form.answer2.data
        elif form.good_answer.data == 'Odpowiedź 3':
            question.good_answer = form.answer3.data
        question.help_link = form.help_link.data
        db.session.add(question)
        db.session.commit()
        flash('Dodano nowe pytanie!', 'success')
        return redirect(url_for('handle_articles'))

    return render_template('newQuiz.html',
                           title='Nowy artykuł',
                           form=form,
                           legend='Nowy artykuł',
                           categories=GetAllCategories())
예제 #2
0
파일: app.py 프로젝트: thaque/scratch
def quizsetup():
    global questions
    global definition
    global choices
    global answer
    global score
    global count
    global no
    score = 0
    count = 0
    answer = 0
    form = QuizForm()
    # if request.method == 'POST':
    #     try:
    #         no = form.no_of_questions.data
    #     except:
    #         message = f"Do you really think {request.form['answer']} is a valid response?"
    #         return render_template('quizsetup.html')
    #     if not no > 0:
    #         return f'''
    #             <html>
    #                 <body>
    #                     <p>How many questions?</p>
    #                     <form method='POST' action='/quizsetup'>
    #                     <p><input name='answer' /></p>
    #                     <p><input type='submit' value='Start'/></p>
    #                     </form>
    #                     <p>Do you really think {request.form['answer']} is a valid response?</p>
    #                 </body>
    #             </html>
    #             '''
    #     questions = generate_questions(no)
    #     definition = get_definition(questions[0])
    #     choices = generate_choices(definition)
    #     return redirect('/quiz')
    if form.validate_on_submit():
        flash(f'Quiz generated with {form.no_of_questions.data} Questions')
        no = form.no_of_questions.data
        questions = generate_questions(no)
        definition = get_definition(questions[0])
        choices = generate_choices(definition)
        return redirect(url_for('quiz'))
        # return f'''
        #     <html>
        #         <body>
        #             <p>{choices}</p>
        #         </body>
        #     </html>
        # '''
    return render_template('quizsetup.html', title='Quiz Setup', form=form, user=user)