예제 #1
0
def list_questions():
    all_question = data_handler.get_all_question()
    sorted_questions = connection.sort_the_questions(
        all_question, request.args.get('order_by'),
        request.args.get('order_direction'))
    return render_template("question_list.html",
                           all_question=sorted_questions,
                           header=data_handler.QUESTIONS_HEADER)
예제 #2
0
def delete_question(question_id):
    all_question = data_handler.get_all_question()
    connection.write_csv_file(data_handler.QUESTION_FILE, all_question,
                              data_handler.QUESTIONS_HEADER, question_id)
    all_answer = data_handler.get_all_answer()
    connection.write_csv_file(data_handler.ANSWER_FILE, all_answer,
                              data_handler.ANSWERS_HEADER, question_id)
    return redirect("/")
예제 #3
0
def display_question(id):
    comments = []
    answers = data_handler.get_all_answer(id)
    questions = data_handler.get_all_question(id)
    header = data_handler.get_header()
    answers_header = data_handler.get_answer_header()
    comment_to_question = data_handler.get_comment_by_question_id(id)
    for answer in answers:
        comments.append(data_handler.get_comments_by_answer_id(answer["id"]))
        print(comments)
    return render_template('display.html',
                           questions=questions,
                           answers=answers,
                           comment_to_question=comment_to_question,
                           comments=comments)
예제 #4
0
def edit_question(question_id):
    question_by_id = data_handler.get_questions_by_id(
        question_id, data_handler.QUESTION_FILE)
    if request.method == 'POST':
        edited_question_data = data_handler.edit_question(
            request.form.items(), question_id)
        all_question = data_handler.get_all_question()
        connection.write_csv_file(data_handler.QUESTION_FILE, all_question,
                                  data_handler.QUESTIONS_HEADER, question_id)
        connection.append_csv_file(data_handler.QUESTION_FILE,
                                   edited_question_data.values())
        return redirect("/question/" + question_id)
    return render_template("edit_question.html",
                           question_id=question_id,
                           message=question_by_id['message'],
                           title=question_by_id['title'])
예제 #5
0
def add_answer(question_id):
    if request.method == 'POST':
        vote_number = request.form["vote_number"]
        message = request.form["message"]
        image = request.form["image"]
        data_handler.insert_answer_table(vote_number, question_id, message,
                                         image)
        return redirect(url_for("display_question", id=question_id))

    question = data_handler.get_all_question(question_id)
    # for num in question_container:
    #     if num["id"] == int(question_id):
    #         question_number = num
    #         print(num)
    return render_template('add_answer.html',
                           question=question,
                           question_id=question_id)