Example #1
0
def show_quizzes():
	if not session.get('logged_in'):
		return redirect(url_for('login'))
	
	courseID = int(request.args.get('courseID'))
	db = get_db()
	course = Course.getCourseFromDB(courseID,db)
	quizzes = course.getQuizzes(db)
	return render_template('quizzes.html', course = course, quizzes = quizzes)
Example #2
0
def show_course():
	if not session.get('logged_in'):
		return redirect(url_for('login'))

	courseID = int(request.args.get('courseID'))
	db = get_db()
	
	course = Course.getCourseFromDB(courseID,db)
	sections = course.getSections(db)

	return render_template('course.html', course = course, sections = sections)
Example #3
0
def new_quiz():
	if not session.get('logged_in'):
		return redirect(url_for('login'))

	courseID = int(request.args.get('courseID'))
	db = get_db()	
	course = Course.getCourseFromDB(courseID,db)
	sections = course.getSections(db)
	questions = course.getQuestions(db)

	if request.method == 'POST':
		if request.form['action'] == 'save':
			title = request.form['title']
			description = request.form['description']
			sectionIds = request.form.getlist('section')
			questionIds = request.form.getlist('question')
			Quiz.newQuiz(title, description, sectionIds, questionIds, db)
			flash("Quiz saved!")
		return redirect(url_for('show_quizzes', courseID=courseID))

	return render_template('new_quiz.html', courseID = courseID, sections = sections, questions = questions)
Example #4
0
def edit_quiz():
	if not session.get('logged_in'):
		return redirect(url_for('login'))

	courseID = int(request.args.get('courseID'))
	quizID = int(request.args.get('quizID'))
	db = get_db()
	quiz = Quiz.getQuizFromDB(quizID,db)
	course = Course.getCourseFromDB(courseID,db)
	sections = course.getSections(db)
	questions = course.getQuestions(db)

	if request.method == 'POST':
		if request.form['action'] == 'save':
			quiz.title = request.form['title']
			quiz.description = request.form['description']
			sectionIds = request.form.getlist('section')
			questionIds = request.form.getlist('question')
			quiz.saveChanges(sectionIds, questionIds, db)
			flash("Quiz saved!")
		return redirect(url_for('show_quizzes', courseID=courseID))
	else:
		selectedSecIds = quiz.getSectionIds(db)
		for section in sections:
			section.check = 0
			for secId in selectedSecIds:
				if section.id == secId:
					section.check = 1

		selectedQIds = quiz.getQuestionIds(db)
		for question in questions:
			question.check = 0
			for qId in selectedQIds:
				if question.id == qId:
					question.check = 1

	return render_template('edit_quiz.html', courseID = courseID, quiz = quiz, sections = sections, questions = questions)