예제 #1
0
def question_page(question_id):
    question = data_manager.get_question_details(question_id)
    if 'user_name' in session:
        user_id = data_manager.get_user_id(session['user_name'])[0]['id']
        return render_template("question.html",
                               question=question,
                               email=session['user_name'],
                               user_id=user_id)
    return render_template("question.html", question=question)
예제 #2
0
def edit_question(question_id):
    question = data_manager.get_question_details(question_id)
    if request.method == 'GET':
        return render_template('edit-question.html',
                               question_id=question_id,
                               question=question)

    data_manager.edit_question(request.form, question_id)

    return redirect(f'/question/{question_id}')
예제 #3
0
def show_question_details(question_id):
    question = data_manager.get_question_details(question_id)
    comments = data_manager.get_comments()
    answers = data_manager.get_answers_for_question(question_id)
    data_manager.update_view_number(question_id)

    return render_template('question.html',
                           question=question,
                           comments=comments,
                           answers=answers)
예제 #4
0
def route_question(id):
    if request.method == "GET":
        questions = data_manager.get_question_details(id)
        answers = data_manager.get_answer_details(id)
        comments = data_manager.get_comments(id)
        # tags = data_manager.get_question_tags(id)
        # all_tags = data_manager.get_all_tags()
        return render_template("question.html",
                               question=questions,
                               answers=answers,
                               comments=comments)
예제 #5
0
def edit_question(id):
    if data_manager.get_owner_by("question", "id", id) == session['user_id']:
        if request.method == "POST":
            usr_input = request.form.to_dict()
            usr_input["id"] = id
            data_manager.edit_question(usr_input)
            return redirect("/question/" + str(id))
        question_details = data_manager.get_question_details(id)
        return render_template("ask-question.html",
                               question_details=question_details)
    abort(404)
예제 #6
0
def add_new_comment_to_question(question_id: int):
    if request.method == 'GET':
        question = data_manager.get_question_details(question_id)
        user_name = data_manager.get_answers_for_questions(question_id)
        return render_template('add_question_comment.html',
                               question=question,
                               user_name=user_name)

    if 'username' in session:
        username = session['username']
        user_id = data_manager.get_user_id_by_name(username)
        site_input = [
            question_id, request.form['comment'], 'question',
            user_id[0].get('id')
        ]
        data_manager.add_comment(site_input)
    else:
        site_input = [question_id, request.form['comment'], 'question', None]
        data_manager.add_comment(site_input)

    return redirect(
        url_for('add_new_comment_to_question', question_id=question_id))
예제 #7
0
def show_specific_question(question_id: int):
    question = data_manager.get_question_details(question_id)
    return render_template('question_details.html', question=question)