def wrapper(*args, **kwargs): if 'question_id' not in kwargs: try: question_id = (data_manager.get_question_id( kwargs['answer_id']))['question_id'] except: question_id = None else: question_id = kwargs['question_id'] if 'username' not in session: window = Tk() window.eval('tk::PlaceWindow %s center' % window.winfo_toplevel()) window.withdraw() if messagebox.askokcancel("Warning", "You need to login first", icon="error") == True: page = 'login' else: page = page_if_messagebox_cancel window.deiconify() window.destroy() window.quit() return redirect(url_for(page, question_id=question_id)) return func(*args, **kwargs)
def delete_answer(answer_id): question_id = data_manager.get_question_id(answer_id)['question_id'] image = data_manager.get_display_answers('question_id', question_id)[0]['image'] if os.path.exists(image): os.remove(image) data_manager.delete_answer_by_id(answer_id) return redirect('/question/' + str(question_id))
def get_question_id(comment_id): index = data_manager.question_or_answer(comment_id) if index['question_id'] == None: question_id_list = data_manager.get_question_id(comment_id) question_id = question_id_list['question_id'] else: question_id = index['question_id'] return question_id
def delete_comment(comment_id): answer_id = data_manager.get_id_from_comment( comment_id=comment_id)['answer_id'] try: question_id = (data_manager.get_question_id(answer_id))['question_id'] except: question_id = (data_manager.get_id_from_comment( comment_id=comment_id))['question_id'] data_manager.delete_comment(comment_id) return redirect('/question/' + str(question_id))
def saving_add_question(): if request.method == 'POST': title = request.form["title"] message = request.form["message"] question = {'title': title, 'message': message, 'image': ''} data_manager.write_question(question) ID = data_manager.get_question_id(title) return redirect('/question/{}'.format(ID[0]['id']))
def edit_answer(answer_id): answers = data_manager.get_answers() question_id = data_manager.get_question_id(answer_id) if request.method == "POST": new_message = request.form['answer'] data_manager.get_update(answer_id, new_message) return redirect(f'/question/{question_id}') return render_template('edit_answer.html', answer_id=answer_id, answers=answers)
def add_comment_to_answer(answer_id): if request.method == 'POST': question_id = (data_manager.get_question_id(answer_id))['question_id'] answer_comment = request.form['answer_comment'] user_id = data_manager.get_user_id_by_username(session['username']) data_manager.create_new_comment(answer_comment, user_id, answer_id=answer_id, question_id=question_id) data_manager.more_user_details(user_id=user_id) return redirect('/question/' + str(question_id)) return render_template('add_cooment_to_answer.html', answer_id=answer_id)
def route_answer(answer_id): question_id = data_manager.get_question_id(answer_id) question = data_manager.read_data(file=data_manager.question, id=question_id) answer = data_manager.read_data(file=data_manager.answer, id=answer_id) url_delete = url_for('route_delete_answer', answer_id=answer_id) return render_template('answer.html', answer_id=answer_id, answer_header=data_manager.answer_header, answer=answer, question_header=data_manager.question_header, question=question, url_delete=url_delete)
def edit_comment(comment_id): comment_details = data_manager.get_display_comment(comment_id) answer_id = data_manager.get_id_from_comment( comment_id=comment_id)['answer_id'] question_id = comment_details['question_id'] if comment_details[ 'question_id'] is not None else ( data_manager.get_question_id(answer_id))['question_id'] comment_details['question_id'] = question_id if request.method == 'GET': return render_template("edit_comment.html", comment=comment_details) else: new_message = request.form['editbody'] data_manager.update_comment(comment_id, new_message) return redirect('/question/' + str(question_id))
def edit_answer(answer_id): if request.method == "GET": full_answer = data_manager.get_answer_by_id(answer_id) message = full_answer[0]['message'] time = datetime.now() return render_template('edit_answer.html', message=message, answer_id=answer_id) if request.method == "POST": answer_data = request.form.to_dict() message = answer_data['message'] question_id_in_list = data_manager.get_question_id(answer_id) question_id = question_id_in_list[0]['question_id'] data_manager.update_answer_by_id(answer_id, message, datetime.now()) return redirect(url_for('display_question', question_id=question_id))
def route_new_comment(question_id='', answer_id=''): if 'username' in session: if request.method == "POST": user_id = data_manager.get_user_id_by_username(session['username']) if question_id == '': data_manager.add_comment( str(data_manager.get_question_id(answer_id)), answer_id, request.form["comment"], user_id) return redirect(url_for('route_list')) elif answer_id == '': data_manager.add_comment(question_id, None, request.form["comment"], user_id) return redirect(url_for('route_list')) return render_template('newcomment.html', title="Add New Comment!", answer_id=answer_id, question_id=question_id) else: return redirect(url_for('route_main'))
def delete_answer_from_db(answer_id): question_id = data_manager.get_question_id(answer_id) data_manager.delete_answer(answer_id) return redirect(url_for('display_one_question', question_id=question_id))
def route_delete_answer(answer_id): question_id = data_manager.get_question_id(answer_id) data_manager.delete_message(id=answer_id, file=data_manager.answer) return redirect(url_for('route_question', question_id=question_id))
def test_get_question_id(self): data = data_manager.get_question_id(2) result = data['question_id'] self.assertEqual(result, 1)