Exemplo n.º 1
0
def accept_answer(answer_id):
    answer = data_manager.get_line_data_by_id(data_manager.answer_db,
                                              answer_id)
    question_users_id = data_manager.get_foreign_key_by_id(
        data_manager.question_db, 'users_id',
        answer[0]['question_id'])[0]['users_id']
    try:
        user_id = data_manager.get_userid_by_username(session['username'])
    except KeyError:
        return redirect('/')
    if answer[0]['accepted_status'] is False and user_id == question_users_id:
        answer_statuses = list(
            map(
                lambda x: x['accepted_status'],
                data_manager.get_lines_data_by_foreign_id(
                    data_manager.answer_db, 'question_id',
                    answer[0]['question_id'])))
        if True not in answer_statuses:
            data_manager.accept_answer(answer_id)
        else:
            flash('You can only accept one answer')
    else:
        flash('Invalid user')
    user_id = data_manager.get_user_id_by_answer_id(answer_id)
    data_manager.increase_reputation('accept', user_id)
    question_id = data_manager.get_foreign_key_by_id(
        data_manager.answer_db, 'question_id', answer_id)[0]['question_id']
    return redirect('/question/{}'.format(question_id))
Exemplo n.º 2
0
def accept_answer(answer_id, question_id):
    if session['id']:
        user_id = session['id']
    else:
        pass
    data_manager.accept_answer(answer_id, user_id)
    return redirect("/list/question/" + question_id)
Exemplo n.º 3
0
def accept_answer(question_id, answer_id):
    if request.method == 'POST':
        data_manager.accept_answer(question_id, answer_id)
        return redirect(url_for('route_question_id', question_id=question_id))
Exemplo n.º 4
0
def accept_answer(answer_id):
    rep_num = 15
    util.update_reputation('answer', answer_id, rep_num)
    data_manager.accept_answer(answer_id)
    question_id = data_manager.get_question_id_by_answer_id(answer_id)
    return redirect(url_for('route_question', question_id=question_id))
Exemplo n.º 5
0
def accept(question_id, answer_id):
    answer_id = int(answer_id)
    data_manager.accept_answer(answer_id)
    return redirect(url_for('route_question', question_id=question_id))