def list_answers(id=None): if 'username' in session: username = session['username'] user = data_handler.get_user_id_by_username(username) time = request.args.get('time') # answer comment edit time stamp q_c_time = request.args.get('q_c_time') question_row = data_handler.get_question_for_id(id) answer_row = data_handler.get_answers_for_id(id) question_comments = data_handler.get_question_comments(id) answer_comments = data_handler.get_answer_comments() tags = data_handler.get_all_tag_name_for_question(id) q_author = data_handler.get_username_by_question_id(id) check_for_valid_question = data_handler.check_user_id_authentication_for_question(username, id) if request.method == 'POST': answers = {'submission_time': data_handler.date_time(), 'vote_number': 0, 'question_id': id, 'message': request.form.get('answer_message'), 'image': request.form.get('image'), 'userid': data_handler.get_user_id_by_username(username), } data_handler.add_new_answer(answers) return redirect(url_for('list_answers', id=id, username=username)) data_handler.question_view_number_counter(id) return render_template('question.html', id=id, question_row=question_row, answer_row=answer_row, question_comments=question_comments, answer_comments=answer_comments, time=time, q_c_time=q_c_time, tags=tags, username=username, user=user, q_author=q_author, check_edit_question=check_for_valid_question) else: return redirect(url_for('user_login'))
def add_question(): if 'username' in session: username = session['username'] if request.method == 'GET': empty_questions = {} return render_template('add-question.html', question=empty_questions, form_url=url_for('add_question'), page_title='Add New Question', button_title='Submit', button_page='Return', username=username) if request.method == 'POST': question = {'submission_time': data_handler.date_time(), 'view_number': request.form.get('view_number'), 'vote_number': request.form.get('vote_number'), 'title': request.form.get('title'), 'message': request.form.get('message'), 'image': request.form.get('image'), 'userid': data_handler.get_user_id_by_username(username), } data_handler.add_new_question(question) return redirect(url_for('list_of_questions', username=username)) else: return redirect(url_for('user_login'))
def sort_questions(): username = session['username'] if request.method == 'POST': user = data_handler.get_user_id_by_username(username) choices = request.form.get('sort') if 'asc' in choices: sorted_data = data_handler.ascending_order(choices) return render_template('list.html', questions=sorted_data, username=username, user=user) if 'desc' in choices: sorted_data = data_handler.descending_order(choices) return render_template('list.html', questions=sorted_data, username=username, user=user)
def index(): """ This is a one-pager which shows all the boards and cards """ if session.get(SESSION_USERNAME): user_id = data_handler.get_user_id_by_username( session[SESSION_USERNAME]) return render_template('index.html', username=SESSION_USERNAME, user_id=user_id) else: return render_template('index.html')
def list_of_questions(): questions = data_handler.get_all_details() last_questions = data_handler.get_latest_five_questions() if 'username' in session: username = session['username'] user = data_handler.get_user_id_by_username(username) if request.method == 'POST': if 'show_all' == request.form.get('show'): return render_template('list.html', questions=questions, username=username, user=user) elif 'show_latest' == request.form.get('show'): return render_template('list.html', questions=last_questions, username=username, user=user) return render_template("list.html", questions=last_questions, username=username, user=user) else: return render_template("list.html", questions=last_questions, username="")
def user_page(user_id=None): username = session['username'] user = data_handler.get_user_id_by_username(username) user_page_name = data_handler.get_username_by_user_id(user_id) questions = data_handler.user_questions(user_id) answers = data_handler.user_answers(user_id) comments = data_handler.user_comments(user_id) unaccepted_answers = data_handler.unaccepted_answers(user_id) print(unaccepted_answers) question_ids = data_handler.question_id_by_comment_ids_for_user_page(user_id) print(question_ids) return render_template('user-page.html', questions=questions, answers=answers, comments=comments, username=username, user=user, title=user_page_name, unaccepted=unaccepted_answers, question_ids_to_comments=question_ids)
def add_question_comment(question_id=None): username = session['username'] comment = data_handler.get_question_for_id(question_id) if request.method == 'POST': comment = {'submission_time': data_handler.date_time(), 'question_id': request.form.get('question_id'), 'answer_id': request.form.get('answer_id'), 'message': request.form.get('message'), 'edited_count': request.form.get('edited_count'), 'userid': data_handler.get_user_id_by_username(username), } data_handler.add_new_comment(comment) return redirect(url_for('list_answers', id=question_id, username=username)) return render_template('add-question-comment.html', comment=comment, edit_comment=None, button_title="Post New Comment", username=username)
def list_of_users(): username = session['username'] user = data_handler.get_user_id_by_username(username) users_list = data_handler.list_of_users() return render_template('users-list.html', username=username, list_of_users=users_list, user=user)
def deny_answer(answer_id): username = session['username'] question_id = data_handler.get_question_id_by_answer_id(answer_id) user = data_handler.get_user_id_by_username(username) data_handler.deny_answer(answer_id) return redirect(url_for('list_answers', id=question_id, user=user, username=username))