Пример #1
0
def question():
    global points
    form_quest = QuestionForm()
    form_score = ScoreForm()
    data = read_json_file(json_questions)
    length = len(data) - 1
    while len(questions_made) < number_questions:
        random_index = generate(length)
        asked_questions.append(data[random_index])
        good_answer = data[random_index]['answer']
        if form_quest.validate_on_submit():
            my_answer = form_quest.answer.data
            if answering(my_answer):
                if my_answer == good_answer:
                    points += 1
                redirect('/question')
        return render_template('question.html',
                               question=data[random_index],
                               form=form_quest)
    score = (points * 100) / number_questions
    if form_score.validate_on_submit():
        correction = form_score.corrections.data
        if correction == 'Yes':
            return render_template('score.html',
                                   points=points,
                                   num_questions=number_questions,
                                   corrections=correction,
                                   questions=asked_questions,
                                   form=form_score,
                                   score=score)
    return render_template('score.html',
                           points=points,
                           num_questions=number_questions,
                           form=form_score,
                           score=score)
Пример #2
0
    def edit_question(course_id, test_id, question_id):
        course = Course.query.filter_by(id=course_id).first()
        test = Test.query.filter_by(id=test_id).first()
        q = Question.query.filter_by(id=question_id).first()
        form = QuestionForm()

        if form.delete.data:
            db.session.delete(q)
            db.session.commit()

            return redirect(
                url_for('edit_test_view', course_id=course_id,
                        test_id=test_id))

        if form.validate_on_submit():
            if form.save.data:
                q.test_id = test_id
                q.question_type = int(form.question_type.data)
                q.question_string = repr(form.description.data.encode())[2:-1]
                q.code_string = repr(form.code_string.data.encode())[2:-1]
                q.mcq_1 = form.mcq_1.data
                q.mcq_2 = form.mcq_2.data
                q.mcq_3 = form.mcq_3.data
                q.mcq_4 = form.mcq_4.data
                q.mcq_answer = form.mcq_solution.data
                q.answer = form.solution.data
                q.mark_alloc = form.mark_alloc.data
                db.session.commit()

                return redirect(
                    url_for('edit_test_view',
                            course_id=course_id,
                            test_id=test_id))
def create():
    form = QuestionForm()
    if request.method == 'POST' and form.validate_on_submit():
        question = Question(subject=form.subject.data, content=form.content.data,
                            create_date=datetime.now(), user=g.user)
        db.session.add(question)
        db.session.commit()
        return redirect(url_for('main.index'))
    return render_template('question/question_form.html', form=form)
Пример #4
0
def index():
    (a, b) = equation.getAB()
    question = "{} x {} = ?".format(a, b)
    form = QuestionForm()
    if form.validate_on_submit():
        flash('Data received: {}'.format(form.answer.data))
        equation.tryAnswer(int(form.answer.data))
        return redirect('/grade')
    return render_template('index.html', question=question, form=form)
Пример #5
0
def submitquestion():
    questionform = QuestionForm()
    if questionform.validate_on_submit():
        text = questionform.question.data
        raw = RawQuestion(question_text=text,
                          created_by=current_user.id,
                          user_email=current_user.email)
        db.session.add(raw)
        db.session.commit()
        return redirect(url_for("index"))
Пример #6
0
def admin():
    if current_user.admin:
        form = QuestionForm()
        if form.validate_on_submit():
            question = Questions(question=form.question.data,
                                 answers=form.answers.data,
                                 correct_answer=form.correct.data,
                                 speed=form.speed.data)
            db.session.add(question)
            db.session.commit()
            return redirect(url_for('admin'))
        return render_template('admin.html', form=form)
    else:
        return redirect(url_for('index'))
