Esempio n. 1
0
def route_edit_comments(comment_id):
    edited_count = data_manager.get_edit_count_comments(comment_id)
    edited_count = edited_count[0]['edited_count']
    comment_message = data_manager.get_comment_message(comment_id)
    answer_id = data_manager.get_answer_by_comment_id(comment_id)
    try:
        question_id = util.read_question_id(answer_id[0]['answer_id'])
    except:
        question_id = data_manager.get_question_id_by_comment_id(comment_id)
    if request.method == 'POST':
        message = request.form['message']
        message = message.replace("'", "''")
        edited_count += 1
        data_manager.edit_comment(message=message,
                                  edited_count=edited_count,
                                  comment_id=comment_id)
        return redirect(
            url_for('route_question',
                    question_id=question_id[0]['question_id']))
    return render_template('edit_comment.html',
                           comment_id=comment_id,
                           comment_message=comment_message,
                           answer_id=answer_id,
                           question_id=question_id,
                           edited_count=edited_count)
Esempio n. 2
0
def edit_comment(question_id, comment_id):
    if request.method == "POST":
        question_id = question_id
        message = request.form["message"]
        data_manager.edit_comment(comment_id, message)
        return redirect("/list/question/" + question_id)
    comment = data_manager.get_unique_comment(comment_id)
    return render_template("edit_comment.html", comment=comment, question_id=question_id, comment_id=comment_id)
Esempio n. 3
0
def edit_comment(comment_id):
    question_id = request.args.get("question_id")
    updated_comment = request.form.get("message")

    data_manager.edit_comment(comment_id, updated_comment)

    return redirect(url_for("display_question",
                            question_id=question_id))
Esempio n. 4
0
def route_edit_comment(comment_id=None):
    comment_datas = data_manager.get_comment_datas(comment_id)
    if request.method == 'POST':
        data_manager.edit_comment(request.form['message'], comment_id)
        question_id = comment_datas[0]['question_id']
        return redirect(
            url_for('get_question_and_answer_and_comments_by_id',
                    question_id=question_id))
    return render_template('/edit_comment.html', datas=comment_datas)
Esempio n. 5
0
def edit_comment(comment_id):
    comment = data_manager.find_comment(comment_id)[0]
    if request.method == 'POST':
        if comment['edited_count'] is not None:
            edit_comm = comment['edited_count'] + 1
        else:
            edit_comm = 1
        message = request.form.get('message')
        data_manager.edit_comment(comment_id, message, edit_comm)
        return redirect('/question/' + str(comment['question_id']))
    return render_template('edit_comment.html', comment=comment)
Esempio n. 6
0
def edit_comment(comment_id):
    comment_list = data_manager.get_comment_by_comment_id(comment_id)
    print(comment_list)
    if request.method == 'POST':
        submission_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        message = request.form['message']
        data_manager.edit_comment(comment_id, submission_time, message)
        answer_id = data_manager.get_answer_id_by_comment(comment_id)
        question_id = data_manager.get_question_by_answer(answer_id)
        return redirect(url_for('route_question', question_id=question_id))
    return render_template('update_comment.html',
                           message=comment_list,
                           comment_id=comment_id)
Esempio n. 7
0
def edit_comment(comment_id):
    comment = data_manager.get_table_by_id(comment_id, "comment")
    question_id = comment['question_id']
    if question_id is None:
        question_id = data_manager.get_answer_by_id(comment['answer_id'])['question_id']

    if request.method == 'POST':
        my_new_data = request.form.to_dict()
        data_manager.edit_comment(my_new_data)

        return redirect('/question/' + str(question_id))

    return render_template('edit_comment.html', comment=comment, question_id=str(question_id))
Esempio n. 8
0
def edit_comment(comment_id):
    comment_user_id = data_manager.get_user_id_by_comment_id(comment_id)
    if session.get('user_id') == comment_user_id:
        if request.method == 'POST':
            new_message = request.form['message']
            new_edited_count = int(request.form['edited_count']) + 1
            data_manager.edit_comment(comment_id, new_message,
                                      new_edited_count)
            question_id = data_manager.get_question_id_by_comment_id(
                comment_id)
            return redirect(url_for('route_question', question_id=question_id))
        comment = data_manager.get_comment_by_id(comment_id)
        return render_template('edit-comment.html', comment=comment)
    else:
        return "You don't have permission to edit this comment!"
