def answers(question_id): temp_lst = [] questions = data_handler.read_elements_csv(QUESTION_DATA_FILE_PATH, question_header) question_dict = data_handler.find_ids(questions, question_id) answers = data_handler.read_elements_csv(ANSWER_DATA_FILE_PATH, answers_header) if request.method == 'POST': message = request.form['answer_message'] image = request.form['img'] answer_container = [ data_handler.get_id(ANSWER_DATA_FILE_PATH), util.get_unix_time(), '0', question_id, message, ] for item in answer_container: temp_lst.append(item) if image: temp_lst.append(image) return redirect('/') return render_template( 'answers.html', question=question_dict, answers=answers, )
def answers(question_id): list_to_csv = [] temp_lst = [] question_dict = data_handler.get_element_by_id(QUESTION_DATA_FILE_PATH, question_id) question_dict['submission_time'] = util.convert_timestamp_to_date_string( question_dict['submission_time']) answers = util.convert_timestamp_to_date_dict( data_handler.read_elements_csv(ANSWER_DATA_FILE_PATH)) if request.method == 'POST': message = request.form['answer_message'] image = request.files['image'] answer_container = [ str(data_handler.get_id(ANSWER_DATA_FILE_PATH)), str(util.get_unix_time()), '0', question_id, message, image.filename ] for item in answer_container: temp_lst.append(item) if image.filename != '': image.save( os.path.join(UPLOAD_FOLDER, secure_filename(image.filename))) list_to_csv.append(temp_lst) data_handler.append_csv_by_row(ANSWER_DATA_FILE_PATH, temp_lst) return redirect(f'/answers/{question_id}') return render_template('answers.html', question=question_dict, answers=answers)
def home(): questions = util.convert_timestamp( data_handler.read_elements_csv(QUESTION_DATA_FILE_PATH, question_header)) return render_template('home.html', questions=questions, headers=TEMPLATE_HEADER)
def remove_answers(question_id): answers = data_handler.read_elements_csv( data_handler.ANSWER_DATA_FILE_PATH) for i, answer in enumerate(answers): if answer['id'] == question_id: del answers[i] return answers
def remove_question(question_id): questions = data_handler.read_elements_csv( data_handler.QUESTION_DATA_FILE_PATH) for i, question in enumerate(questions): if question['id'] == question_id: del questions[i] return questions
def question_downvote(question_id): if request.method == 'POST': questions = data_handler.read_elements_csv(QUESTION_DATA_FILE_PATH) data_handler.change_vote(questions, question_id, 'decrease') data_handler.update_csv( 'question.csv', [list(question.values()) for question in questions], question_header) return redirect(f'/answers/{question_id}')
def down_vote_answers(answer_id): if request.method == 'POST': answers = data_handler.read_elements_csv(ANSWER_DATA_FILE_PATH) data_handler.change_vote(answers, answer_id, 'decrement') data_handler.update_csv('answer.csv', [list(answer.values()) for answer in answers], answers_header) question_id = data_handler.get_question_id(answer_id, answers) return redirect(f'/answers/{question_id}')
def home(): data = data_handler.read_elements_csv() return render_template('home.html', headers=headers, data=data[1:])
def sort(path, order): data = data_handler.read_elements_csv(path) return sorted(data, key=lambda item: item[order])