예제 #1
0
def answer_next_id():
    answers = data_manager.get_all_answers()
    try:
        next_id = max(int(id) for id in answers.keys())
        return next_id+1
    except ValueError:
        return 1
예제 #2
0
def vote_ask_plus(answer_id, question_id):
    all_answers = data_manager.get_all_answers()
    for answer in all_answers:
        if answer_id == answer['id']:
            answer['vote_number'] = int(answer['vote_number']) + 1
            connection.write_file(all_answers,
                                  'ask-mate-python/sample_data/answer.csv')
    question_id = str(question_id)
    return redirect('/show_question/' + question_id)
예제 #3
0
def question_details(question_id):
    question = data_manager.get_question_by_id(question_id)
    data_manager.update_view_number(question.get('view_number'), question_id)
    return render_template('question-details.html',
                           question=question,
                           question_id=question_id,
                           answers=data_manager.get_all_answers(),
                           comments=data_manager.get_all_comments(),
                           login=get_user_id())
예제 #4
0
def question_route(id):
    if request.method == "GET":
        answer_user_data=data_manager.find_username_for_answer(id)

        question_user_data=data_manager.find_username_by_question_id(id)
        quest_comm_user_data = data_manager.find_userdata_for_questions_comments(id)
        question = data_manager.get_question(id)
        answers = data_manager.get_all_answers(id)
        question_comments = data_manager.get_question_comments(id)
        return render_template("question-page.html", to_display=question,q_user_data=question_user_data,
                               a_user_data=answer_user_data, answers_to_display=answers, question_id=id,
                               comments=question_comments, quest_comm_user_data=quest_comm_user_data)
예제 #5
0
def route_new_answer(id):
    if request.method == 'POST':
        current_file = data_manager.get_all_answers()
        new_answer = {}
        if current_file:
            new_answer['id'] = str(int(current_file[-1]['id']) + 1)
        else:
            new_answer['id'] = '0'
        new_answer['submission_time'] = ''
        new_answer['vote_number'] = '0'
        new_answer['question_id'] = id
        new_answer['message'] = request.form['answer']
        new_answer['image'] = ''
        current_file.append(new_answer)
        data_manager.save_new_answer(current_file)
        return redirect('/question_detail/' + id)
    return render_template('answer.html')
예제 #6
0
파일: app.py 프로젝트: Stachozaur/Ask-Mate
def display_question(id):
    answers = data_manager.get_all_answers()
    questions = data_manager.get_all_questions()
    comments = data_manager.get_all_comments()
    question_votes = data_manager.get_number_of_votes_by_id(id, 'questions')
    answer_votes = data_manager.get_all_votes_from_answers_by_question_id(id)
    id = int(id)
    question_data = data_manager.get_question_by_id(id)
    title = question_data['title']
    message = question_data['message']
    print(question_votes, answer_votes)

    return render_template('display_question.html',
                           questions=questions,
                           title=title,
                           message=message,
                           id=id,
                           answers=answers,
                           comments=comments,
                           question_votes=question_votes,
                           answers_votes=answer_votes)
예제 #7
0
def get_all_answers(): # get list of dictionaries, list of all questions
    try:
        return data_manager.get_all_answers()
    except FileNotFoundError as e:
        # logging.debug(e)
        return []