def route_delete_answer(answer_id): current_answer = data_manager.get_record_by_id('answer', answer_id)[0] question_id = current_answer['question_id'] data_manager.delete_single_answer_by_id(answer_id) data_manager.update_view_counter(question_id, -1) return redirect(url_for('route_show_question', question_id=question_id))
def route_edit_answer(answer_id): current_answer = data_manager.get_record_by_id('answer', answer_id)[0] current_answer['message'] = current_answer['message'].replace('<br/>', "") username = session['username'] if request.method == 'POST': edited_answer = { 'message': request.form['message'].replace('\n', '<br/>'), 'image': current_answer['image'] } question_id = int(request.form['question_id']) if len(request.files) > 0: if request.files['image'].filename != "": current_image_name = str(request.files['image']) normal_image_name = data_manager.get_back_image_name( current_image_name) edited_answer['image'] = normal_image_name file = request.files['image'] filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) data_manager.update_answer(edited_answer, answer_id) data_manager.update_view_counter(question_id, -1) return redirect(url_for('route_show_question', question_id=question_id)) return render_template('edit_answer.html', answer=current_answer, username=username, answer_id=answer_id)
def route_show_question(question_id): data_manager.update_view_counter(question_id, 1) current_question = data_manager.get_record_by_id('question', question_id)[0] current_answers = data_manager.get_answers_by_question_id(question_id) number_of_answers = len(current_answers) current_question_comments = data_manager.get_comments_by_question_id( question_id) current_answer_comments = data_manager.get_answer_comments() if 'username' in session: username = session['username'] return render_template('show_question.html', question_id=question_id, question=current_question, answers=current_answers, question_comments=current_question_comments, answer_comments=current_answer_comments, number_of_answers=number_of_answers, username=username) return render_template('show_question.html', question_id=question_id, question=current_question, answers=current_answers, question_comments=current_question_comments, answer_comments=current_answer_comments, number_of_answers=number_of_answers)
def route_new_answer(question_id): username = session['username'] data_manager.update_view_counter(question_id, -2) if request.method == 'POST': username = session['username'] user_id = data_manager.get_user_id_by_username(username) new_answer = { 'submission_time': "", 'vote_number': 0, 'question_id': question_id, 'message': request.form['message'].replace('\n', '<br/>'), 'image': "", 'user_id': user_id } if len(request.files) > 0: if request.files['image'].filename != "": current_image_name = str(request.files['image']) normal_image_name = data_manager.get_back_image_name( current_image_name) new_answer['image'] = normal_image_name file = request.files['image'] filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) data_manager.insert_new_answer_to_database(new_answer) return redirect(url_for('route_show_question', question_id=question_id)) return render_template('new_answer.html', question_id=question_id, username=username)
def add_new_comment_to_answer(answer_id): if request.method == 'POST': question_id = data_manager.get_question_id_by_answer_id(answer_id) username = session['username'] user_id = data_manager.get_user_id_by_username(username) new_comment = { 'question_id': question_id, 'answer_id': answer_id, 'message': request.form['comment_message'].replace('\n', '<br/>'), 'submission_time': "", 'edited_count': 0, 'user_id': user_id } data_manager.insert_new_answer_comment_to_database(new_comment) data_manager.update_view_counter(question_id, -1) return redirect(url_for('route_show_question', question_id=question_id)) return render_template('new_answer_comment.html', answer_id=answer_id)
def update_comment(comment_id): comment = data_manager.get_comment_by_comment_id('comment', comment_id) comment['message'] = comment['message'].replace("<br/>", "") username = session['username'] if request.method == 'POST': edited_comment = { 'message': request.form['comment_message'].replace('\n', '<br/>') } data_manager.update_data_by_id('comment', edited_comment, comment_id) current_comment = data_manager.get_comment_by_comment_id( 'comment', comment_id) question_id = current_comment['question_id'] data_manager.update_view_counter(question_id, -1) return redirect(url_for('route_show_question', question_id=question_id)) return render_template('edit_comment.html', comment_id=comment_id, comment=comment, username=username)
def route_vote_answer_down(answer_id): data_manager.vote_counter('answer', answer_id, 'down') question_id = data_manager.get_question_id_by_answer_id(answer_id) data_manager.update_view_counter(question_id, -1) return redirect(url_for('route_show_question', question_id=question_id))
def route_vote_question_down(question_id): data_manager.vote_counter("question", question_id, 'down') data_manager.update_view_counter(question_id, -1) return redirect(url_for('route_show_question', question_id=question_id))
def route_delete_comment(comment_id): question_id = data_manager.get_question_id_by_comment_id(comment_id) data_manager.delete_single_comment_by_id(comment_id) data_manager.update_view_counter(question_id, -1) return redirect(url_for('route_show_question', question_id=question_id))