def edit_question(question_id): question = data_manager.find_question(question_id)[0] if request.method == 'POST': title = request.form.get('title') message = request.form.get("message") image = request.form.get('image') data_manager.edit_question(question_id, title, message, image) return redirect('/') return render_template('edit.html', question=question, id=question_id)
def add_question_comment(question_id): questions = data_manager.find_question(question_id) if request.method == 'POST': submission_time = datetime.now().date() message = request.form.get('message') data_manager.add_comment_for_question(question_id, message, submission_time) return redirect('/question/' + str(question_id)) return render_template('add_comment.html', questions=questions)
def edit_question(question_id): questions = data_manager.find_question(question_id) if request.method == 'POST': title = request.form.get('title') message = request.form.get('message') image = request.form.get('image') data_manager.update_question_on_csv(title, message, image, question_id) return redirect('/question/' + str(question_id)) return render_template('edit.html', questions=questions)
def show_question(id): tags = data_manager.get_all_tags() question_t = data_manager.all_question_tag() answers = data_manager.get_answer() view = data_manager.find_question(id)[0] view_no = view.get('view_number', '') data_manager.view_question(id, view_no) answer_by_question_id = data_manager.find_answer_by_question_id(id) question = data_manager.find_question(id)[0] comment_id_question = data_manager.get_comments_by_question_id(id) tabel_comment = data_manager.get_tabel_comment() return render_template('question.html', question=question, answers=answers, answer_by_question_id=answer_by_question_id, comment_id_question=comment_id_question, tabel_comment=tabel_comment, tags=tags, question_t=question_t)
def add_answer(question_id): questions = data_manager.find_question(question_id) if request.method == 'POST': submission_time = datetime.now().date() vote_number = 0 message = request.form.get('message') question_id = question_id image = request.form.get('image') data_manager.add_answer_in_csv(submission_time, vote_number, message, question_id, image) return redirect('/question/' + str(question_id)) return render_template('add-answer.html', questions=questions)
def add_question_comment(question_id): questions = data_manager.find_question(question_id) if request.method == 'POST': question_id = question_id message = request.form.get('message') submission_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") id_user = session['user_id'] data_manager.add_comment_question(question_id, message, submission_time, id_user) data_manager.update_users_comments(session['user_id']) return redirect('/question/' + str(question_id)) return render_template('add_question_comment.html', questions=questions)
def new_answer(question_id): question = data_manager.find_question(question_id) if request.method == 'POST': submission_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") vote_number = 0 question_id = question_id message = request.form.get("message") image = request.form.get('image') id_user = session['user_id'] data_manager.new_answer(submission_time, vote_number, question_id, message, image, id_user) data_manager.update_users_answers(session['user_id']) return redirect('/question/' + str(question_id)) return render_template('new_answer.html', id=question_id)
def add_tags(question_id): tags = data_manager.get_all_tags() question = data_manager.find_question(question_id)[0] if request.method == 'POST': name = request.form.get('tag') try: data_manager.add_tag(name) tag_id = data_manager.get_tag_id(name) data_manager.add_tag_in_question_tag(question_id, tag_id['id']) return redirect('/question/' + str(question_id)) except: flash("Tag exist") return redirect('/question/' + str(question_id)) return render_template('add_tags.html', question=question, tags=tags)
def display_question(question_id): if request.method == 'GET': data_manager.view_up_answer(question_id) question_comments = data_manager.get_question_comment(question_id) questions = data_manager.find_question(question_id) answers = data_manager.find_question_answer(question_id) comments = data_manager.get_comments() question_tags = data_manager.get_question_tags(question_id) return render_template('question.html', questions=questions, answers=answers, question_comments=question_comments, comments=comments, question_id=question_id, question_tags=question_tags)