def edit_comment(comment_id=None): question_comment = persistence.get_item_by_id("comment", comment_id) question_id = question_comment[0]['question_id'] question = persistence.get_item_by_id("question", question_id) if request.method == "GET": return render_template('add_comment.html', question_comment=question_comment, question=question, question_id=question_id) if request.method == "POST": question_comment[0]['message'] = request.form["comment"] persistence.edit_comment(question_comment) return redirect('/question/' + str(question_id))
def write_answer(question_id=None): questions = persistence.get_item_by_id("question", question_id) user_list = logic.show_the_users() return render_template('post_answer.html', questions=questions, question_id=question_id, user_list=user_list)
def new_question_comment(question_id=None): if request.method == "GET": question = persistence.get_item_by_id("question", question_id) return render_template('add_comment.html', question=question, question_id=question_id) if request.method == "POST": dict = logic.comment_dict(request.form["comment"], question_id=question_id) persistence.add_row_to_db(dict, "comment") return redirect('/question/' + str(question_id))
def new_question_comment(question_id=None): if request.method == "GET": user_list = logic.show_the_users() question = persistence.get_item_by_id("question", question_id) return render_template('add_comment.html', question=question, question_id=question_id, user_list=user_list) if request.method == "POST": user_id = persistence.get_user_id(request.form["username"])[0]['id'] dict = logic.comment_dict(request.form["comment"], question_id=question_id) persistence.add_row_to_db(dict, "comment", user_id) return redirect('/question/' + str(question_id))
def view_question(question_id=None): question = persistence.get_item_by_id("question", question_id) questions_answer = persistence.get_item_by_foreign_key( 'answer', question_id, "question_id") question_comment = persistence.get_item_by_foreign_key( 'comment', question_id, "question_id") answer_ids = logic.get_answer_ids(questions_answer) answer_comment = logic.get_answer_comments(answer_ids) labels = logic.get_list_of_headers(question) labels_answer = logic.get_list_of_headers(questions_answer) labels_question_comment = logic.get_list_of_headers(question_comment) labels_answer_comment = logic.get_list_of_headers(answer_comment) return render_template('display_question.html', question=question, questions_answer=questions_answer, labels=labels, question_id=question_id, labels_answer=labels_answer, question_comment=question_comment, answer_comment=answer_comment, labels_question_comment=labels_question_comment, labels_answer_comment=labels_answer_comment)
def delete_comment(comment_id=None): question_id = persistence.get_item_by_id('comment', comment_id)[0]["question_id"] persistence.delete_item('comment', comment_id) return redirect('/question/' + str(question_id))
def write_answer(question_id=None): questions = persistence.get_item_by_id("question", question_id) return render_template('post_answer.html', questions=questions, question_id=question_id)