コード例 #1
0
ファイル: server.py プロジェクト: Gnorbi951/ask-mate-python
def add_new_comment_to_answer(answer_id: int):
    question_id = data_manager.get_question_id_by_answer_id(answer_id)
    question_id = question_id[0].get('id')
    user_name = data_manager.get_answers_for_questions(question_id)
    answer_data = data_manager.get_answer_by_id(answer_id)
    question_data = data_manager.get_question_by_id(question_id)
    answer_comment = data_manager.get_comments_for_answer(answer_id)
    if request.method == 'POST':
        if 'username' in session:
            username = session['username']
            user_id = data_manager.get_user_id_by_name(username)
            site_input = [
                answer_id, request.form['comment'], 'answer',
                user_id[0].get('id')
            ]
            data_manager.add_comment(site_input)
        else:
            site_input = [answer_id, request.form['comment'], 'answer', None]
            data_manager.add_comment(site_input)
        return redirect(
            url_for('add_new_comment_to_answer', answer_id=answer_id))

    return render_template('add_answer_comment.html',
                           answer_data=answer_data,
                           answer_comment=answer_comment,
                           question_id=question_id,
                           question_data=question_data,
                           user_name=user_name)
コード例 #2
0
ファイル: server.py プロジェクト: AdinaDida/Ask-Mate-SQL
def route_add_comment(question_id):
    if request.method == 'POST':
        submission_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        message = request.form['message']
        data_manager.add_comment(submission_time, question_id, message)
        return redirect(url_for('route_question', question_id=question_id))
    return render_template('comment_question.html', question_id=question_id)
コード例 #3
0
def route_add_comment(what, id_):
    if request.method == 'GET':
        question = None
        answer = None
        if what == 'question':
            question = data_manager.get_question_by_id(id_)
        elif what == 'answer':
            answer = data_manager.get_answer_by_id(id_)
        return render_template('comment.html',
                               question=question,
                               answer=answer,
                               comment=None)
    elif request.method == 'POST':
        answer_id = None
        question_id = None
        if what == 'question':
            question_id = id_
        elif what == 'answer':
            answer_id = id_

        values = [
            question_id, answer_id, request.form['message'],
            util.get_timestamp(), '0'
        ]

        data_manager.add_comment(values)

        if answer_id:
            question_id = data_manager.get_question_id_by_answer_id(answer_id)

        return redirect(f'/question/{question_id}')
コード例 #4
0
ファイル: server.py プロジェクト: pakayb/ask-mate-python
def add_comment_to_question(answer_id=None, question_id=None):
    if request.method == 'POST':
        data_manager.add_comment(
            create_new_comment_data(answer_id, question_id))
        return redirect(url_for('question_details', question_id=question_id))
    elif request.method == 'GET':
        return render_template('add_comment.html', question_id=question_id)
コード例 #5
0
def add_comment(id):
    usr_input = request.form.to_dict()
    usr_input['question_id'] = id
    usr_input['submission_time'] = datetime.now()
    usr_input['user_id'] = session['user_id']
    usr_input['edited_count'] = 0
    print(usr_input)
    data_manager.add_comment(usr_input)
    return redirect("/question/" + str(id))
コード例 #6
0
def add_new_comment_to_question(question_id):
    if authenticate_user():
        if request.method == "GET":
            return show_question(question_id, is_new_comment=True)
        elif request.method == "POST":
            new_comment = request.form.to_dict()
            new_comment["question_id"] = question_id
            new_comment["answer_id"] = None
            new_comment['user_id'] = session['user_id']
            data_manager.add_comment(new_comment)
            return redirect(url_for("show_question", question_id=question_id))
    return redirect(url_for('login'))
コード例 #7
0
def add_comment_to_answer(answer_id):
    if request.method == 'POST':
        comment = {
            'message': request.form['comment'],
            'user_id': session['user_id']
        }
        question_id = data_manager.get_question_id_by_answer_id(answer_id)
        data_manager.add_comment(comment, question_id['id'], answer_id)
        return redirect(f'/question/{question_id["id"]}')

    return render_template('add_and_edit_comment_to_answer.html',
                           answer_id=answer_id)
コード例 #8
0
ファイル: server.py プロジェクト: pakayb/ask-mate-python
def add_comment_to_answer(answer_id=None, question_id=None):
    if request.method == 'POST':
        data_manager.add_comment(
            create_new_comment_data(answer_id, question_id))
        return redirect(
            url_for('question_details',
                    question_id=request.form.get('redirect_id')))
    elif request.method == 'GET':
        answer = data_manager.get_answer_by_id(answer_id)
        return render_template('add_answer_comment.html',
                               answer_id=answer_id,
                               redirect_id=answer.get('question_id'))
コード例 #9
0
def add_new_comment_to_answer(answer_id):
    if authenticate_user():
        question_id = data_manager.get_answer_by_id(answer_id)['question_id']
        comments_for_answers = data_manager.get_comments_for_answers(
            question_id)
        if request.method == "GET":
            return show_question(question_id, answer_to_comment=answer_id)
        elif request.method == "POST":
            new_comment = request.form.to_dict()
            new_comment["question_id"] = question_id
            new_comment["answer_id"] = answer_id
            new_comment['user_id'] = session['user_id']
            data_manager.add_comment(new_comment)
            return redirect(url_for("show_question", question_id=question_id))
    return redirect(url_for('login'))
コード例 #10
0
ファイル: server.py プロジェクト: andris9016/ask-mate-python
def route_new_comment(question_id='', answer_id=''):
    if request.method == "POST":
        if question_id == '':
            data_manager.add_comment(question_id, answer_id,
                                     request.form["comment"])
            return redirect(url_for('route_list'))
        elif answer_id == '':
            data_manager.add_comment(question_id, answer_id,
                                     request.form["comment"])
            return redirect(url_for('route_list'))

    return render_template('newcomment.html',
                           title="Add New Comment!",
                           answer_id=answer_id,
                           question_id=question_id)
コード例 #11
0
ファイル: server.py プロジェクト: jkrisz511/AskMate
def route_new_comment(question_id='', answer_id=''):
    if 'username' in session:
        if request.method == "POST":
            user_id = data_manager.get_user_id_by_username(session['username'])
            if question_id == '':
                data_manager.add_comment(
                    str(data_manager.get_question_id(answer_id)), answer_id,
                    request.form["comment"], user_id)
                return redirect(url_for('route_list'))
            elif answer_id == '':
                data_manager.add_comment(question_id, None,
                                         request.form["comment"], user_id)
                return redirect(url_for('route_list'))
        return render_template('newcomment.html',
                               title="Add New Comment!",
                               answer_id=answer_id,
                               question_id=question_id)
    else:
        return redirect(url_for('route_main'))
コード例 #12
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))
コード例 #13
0
def add_comment(id):
    comment = request.form["comment_text"]
    data_manager.add_comment(id, comment)
    return redirect("/question/" + str(id))