def list_question(): # names=data_manager.get_fieldnames_from_file("sample_data/question.csv") dict_from_csv = data_manager.get_list_of_dicts_from_database( question_table) dict_sorted_by_time = logic.sort_by_time(dict_from_csv) current_user = user.current_user return render_template('list_questions.html', dict_sorted_by_time=dict_sorted_by_time, user_in_database=current_user)
def display(question_id): question_id = int(question_id) view_number = logic.count_views(question_id) title = logic.get_data_from_certain_row("title", question_id) message = logic.get_data_from_certain_row("message", question_id) user_id = logic.get_data_from_certain_row("user_id", question_id) current_user = user.current_user row = logic.display(question_id) dict_table = data_manager.get_list_of_dicts_from_database(answer_table) tags = data_manager.get_tags_by_question_id(question_id) dict_with_comments = data_manager.get_list_of_dicts_from_database( comment_table) comment_dict_sorted_by_time = logic.sort_by_time(dict_with_comments) return render_template( 'display_question.html', row=row, question_id=question_id, dict_table=dict_table, message=message, title=title, tags=tags, comment_dict_sorted_by_time=comment_dict_sorted_by_time, user_in_database=current_user, user_id=user_id)
def change_vote_value(file): list_of_dicts = data_manager.get_list_of_dicts_from_database(file) if file == "question": if request.form.get('UP') != None: id_of_item_voted_up = int(request.form.get('UP')) user.change_user_reputation_in_question(id_of_item_voted_up, 5) for row in list_of_dicts: if row['id'] == id_of_item_voted_up: row['vote_number'] = (int(row['vote_number']) + 1) updated_vote_number = row['vote_number'] arg_list = [updated_vote_number, id_of_item_voted_up] data_manager.update_votes_in_database(file, arg_list) if request.form.get('DOWN') != None: id_of_item_voted_down = int(request.form.get('DOWN')) user.change_user_reputation_in_question(id_of_item_voted_down, -2) for row in list_of_dicts: if row['id'] == id_of_item_voted_down: row['vote_number'] = (int(row['vote_number']) - 1) updated_vote_number = row['vote_number'] arg_list = [updated_vote_number, id_of_item_voted_down] data_manager.update_votes_in_database(file, arg_list) elif file == "answer": if request.form.get('UP') != None: id_of_item_voted_up = int(request.form.get('UP')) user.change_user_reputation_in_answer(id_of_item_voted_up, 10) for row in list_of_dicts: if row['id'] == id_of_item_voted_up: row['vote_number'] = (int(row['vote_number']) + 1) updated_vote_number = row['vote_number'] arg_list = [updated_vote_number, id_of_item_voted_up] data_manager.update_votes_in_database(file, arg_list) if request.form.get('DOWN') != None: id_of_item_voted_down = int(request.form.get('DOWN')) user.change_user_reputation_in_answer(id_of_item_voted_down, -2) for row in list_of_dicts: if row['id'] == id_of_item_voted_down: row['vote_number'] = (int(row['vote_number']) - 1) updated_vote_number = row['vote_number'] arg_list = [updated_vote_number, id_of_item_voted_down] data_manager.update_votes_in_database(file, arg_list)
def user_profile(user_id): user_id = int(user_id) question = data_manager.user_questions(user_id) answer = data_manager.user_answers(user_id) comment = data_manager.user_comments(user_id) users_datadict = data_manager.get_list_of_dicts_from_database(user_table) count_question = data_manager.count_user_questions(user_id) count_answer = data_manager.count_user_answers(user_id) count_comment = data_manager.count_user_comments(user_id) return render_template("User_profile.html", users_datadict=users_datadict, count_question=count_question, question=question, count_answer=count_answer, answer=answer, count_comment=count_comment, comment=comment, user_id=user_id)
def display(question_id): question_dict = data_manager.get_list_of_dicts_from_database(server.question_table) for row in question_dict: if row['id'] == question_id: return row
def delete_single_answer(answer_table, answer_id): list_of_answers = data_manager.get_list_of_dicts_from_database(answer_table) for answer in list_of_answers: if answer["id"] == answer_id: data_manager.delete_dict_from_database(server.answer_table, answer["id"]) return answer["question_id"]
def get_data_from_certain_row(field_name, question_id): list_of_dicts = data_manager.get_list_of_dicts_from_database(server.question_table) value = [row[field_name] for row in list_of_dicts if question_id == row['id']] return value[0]
def users_list(): users_datadict = data_manager.get_list_of_dicts_from_database(user_table) return render_template('users_list.html', users_datadict=users_datadict)