def route_question(question_id): question = data_handler.get_data_by_id(question_id, 'question')[0] if request.method == "GET" and not request.args.get("answer_id"): question["view_number"] = int(question["view_number"]) + 1 data_handler.edit_row('question', question) answer_id_for_comment = request.args.get("answer_id") comment_to_question = request.args.get("comment_to_question") answers = data_handler.get_answers_by_qid(question_id) comments = data_handler.get_comments_by_question(question) if request.args.get("answer_to_edit"): answer_to_edit = data_handler.get_data_by_id( str(request.args.get("answer_to_edit")), "answer")[0] else: answer_to_edit = {} comment_to_edit = dict(request.form) user_data = {} if 'username' in request.cookies: username = request.cookies.get('username') user_data = data_handler.get_data_by_username(username)[0] return render_template("question.html", question=question, answers=answers, comments=comments, answer_id=answer_id_for_comment, comment_to_question=comment_to_question, comment_to_edit=comment_to_edit, answer_to_edit=answer_to_edit, user_data=user_data)
def route_edit(question_id): if request.method == "POST": data_handler.edit_row("question", request.form) return redirect( url_for("route_question", question_id=request.form.get("id"))) question = data_handler.get_data_by_id(question_id, 'question')[0] return render_template("add-question.html", question=question)
def route_answer_vote_down(answer_id): answer = data_handler.get_data_by_id(answer_id, 'answer')[0] question_id = str(answer["question_id"]) answer["vote_number"] = int(answer["vote_number"]) - 1 question = data_handler.get_data_by_id(question_id, 'question')[0] question["view_number"] = int(question["view_number"]) - 1 data_handler.edit_row("question", question) data_handler.edit_row("answer", answer) return redirect(url_for("route_question", question_id=question_id))
def route_edit_comment(comment_id): if request.method == "POST": edited_comment = dict(request.form) edited_comment["edited_count"] = int( edited_comment["edited_count"]) + 1 data_handler.edit_row("comment", edited_comment) if request.form.get("question_id") != 'NULL': question_id = data_handler.get_data_by_id( comment_id, "comment")[0]["question_id"] else: question_id = \ data_handler.get_data_by_id(str(data_handler.get_data_by_id(comment_id, "comment")[0]["answer_id"]), "answer")[0]["question_id"] return redirect(url_for("route_question", question_id=question_id))
def route_edit_answer(answer_id): data_handler.edit_row("answer", request.form) question_id = data_handler.get_data_by_id(answer_id, "answer")[0]["question_id"] return redirect(url_for("route_question", question_id=question_id))
def route_question_vote_down(question_id): question = data_handler.get_data_by_id(question_id, 'question')[0] question["vote_number"] = int(question["vote_number"]) - 1 question["view_number"] = int(question["view_number"]) - 1 data_handler.edit_row("question", question) return redirect(url_for("route_question", question_id=question_id))