def editqn(qnID): """Renders the edit questions page for educators.""" if not current_user.check_educator(): return render_template('errors/error403.html'), 403 qn = validate_qn_link(qnID, current_user.id) form = QuestionForm() if request.method == 'GET': topicID = qn.topicID if qn.topicID else 0 form.topic.data = topicID form.qn.data = qn.question options = [option.option for option in qn.options] form.op1.data, form.op2.data, form.op3.data, form.op4.data = options for i in range(len(options)): if qn.options[i].id == qn.answerID: form.corrOp.data = i + 1 break if form.validate_on_submit(): #Commit inputs to database options = (form.op1.data, form.op2.data, form.op3.data, form.op4.data) edit_question(qn, form.qn.data, options, form.corrOp.data, form.topic.data) flash('Question Edited Successfully!') return redirect(url_for('main.dashboard')) return render_template('quiz/createqn.html', title=' | Create Quiz', form=form, edit=True)
def preview_quiz(quizID): """Renders the preview quiz page for educators.""" if not current_user.check_educator(): return render_template('errors/error403.html'), 403 quiz = validate_quiz_link(current_user, quizID) questions = get_questions_quiz(quiz) delQuizForm = DeleteForm(prefix='quiz') delQnForm = DeleteForm(prefix='qn') return render_template('quiz/previewquiz.html', title=' | Create Class', questions=questions, quiz=quiz, delQuizForm=delQuizForm, delQnForm=delQnForm)
def deletequiz(quizID): """Renders the create quiz page for educators.""" if not current_user.check_educator(): return render_template('errors/error403.html'), 403 quiz = validate_quiz_link(current_user, quizID) delQuizForm = DeleteForm(prefix='quiz') delQnForm = DeleteForm(prefix='qn') if delQuizForm.validate_on_submit(): remove_quiz(quiz) flash('Quiz deleted') return redirect(url_for('main.dashboard'))
def deleteqn(quizID, qnID): """Routing to delete a question from a quiz for educators.""" if not current_user.check_educator(): return render_template('errors/error403.html'), 403 quiz = validate_quiz_link(current_user, quizID) qn = validate_qn_link(qnID, current_user.id) delQuizForm = DeleteForm(prefix='quiz') delQnForm = DeleteForm(prefix='qn') if delQnForm.validate_on_submit(): remove_question_quiz(quiz, qn) flash('Question removed from Quiz') return redirect(url_for('quiz.preview_quiz', quizID=quizID))
def createquiz(): """Renders the create quiz page for educators.""" if not current_user.check_educator(): return render_template('errors/error403.html'), 403 classForm = NameForm(prefix='class') quizForm = NameForm(prefix='quiz') image_file = get_image_file(current_user) if quizForm.validate_on_submit(): quiz = add_quiz(current_user, quizForm.title.data) if quiz is None: flash('You have already created a Quiz with this name. Please choose a different name.', 'warning') return redirect(url_for('main.dashboard')) return redirect(url_for('quiz.createqn', quizID=quiz.id)) return render_template('dashboard.html', image_file=image_file, classForm=classForm, quizForm=quizForm)
def delete_thread(groupID, threadID): # Check validity of link access first if not current_user.check_educator(): return render_template('errors/error403.html'), 403 group = validate_group_link(current_user, groupID) thread = Thread.query.filter_by(groupID=groupID,id=threadID).first_or_404() postForm = PostForm() delThreadForm = DeleteForm(prefix="thread") delPostForm = DeleteForm(prefix="post") if delThreadForm.validate_on_submit(): remove_thread(thread) flash('Thread deleted') return redirect(url_for('forum.forum', groupID=groupID))
def createqn(quizID): """Renders the add questions page for educators.""" if not current_user.check_educator(): return render_template('errors/error403.html'), 403 quiz = validate_quiz_link(current_user, quizID) form = QuestionForm() delQuizForm = DeleteForm(prefix='quiz') delQnForm = DeleteForm(prefix='qn') if form.validate_on_submit(): #Commit inputs to database options = (form.op1.data, form.op2.data, form.op3.data, form.op4.data) question = add_question(current_user, form.qn.data, options, form.corrOp.data, form.topic.data) if form.img.data: question.image_file = update_qn_image(form.img.data) add_question_quiz(quiz, question) flash('Question added') if form.complete.data: return redirect(url_for('quiz.createquizsuccess', quizID=quizID)) return redirect(url_for('quiz.createqn', quizID=quizID)) return render_template('quiz/createqn.html', title=' | Create Quiz', form=form, quiz=quiz,delQuizForm=delQuizForm, delQnForm=delQnForm)
def createquizsuccess(quizID): """Renders the create quiz was a success page for educators.""" if not current_user.check_educator(): return render_template('errors/error403.html'), 403 return render_template('quiz/createquizsuccess.html', title=' | Create Quiz', quizID=quizID)