def update_comment(comment_id):
    site_user_id = data_manager.get_site_user_id_by_comment_id(comment_id)
    if site_user_id['site_user_id'] != session['user_id']:
        return redirect('https://i.imgflip.com/239qx5.jpg')
    if request.method == 'POST':
        comment_to_update = request.form.to_dict()
        data_manager.edit_comment(comment_to_update)
        question_id = str(
            data_manager.get_question_id_by_comment_id(comment_id)
            ['question_id'])
        return redirect('/question/' + question_id)

    comment = data_manager.get_comment_by_id(comment_id)
    return render_template('edit_comment.html',
                           comment_id=comment_id,
                           comment=comment)
Esempio n. 10
0
def edit_comment(question_id=None, comment_id=None):
    if request.method == 'POST':
        comment = data_manager.get_comment(comment_id)[0]
        comment['message'] = request.form.get('message')
        comment['edited_count'] += 1
        data_manager.edit_comment(comment)
        return redirect(
            url_for('display_one_question', question_id=question_id))

    comment = data_manager.get_comment(comment_id)[0]

    return render_template('all_comment_functions.html',
                           page_title='Edit comment',
                           button_title='Edit comment',
                           comment=comment,
                           question_id=question_id)
Esempio n. 11
0
def route_edit_comment(comment_id):
    user_id = session['user_id']['id']
    redirect_question_id = request.args['redirect_question_id']
    comment_message = data_manager.get_comment_message(comment_id)
    if request.method == 'POST':
        if user_id != comment_message['user_id']:
            return render_template('error.html', error_message='Stop hacking!!!')
        else:
            modified_comment_message = request.form['comment']
            data_manager.edit_comment(comment_id, modified_comment_message)
            return redirect(url_for('route_show_details', question_id=redirect_question_id))

    return render_template('comment.html',
                           comment_id=comment_id,
                           comment_message=comment_message,
                           redirect_question_id=redirect_question_id)
Esempio n. 12
0
def route_edit_comment(comment_id):
    if 'id' not in session:
        return redirect(url_for('route_main'))
    if request.method == 'GET':
        comment = data_manager.get_comment('id', int(comment_id))
        if comment[0]['question_id'] is None:
            answer = data_manager.get_row_from_table('answer', int(comment[0]['answer_id']))
            return render_template("edit_comment.html", comment=comment, answer=answer, comment_id=comment_id)
        else:
            return render_template("edit_comment.html", comment=comment, comment_id=comment_id, answer='')
    else:
        comment = data_manager.get_comment('id', int(comment_id))
        message = request.form['message']
        data_manager.edit_comment(int(comment_id), message)
        if comment[0]['question_id'] is None:
            answer = data_manager.get_row_from_table('answer', int(comment[0]['answer_id']))
            comment = answer
        return redirect(f'/question/{comment[0]["question_id"]}/question')
Esempio n. 13
0
def edit_comment(comment_id):
    if request.method == "POST":
        message = request.form.get("message")
        question_id = request.form.get("question_id")
        data_manager.edit_comment(comment_id, message)

        return redirect(url_for('manage_questions', question_id=question_id))

    commentdata = data_manager.get_comment_by_comment_id(comment_id)

    return render_template(
        "comment.html",
        id_type="question_id",
        id=commentdata[
            "question_id"],  # need this for the post request redirection
        sending_route=f'/comment/{comment_id}/edit',
        labelaction='Edit comment',
        method="POST",
        message=commentdata["message"],
    )
Esempio n. 14
0
def edit_comment(comment_id):
    if request.method == "GET":
        comment = data_manager.get_comment_by_id(comment_id)
        return render_template('edit_comment.html', comment=comment)

    comment = data_manager.get_comment_by_id(comment_id)
    if comment['question_id']:
        question_id = comment['question_id']
    else:
        question_id = data_manager.get_answer_by_id(
            comment['answer_id'])['question_id']
    edited_comment_data = {
        'message':
        request.form.get('message'),
        'edited_count':
        comment['edited_count'] +
        1 if type(comment['edited_count']) is int else 1
    }
    data_manager.edit_comment(comment_id, edited_comment_data)
    return redirect(url_for('display_question', question_id=question_id))