Exemple #1
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())
Exemple #2
0
def display_question(question_id):
    global latest_opened_question_id
    latest_opened_question_id = question_id
    question = data_manager.get_question_by_id(question_id)
    answers = data_manager.get_all_answers_by_id_ordered_by_vote_number(
        question_id)
    comments = data_manager.get_all_comments()
    return render_template('display_question.html',
                           question=question,
                           answers=answers,
                           comments=comments)
Exemple #3
0
def show_question_and_answers(question_id: int):

    single_question = data_manager.get_single_question(question_id)
    answers_list_for_single_question = data_manager.get_all_answers_for_single_question(
        question_id)
    comments_for_single_question = data_manager.get_all_comments_for_single_question(
        question_id)
    all_comments = data_manager.get_all_comments()
    return render_template(
        'question.html',
        question_id=question_id,
        single_question=single_question,
        QUESTION_HEADERS=connection.QUESTION_HEADERS,
        all_answers=answers_list_for_single_question,
        ANSWER_HEADERS=connection.ANSWER_HEADERS,
        comments_for_single_question=comments_for_single_question,
        all_comments=all_comments)
Exemple #4
0
def delete_comment(comment_id):
    question_id = request.args.get("question_id")
    answer_id = request.args.get("answer_id")
    comments = data_manager.get_all_comments()
    data_manager.delete_comment(comment_id)

    if answer_id is None:
        answer_id = 0

    decision = util.deciding_where_to_redirect(comments, comment_id, answer_id, question_id)

    if decision == "question":
        return redirect(url_for("display_question",
                                question_id=question_id))
    elif decision == "answer":
        return redirect(url_for("show_answer_and_comments",
                                answer_id=answer_id,
                                question_id=question_id))
Exemple #5
0
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)
def display_question_and_answers(question_id):
    session['url'] = url_for('display_question_and_answers',
                             question_id=question_id)

    if request.method == 'GET':
        # update view number for question
        data_manager.increment_view_number(question_id)

    question_ids = data_manager.get_question_ids()
    question = data_manager.get_single_question(question_id)
    answers = data_manager.get_answers_for_question(question_id)
    tags = data_manager.get_tags_for_question(question_id)
    comments = data_manager.get_all_comments(question_id)
    user_id = session.get('user_id', False)

    return render_template('display_question/question_display.html',
                           question=question,
                           tags=tags,
                           answers=answers,
                           question_ids=question_ids,
                           comments=comments,
                           user_id=user_id)