Ejemplo n.º 1
0
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}')
Ejemplo n.º 2
0
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}')
Ejemplo n.º 3
0
def delete_question(question_id):
    if request.method == 'POST':
        remove_from_qs = util.remove_question(question_id)
        remove_answers = util.remove_answers(question_id)
        data_handler.update_csv(
            'question.csv',
            [list(dictionary.values())
             for dictionary in remove_from_qs], question_header)
        data_handler.update_csv(
            'answer.csv',
            [list(dictionary.values())
             for dictionary in remove_answers], answers_header)

    return redirect('/')