예제 #1
0
def vote_answers(vote_method, answer_id):
    answer = data_manager.get_answer_by_answer_id(answer_id)
    question_id = answer["question_id"]

    user_name = session["user"]
    user = data_manager.get_user_id_by_name(user_name)
    user.update({"user_name": user_name, "vote_method": vote_method})

    if data_manager.check_if_user_voted_on_answer(user_name, answer_id):
        result = data_manager.check_if_user_voted_on_answer(
            user_name, answer_id)
        voted = data_manager.delete_vote_on_answer_from_votes_db(
            result, vote_method)
        if voted:
            data_manager.vote_answer(vote_method, answer_id)

            author = data_manager.get_author_by_answer_id(
                answer_id)["user_name"]
            author_repu = data_manager.get_reputation(author)
            new_repu = data_manager.annul_calc_reputation(
                "answer", vote_method, author_repu)
            data_manager.update_user_reputation(author, new_repu)
        return redirect(f'/questions/{question_id}')
    else:
        author = data_manager.get_author_by_answer_id(answer_id)["user_name"]
        author_repu = data_manager.get_reputation(author)
        new_repu = data_manager.calculate_reputation("answer", vote_method,
                                                     author_repu)
        data_manager.update_user_reputation(author, new_repu)

        data_manager.create_vote_on_answer_in_votes_db(answer_id, user)
        data_manager.vote_answer(vote_method, answer_id)
        return redirect(url_for("manage_questions", question_id=question_id))
예제 #2
0
def manage_questions(question_id):
    if request.args.getlist('addinganswer'):
        addinganswer = True
    else:
        addinganswer = False

    current_question = data_manager.get_question_by_id(question_id)
    answers_to_question = data_manager.get_answers_by_question_id(question_id)
    reputation = data_manager.get_reputation(current_question['user_name'])
    current_question['reputation'] = reputation['reputation']
    comments = data_manager.find_comments(question_id)

    if 'user' in session:
        question_vote = data_manager.check_if_user_voted_on_question(
            session['user'], question_id)
    else:
        question_vote = []

    return render_template("question-child.html",
                           question_id=int(question_id),
                           comments=comments,
                           question=current_question,
                           answers=answers_to_question,
                           addinganswer=addinganswer,
                           question_headers=QUESTION_HEADERS,
                           answer_headers=ANSWER_HEADERS,
                           question_vote=question_vote)
예제 #3
0
def vote_down_answer(answer_id):
    data_manager.vote_down_answer(answer_id)
    question_id = data_manager.get_question_id_by_answer_id(
        answer_id)['question_id']
    user_id = data_manager.get_display_question(question_id)['user_id']
    reputation = data_manager.get_reputation(user_id=user_id)
    data_manager.update_reputation(user_id, (reputation - 2))
    return redirect('/question/' + str(question_id))
예제 #4
0
def user_page(user_id):
    if request.method == 'GET':
        user = data_manager.get_user_by_id(user_id)
        count_questions = data_manager.count_questions(user_id)
        count_answer = data_manager.count_answers(user_id)
        user_question = data_manager.user_page_questions(user_id)
        user_answer = data_manager.user_page_answer(user_id)
        user_comment = data_manager.user_page_comment(user_id)
        count_comment = data_manager.count_comments(user_id)
        reputation = data_manager.get_reputation(user_id)
        return render_template('user_page.html', user=user, count_questions=count_questions,
                                count_answer=count_answer, user_question=user_question,
                                user_answer=user_answer, user_comment=user_comment, count_comment=count_comment,
                                reputation=reputation)
예제 #5
0
def vote_down_question(question_id):
    data_manager.vote_down_question(question_id)
    user_id = data_manager.get_display_question(question_id)['user_id']
    reputation = data_manager.get_reputation(user_id=user_id)
    data_manager.update_reputation(user_id, (reputation - 2))
    return redirect('/list')