def question_details(id): lines = data_manager.read_file('question.csv') data = common.details_by_id('question.csv', id) answer = common.answer_by_question_id('answer.csv', id) return render_template("question_details.html", id=id, lines=data, answer=answer)
def id_generator(filename): lines = data_manager.read_file(filename) for search in lines: new_id = search[0] new_id = int(new_id) new_id += 1 return new_id
def request_counter(): count = data_manager.read_file() if request.method == 'GET': count['GET'] += 1 elif request.method == 'POST': count['POST'] += 1 elif request.method == 'PUT': count['PUT'] += 1 else: count['DELETE'] += 1 data_manager.write_file(count) return redirect('/')
def delete_question(filename_question, filename_answer, id): lines_question = data_manager.read_file(filename_question) lines_answer = data_manager.read_file_latin(filename_answer) edited_answers =[] for data in lines_answer: if id != data[0]: edited_answers.append(data) data_manager.write_in_file_latin('answer.csv', edited_answers) searched_id = int(id) lines_question.pop(searched_id) data_manager.write_in_file('question.csv', lines_question)
def asking_question(): if request.method == 'GET': return render_template('ask_a_question_form.html') elif request.method == 'POST': lines = data_manager.read_file('question.csv') data_dict = request.form.to_dict() data_list = [ common.id_generator('question.csv'), data_dict['question_title'], data_dict['question_detail'], data_dict['category'], time.asctime(time.localtime(time.time())) ] lines.append(data_list) data_manager.write_in_file('question.csv', lines) return redirect('/')
def route_id_story(id_story): title = "Super Sprinter 3000 - Edit Story" headline = "User Story manager - Edit Story" button = "Update" mode = "edit" data_list = data_manager.read_file() for item in data_list: if item[0] == str(id_story): selected_story_dict = { label: item for label, item in zip(DATA_LABELS, item[1:]) } return render_template('form.html', options=OPTIONS, title=title, headline=headline, button=button, mode=mode, id_story=id_story, selected_story_dict=selected_story_dict) return "This ID has no story attached to it."
def edit_question(id): lines = data_manager.read_file('question.csv') found_lines = common.find_question_line('question.csv', id) if request.method == 'GET': return render_template('ask_a_question_form.html') elif request.method == 'POST': data_dict = request.form.to_dict() for data in lines: question_id = data[0] question_time = data[4] data_list = [ question_id, data_dict['question_title'], data_dict['question_detail'], data_dict['category'], question_time ] searched_id = int(id) lines[searched_id] = data_list data_manager.write_in_file('question.csv', lines) return redirect('/')
def route_index(): data_list = data_manager.read_file() return render_template('list.html', table_header=TABLE_HEADER, data_list=data_list)
def homepage(): data = common.details_by_id('question.csv', id) lines = data_manager.read_file('question.csv') return render_template("homepage.html", lines=lines, data=data)
def delete_question_with_answer(id): lines_question = data_manager.read_file('question.csv') lines_answer = data_manager.read_file_latin('answer.csv') common.delete_question('question.csv', 'answer.csv', id) return redirect('/')
def find_question_line(filename, id): lines = data_manager.read_file('question.csv') for data in lines: if id == data[0]: return data
def details_by_id(filename, id): lines = data_manager.read_file(filename) for data in lines: if data[0] == id: return data
def present_statistics(): count = data_manager.read_file() return render_template('statistics.html', count=count)