Пример #7
0
def start_quiz(quiz_id, current_question):
    form = QuestionForm()
    current_question = int(current_question)
    question_list = (
        db.session.execute('Select * from Question where quiz_id ==' +
                           str(quiz_id) + " ORDER BY question_id")).fetchall()
    quiz_name = (db.session.execute('Select * from Quiz where quiz_id ==' +
                                    str(quiz_id))).first()
    temp_list = question_list[current_question][4:8]
    user_id = str(current_user.get_id())
    saved_answers = (
        db.session.execute('Select * from results where question_id == ' +
                           str(question_list[current_question][0]) +
                           ' and user_id == ' + user_id)).first()
    option_list = []
    random_int = random.randrange(0, 4)
    #Load the previous answer if it exists and randomise the other answers order
    if saved_answers == None:
        option_list.append((None, "Select Answer"))
        for counter in range(len(temp_list)):
            option = temp_list[((random_int + counter) % 4)]
            option_list.append((option, option))
    #Otherwise create a list of answers and randomise order
    else:
        option_list.append((saved_answers[4], saved_answers[4]))
        for counter in range(len(temp_list)):
            option = temp_list[((random_int + counter) % 4)]
            if option == saved_answers[4]:
                continue
            option_list.append((option, option))
    form.set_options(option_list)
    #If user submits a valid answer load next question
    if form.validate_on_submit():
        submit_answer(quiz_id, question_list, form.answer.data,
                      current_question)
        if form.submit_answer.data:
            if current_question + 1 < len(question_list):
                return redirect(
                    url_for('start_quiz',
                            quiz_id=quiz_id,
                            current_question=current_question + 1))
            else:
                return redirect(url_for('quiz_results', quiz_id=quiz_id))
    return render_template('./question_page.html',
                           title=quiz_name[1],
                           question_list=question_list,
                           current_question=current_question,
                           quiz_name=quiz_name[1],
                           form=form,
                           quiz_id=quiz_id)
def modify(question_id):
    question = Question.query.get_or_404(question_id)
    if g.user != question.user:
        flash('수정권한이 없습니다')
        return redirect(url_for('question.detail', question_id=question_id))
    if request.method == 'POST':
        form = QuestionForm()
        if form.validate_on_submit():
            form.populate_obj(question)
            question.modify_date = datetime.now()  # 수정일시 저장
            db.session.commit()
            return redirect(url_for('question.detail', question_id=question_id))
    else:
        form = QuestionForm(obj=question)
    return render_template('question/question_form.html', form=form)
def questions():
    form = QuestionForm()
    if form.validate_on_submit():
        new_question = Question(question=form.question.data,
                                module=form.modules.data,
                                option_one=form.option_one.data,
                                option_two=form.option_two.data,
                                option_three=form.option_three.data,
                                option_four=form.option_four.data,
                                right_choice=form.right_choice.data)
        db.session.add(new_question)
        db.session.commit()
        flash('Die Frage wurde eingereicht.')
        flash('Sie muss noch von einem Tutor freigegeben werden.')
        return redirect(url_for('questions'))
    return render_template('questions.html', form=form)
Пример #10
0
def home():
    """ This is the home directory """
    question_form = QuestionForm()
    questions = get_questions()

    context = {
        'questions': questions,
        'question_form': question_form,
    }

    if question_form.validate_on_submit():
        set_question(question=question_form.question.data)
        flash('Se agrego la pregunta')
        return redirect(url_for('home'))

    return render_template('home.html', **context)
Пример #11
0
def question(quest_id):
    form = QuestionForm()
    page = request.args.get('page', 1, type=int)
    post = Post.query.filter_by(id=quest_id).first()
    if form.validate_on_submit():
        answer = Answer(body=form.answer.data, author=current_user, post=post)
        db.session.add(answer)
        db.session.commit()
        flash('Your answer is very good, bro!')
        return redirect(url_for('question', quest_id=quest_id))
    answers = Answer.query.filter_by(quest_id=quest_id).order_by(
        Answer.timestamp.desc())
    return render_template('question.html',
                           title='Question',
                           answers=answers,
                           form=form,
                           post=post)
Пример #12
0
def ask_question():
    form = QuestionForm()
    if form.validate_on_submit():
        data = form.data
        user = User.query.filter_by(username=session['user']).first()
        user_id = user.id
        question = Question(
            title=data['title'],
            label=data['cate'],
            detail=data['detail'],
            author_id=user_id,
            addtime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        )
        db.session.add(question)
        db.session.commit()
        return redirect('/')

    return render_template('ask.html', title='提问', form=form)
Пример #13
0
def find_questiontag():
    form = QuestionForm()
    if form.validate_on_submit():
        question = form.question.data
        # print(question)
        tags = model_predictions.run(question)
        tags = tags[0].strip('[]')
        tags_list = tags.split(',')

        final_tags = []
        for tag in tags_list:
            final_tags.append(tag.strip().strip('\''))

        tags_str = ',  '.join(final_tags)

        return render_template('print_questiontag.html',
                               tags=tags_str,
                               question=question)
    return render_template('find_questiontag.html', form=form)
