def select_all(): questions = [] sql = "SELECT * FROM questions" results = run_sql(sql) for result in results: difficulty = difficulty_repository.select(result["difficulty_id"]) topic = topic_repository.select(result["topic_id"]) user_topic = user_topic_repository.select(result["user_topic_id"]) question = Question(result["the_question"], result["correct_answer"], result["alt_ans_1"], result["alt_ans_2"], result["alt_ans_3"], difficulty, topic, user_topic, result["used"], result["id"]) questions.append(question) return questions
def select(id): question = None sql = "SELECT * FROM questions WHERE id = %s" values = [id] result = run_sql(sql, values)[0] difficulty = difficulty_repository.select(result["difficulty_id"]) topic = topic_repository.select(result["topic_id"]) user_topic = user_topic_repository.select(result["user_topic_id"]) if result is not None: question = Question(result["the_question"], result["correct_answer"], result["alt_ans_1"], result["alt_ans_2"], result["alt_ans_3"], difficulty, topic, user_topic, result["used"], result["id"]) return question
def select_all(): quizzes = [] sql = "SELECT * FROM quizzes" results = run_sql(sql) for result in results: difficulty = difficulty_repository.select(result["difficulty_id"]) topic = topic_repository.select(result["topic_id"]) quiz = Quiz(result["date"], result["number_of_questions"], difficulty, topic, result["question_list"], result["id"]) quizzes.append(quiz) return quizzes
def select(id): quiz = None sql = "SELECT * FROM quizzes WHERE id = %s" values = [id] result = run_sql(sql, values)[0] difficulty = difficulty_repository.select(result["difficulty_id"]) topic = topic_repository.select(result["topic_id"]) if result is not None: quiz = Quiz(result["date"], result["number_of_questions"], difficulty, topic, result["question_list"]) return quiz
def update_quiz(id): date = request.form["date"] number_of_questions = request.form["number_of_questions"] difficulty_id = request.form["difficulty_id"] difficulty = difficulty_repository.select(difficulty_id) topic_id = request.form["topic_id"] topic = topic_repository.select(topic_id) question_list = request.form["question_list"] quiz = Quiz(date, number_of_questions, difficulty, topic, question_list, id) quiz_repository.update(quiz) return redirect("/quizzes")
def create_quiz(): date = request.form["date"] number_of_questions = request.form["number_of_questions"] difficulty_id = request.form["difficulty"] difficulty = difficulty_repository.select(difficulty_id) topic_id = request.form["topic"] topic = topic_repository.select(topic_id) for question in number_of_questions: question_list.append(question) return question_list new_quiz = Quiz(date, number_of_questions, difficulty, topic, question_list) quiz_repository.save(new_quiz) return redirect("/quizzes")
def create_question(): the_question = request.form["the_question"] correct_answer = request.form["correct_answer"] alt_ans_1 = request.form["alt_ans_1"] alt_ans_2 = request.form["alt_ans_2"] alt_ans_3 = request.form["alt_ans_3"] difficulty_id = request.form["difficulty"] difficulty = difficulty_repository.select(difficulty_id) topic_id = request.form["topic"] topic = topic_repository.select(topic_id) user_topic_id = request.form["user_topic"] user_topic = user_topic_repository.select(user_topic_id) used = False new_question = Question(the_question, correct_answer, alt_ans_1, alt_ans_2, alt_ans_3, difficulty, topic, user_topic, used) question_repository.save(new_question) return redirect("/questions")
def update_question(id): the_question = request.form["the_question"] correct_answer = request.form["correct_answer"] alt_ans_1 = request.form["alt_ans_1"] alt_ans_2 = request.form["alt_ans_2"] alt_ans_3 = request.form["alt_ans_3"] difficulty_id = request.form["difficulty_id"] difficulty = difficulty_repository.select(difficulty_id) topic_id = request.form["topic_id"] topic = topic_repository.select(topic_id) user_topic_id = request.form["user_topic_id"] user_topic = user_topic_repository.select(user_topic_id) used = None question = Question(the_question, correct_answer, alt_ans_1, alt_ans_2, alt_ans_3, difficulty, topic, user_topic, used, id) question_repository.update(question) return redirect("/questions")