def answer_vote(answer_id, vote): if vote == 'up': data_manager.vote('answer', 1, answer_id) else: data_manager.vote('answer', -1, answer_id) changed_answer = data_manager.get_table_by_id(answer_id, "answer") return redirect('/question/' + str(changed_answer['question_id']))
def delete_comment(comment_id): comment = data_manager.get_table_by_id(comment_id, "comment") question_id = comment['question_id'] if question_id is None: question_id = data_manager.get_answer_by_id(comment['answer_id'])['question_id'] data_manager.delete_from_table_by_id(comment_id, "comment") return redirect('/question/' + str(question_id))
def edit_answer(answer_id): answer = data_manager.get_table_by_id(answer_id, "answer") if request.method == 'POST': my_new_data = request.form.to_dict() data_manager.edit_answer(my_new_data) return redirect('/question/' + str(my_new_data['question_id'])) return render_template('edit_answer.html', answer=answer)
def edit_question(question_id): question = data_manager.get_table_by_id(question_id, "question") if request.method == 'POST': my_new_data = request.form.to_dict() data_manager.edit_question(my_new_data) return redirect('/question/' + str(my_new_data['question_id'])) return render_template('edit_question.html', question=question, )
def add_comment_to_answer(answer_id): answer_headers = ['message', 'submission_time', 'vote_number', 'image'] answer = data_manager.get_table_by_id(answer_id, "answer") if request.method == 'POST': new_comment = request.form.to_dict() data_manager.add_comment_to_answer(new_comment) return redirect('/question/' + str(request.form.get('question_id'))) return render_template('post_comment_to_answer.html', answer=answer, answer_headers=answer_headers)
def add_comment_to_question(question_id): question = data_manager.get_table_by_id(question_id, "question") question_headers = ['title', 'message', 'submission_time', 'view_number', 'vote_number', 'image'] if request.method == 'POST': new_comment = request.form.to_dict() data_manager.add_comment_to_question(new_comment) return redirect('/question/' + new_comment['question_id']) return render_template('add_comment_to_question.html', question_headers=question_headers, question=question)
def add_new_answer(question_id): question = data_manager.get_table_by_id(question_id, "question") if request.method == 'POST': new_answer = request.form.to_dict() data_manager.add_answer(new_answer) return redirect('/question/' + new_answer['question_id']) else: return render_template('post_answer.html', question=question)
def edit_comment(comment_id): comment = data_manager.get_table_by_id(comment_id, "comment") question_id = comment['question_id'] if question_id is None: question_id = data_manager.get_answer_by_id(comment['answer_id'])['question_id'] if request.method == 'POST': my_new_data = request.form.to_dict() data_manager.edit_comment(my_new_data) return redirect('/question/' + str(question_id)) return render_template('edit_comment.html', comment=comment, question_id=str(question_id))
def add_tag_to_question(question_id): question_headers = ['title', 'message', 'submission_time', 'view_number', 'vote_number', 'image'] question = data_manager.get_table_by_id(question_id, "question") tags = data_manager.get_all_tags() if request.method == 'POST': if request.form.get("selector") == "custom": question_id = request.form.get("question_id") name = request.form.get("tag_message").strip().lower() data_manager.add_new_tag_to_tags(name) id = data_manager.get_tag_id(name) data_manager.add_new_tag_to_question(request.form.get("question_id"), id['id']) else: question_id = request.form.get("question_id") name = request.form.get("selector") id = data_manager.get_tag_id(name) data_manager.add_new_tag_to_question(request.form.get("question_id"), id['id']) return redirect('/question/' + str(question_id)) return render_template('add_tag_to_question.html', question=question, tags=tags, question_headers=question_headers)
def route_question(question_id): question_headers = ['title', 'message', 'submission_time', 'view_number', 'vote_number', 'image'] answer_headers = ['message', 'submission_time', 'vote_number', 'image', 'user_options'] question = data_manager.get_table_by_id(question_id, "question") answers = data_manager.get_answer_by_question_id(question_id) answer_ids = tuple([answer['id'] for answer in answers]) if len(answer_ids) > 0: answer_comments = data_manager.get_comments_by_answer_idlist(answer_ids) else: answer_comments = None tags = data_manager.get_tags_by_question_id(question_id) question_comments = data_manager.get_comments_by_question_id(question_id) return render_template('question.html', question=question, question_title='Question', answers=answers, question_headers=question_headers, answer_headers=answer_headers, tags=tags, question_comments=question_comments, answer_comments=answer_comments )
def delete_answer(answer_id): answer = data_manager.get_table_by_id(answer_id, "answer") data_manager.delete_from_table_by_id(answer_id, "answer") return redirect('/question/' + str(answer['question_id']))