Пример #14
0
def index():
    form = QuestionForm(meta={'csrf': True})
    if request.method == 'POST' and form.validate_on_submit():
        email = form.data['username']
        for fieldname, value in form.data.items():
            if fieldname == 'question_fields':
                array[fieldname] = value[0]
                #'question_fields': [{'csrf_token': u'', 'question11': u'Bus', 
                                    #'question10': u'Edmonton', 'question12': u' Toronto', 
                                    #'question5': u'sf', 'question4': u'dsafd', 'question7': u'fdsaf', 
                                    # 'question6': u'dsa', 'question1': u'fdsafs', 'question3': u'dsaf', 
                                    #'question2': u'fdsaf', 'question9': u'fdsfds', 'question8': u'dsaf'}]
                save_answer(value[0], email)
        flash('Questions are submmited by user {}'.format(
            form.username.data))
        return redirect('/')
    else:
        form.questions = Question.query.all()
    return render_template('questionForm.html', title='Task1', form=form)
Пример #15
0
def addQuestion():
    if current_user.tipo_usuario != 1:
        return redirect(url_for('index'))
    form = QuestionForm()
    if form.validate_on_submit():
        pregunta = Pregunta(pregunta=form.pregunta.data, year=form.year.data)
        pregunta.addPregunta()
        QuestionOption2.newOption(pregunta.id, form.respuesta1.data)
        QuestionOption2.newOption(pregunta.id, form.respuesta8.data)
        QuestionOption2.newOption(pregunta.id, form.respuesta7.data)
        QuestionOption2.newOption(pregunta.id, form.respuesta6.data)
        QuestionOption2.newOption(pregunta.id, form.respuesta5.data)
        QuestionOption2.newOption(pregunta.id, form.respuesta4.data)
        QuestionOption2.newOption(pregunta.id, form.respuesta3.data)
        QuestionOption2.newOption(pregunta.id, form.respuesta2.data)
        flash('Pregunta añadida correctamente')
        return redirect(url_for('adminProfile'))
    return render_template('addQuestion.html',
                           title='Nueva Pregunta',
                           form=form)
Пример #16
0
    def new_question(course_id, test_id):
        form = QuestionForm()

        if form.validate_on_submit():
            q = Question()
            q.test_id = test_id
            q.question_type = int(form.question_type.data)
            q.question_string = repr(form.description.data.encode())[2:-1]
            q.code_string = repr(form.code_string.data.encode())[2:-1]
            q.mcq_1 = form.mcq_1.data
            q.mcq_2 = form.mcq_2.data
            q.mcq_3 = form.mcq_3.data
            q.mcq_4 = form.mcq_4.data
            q.mcq_answer = form.mcq_solution.data
            q.answer = form.solution.data
            q.mark_alloc = form.mark_alloc.data

            db.session.add(q)
            db.session.commit()

        return redirect(
            url_for('edit_test_view', course_id=course_id, test_id=test_id))
Пример #17
0
def user(username):
    if not current_user.is_authenticated:
        return redirect(url_for('index'))

    question_form = QuestionForm()
    if request.method == "POST":
        if question_form.validate_on_submit():
            question = Question(asker_id=current_user.id,
                                asker_name=current_user.first_name + " " +
                                current_user.last_name,
                                topic=question_form.topic.data,
                                content=question_form.question.data,
                                category=question_form.category.data)

            db.session.add(question)
            db.session.commit()

            return redirect(url_for('q_a'))
        else:
            flash("Dikkatli ol biraz :)")
            return render_template('user/main.html', form=question_form)
    if request.method == "GET":
        return render_template('user/main.html', form=question_form)
Пример #18
0
def newQuestion():
    """Route to generate new questions."""
    form = QuestionForm()
    if form.validate_on_submit():
        question = Question(
            category=form.category.data,
            question=form.question.data,
            frontend=form.frontend.data,
            ans01=form.ans01.data,
            ans02=form.ans02.data,
            ans03=form.ans03.data,
            ans04=form.ans04.data,
            ans05=form.ans05.data,
            ans06=form.ans06.data,
            ans07=form.ans07.data,
            ans08=form.ans08.data,
            ans09=form.ans09.data,
            ans10=form.ans10.data,
            ans11=form.ans11.data,
            ans12=form.ans12.data,
            ans13=form.ans13.data,
            ans14=form.ans14.data,
            ans15=form.ans15.data,
            ans16=form.ans16.data,
            ans17=form.ans17.data,
            ans18=form.ans18.data,
            ans19=form.ans19.data,
            ans20=form.ans20.data,
            sort=form.sort.data,
        )
        db.session.add(question)
        db.session.commit()
        return redirect('/frage/neu')
    return render_template('newQuestion.html',
                           title='Neue Frage erfassen',
                           form=form)