def index(sorting_col=1, way="desc"): answers = common.get_table_from_file("data/answer.csv") table = common.get_table_from_file("data/question.csv") answer_counter = {} for element in table: table[table.index(element)].append(0) for value in answers: if element[0] == value[3]: table[table.index(element)][7] += 1 if sorting_col is not None: table = common.sort_table(table, sorting_col, way) return render_template("index.html", question_list=table)
def delete_question(question_id): question_table = common.get_table_from_file("data/question.csv") answer_table = common.get_table_from_file("data/answer.csv") ID_INDEX = 0 for element in question_table: if element[ID_INDEX] == question_id: question_table.remove(element) temp_table = [] for question_id_old in answer_table: if question_id_old[3] != question_id: temp_table.append(question_id_old) common.write_table_to_file(question_table, "data/question.csv") common.write_table_to_file(temp_table, "data/answer.csv") return redirect(url_for("index"))
def update_data(question_id): question_table = common.get_table_from_file("data/question.csv") updated_question = [] filename = None if 'file' in request.files: file = request.files['file'] if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) for element in question_table: if element[0] == question_id: updated_question.append(element) question_table.remove(element) flatten_updated_question = [] for element in updated_question: for item in element: flatten_updated_question.append(item) flatten_updated_question.pop(4) flatten_updated_question.pop(4) flatten_updated_question.insert(4, request.form['updated-question_title']) flatten_updated_question.insert(5, request.form['updated-message']) if filename is not None: flatten_updated_question.insert(6, filename) question_table.append(flatten_updated_question) common.write_table_to_file(question_table, "data/question.csv") return redirect(url_for('answer', question_id=question_id))
def delete_answer(answer_id, question_id): answer_table = common.get_table_from_file("data/answer.csv") for element in answer_table: if element[0] == answer_id: answer_table.remove(element) common.write_table_to_file(answer_table, "data/answer.csv") return redirect(url_for('answer', question_id=question_id))
def submit_question(): if "SLY" in request.form["question_title"]: return render_template("sly.html") table = common.get_table_from_file("data/question.csv") submit_data_list = [] VIEW_NUMBER = "0" VOTE_NUMBER = "0" filename = "" file = request.files['file'] if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) ID = common.ID_generator(table) submit_data_list.append(ID) timestamp = datetime.datetime.fromtimestamp( time()).strftime('%Y-%m-%d %H:%M:%S') submit_data_list.append(timestamp) submit_data_list.append(VIEW_NUMBER) submit_data_list.append(VOTE_NUMBER) submit_data_list.append(request.form["question_title"]) submit_data_list.append(request.form["message"]) submit_data_list.append(filename) table.append(submit_data_list) common.write_table_to_file(table, "data/question.csv") return redirect(url_for("index"))
def answer(question_id, sorting_col=2, way="desc"): QUESTION_ID = 3 question_table = common.get_table_from_file("data/question.csv") actual_question = "" for element in question_table: if element[0] == question_id: actual_question = element table = common.get_table_from_file("data/answer.csv") answers_table = [] for element in table: if element[QUESTION_ID] == question_id: answers_table.append(element) answers_table = common.sort_table_answer(answers_table, sorting_col, way) return render_template("answer.html", answers=answers_table, question=actual_question, question_id=question_id)
def view_func(question_id): question_table = common.get_table_from_file("data/question.csv") for element in question_table: if element[0] == question_id: views = int(element[2]) + 1 question_table[question_table.index(element)][2] = str(views) common.write_table_to_file(question_table, "data/question.csv") return redirect(url_for('answer', question_id=question_id))
def update_page(question_id): ID_INDEX = 0 question_table = common.get_table_from_file("data/question.csv") data_to_fill = [] for element in question_table: if element[ID_INDEX] == question_id: data_to_fill.append(element) return render_template("update.html", datas=data_to_fill)
def delete_data(): table = common.get_table_from_file() ID = request.form['delete'] ID_string = str(ID) for element in table: if element[0] == ID_string: table.remove(element) common.write_table_to_file(table) return redirect(url_for('home_list'))
def story_editor_render(story_id=None, form_data=[]): table = common.get_table_from_file() ID = request.form['edit_option'] ID_string = str(ID) datas_to_fill = [] for element in table: if element[0] == ID_string: datas_to_fill.append(element) return render_template("form.html", story_id=story_id, form_data=datas_to_fill)
def read_and_add_form_data(): table = common.get_table_from_file() data_list = [] data_list.insert(0, common.ID_generator(table)) request_names = [ 'story-title', 'user-story', 'accept-crit', 'bussines-value', 'estimation', 'status' ] for name in request_names: data_list.append(request.form[name]) cleared_data_list = common.clear_input(data_list) table.append(cleared_data_list) common.write_table_to_file(table)
def submit_answer(question_id): answers = common.get_table_from_file("data/answer.csv") new_answer = [] timestamp = datetime.datetime.fromtimestamp( time()).strftime('%Y-%m-%d %H:%M:%S') new_answer.append(common.ID_generator(answers)) new_answer.append(timestamp) new_answer.append("0") new_answer.append(question_id) new_answer.append(request.form["answer"]) new_answer.append("IMAGE") answers.append(new_answer) common.write_table_to_file(answers, "data/answer.csv") return redirect(url_for('answer', question_id=question_id))
def route_save_story(): table = common.get_table_from_file('data.csv') if request.method == 'POST': story_title = request.form['story_title'] user_story = request.form['user_story'] acceptance_criteria = request.form['acceptance_criteria'] business_value = str(request.form['business_value']) + ' points' estimation = str(request.form['estimation']) + ' h' new_id = str(int(table[-1][0]) + 1) new_story_list = [ new_id, story_title, user_story, acceptance_criteria, business_value, estimation, 'planning' ] table.append(new_story_list) common.write_table_to_file('data.csv', table) return redirect('/')
def edit_story(): table = common.get_table_from_file() ID = request.form["edit"] ID_string = str(ID) changed_story = [] changed_story.append(ID_string) request_names = [ 'changed-story-title', 'changed-user-story', 'changed-accept-crit', 'changed-bussines-value', 'changed-estimation', 'changed-status' ] for names in request_names: changed_story.append(request.form[names]) cleared_data_list = common.clear_input(changed_story) for element in table: if element[0] == ID_string: table.remove(element) table.insert(0, cleared_data_list) common.write_table_to_file(table) return redirect(url_for('home_list'))
def route_save_updated_story(story_id): table = common.get_table_from_file('data.csv') if request.method == 'POST': story_title = request.form['story_title'] user_story = request.form['user_story'] acceptance_criteria = request.form['acceptance_criteria'] business_value = str(request.form['business_value']) + ' points' estimation = str(request.form['estimation']) + ' h' status = request.form['status'] for line in table: if line[0] == str(story_id): line.clear() updated_story_list = [ story_id, story_title, user_story, acceptance_criteria, business_value, estimation, status ] for i in updated_story_list: line.append(i) common.write_table_to_file('data.csv', table) return redirect('/')
def route_update_story(story_id): table = common.get_table_from_file('data.csv') for line in table: if line[0] == str(story_id): story_title = line[1] user_story = line[2] acceptance_criteria = line[3] business_value = line[4].split() business_value = int(business_value[0]) estimation = line[5].split() estimation = float(estimation[0]) status = line[6] return render_template('update.html', story_id=story_id, story_title=story_title, user_story=user_story, acceptance_criteria=acceptance_criteria, business_value=business_value, estimation=estimation, status=status)
def route_index(): datatable = common.get_table_from_file('data.csv') return render_template('list.html', datatable=datatable)
def home_list(data_list=[]): data_table = common.get_table_from_file() return render_template("list.html", data_list=data_table)