Exemplo n.º 1
0
def route_edit_comment(comment_id):
    comment = data_manager.get_comment_by_id(comment_id)
    if request.method == 'GET':
        question = None
        answer = None
        if comment['question_id']:
            question = data_manager.get_question_by_id(comment['question_id'])
        else:
            answer = data_manager.get_answer_by_id(comment['answer_id'])
        return render_template('comment.html',
                               question=question,
                               answer=answer,
                               comment=comment)
    elif request.method == 'POST':

        values = [
            comment_id, request.form['message'], comment['edited_count'] + 1
        ]
        data_manager.update_comment(values)

        if comment['question_id']:
            question_id = comment['question_id']
        else:
            answer = data_manager.get_answer_by_id(comment['answer_id'])
            question_id = answer['question_id']

        return redirect(f'/question/{question_id}')
def save_edited_comment():
    edited_message = request.form.to_dict()
    data_manager.update_comment(edited_message)
    edited_comment = data_manager.get_comment_by_id(edited_message["id"])
    if edited_comment["question_id"] == None:
        question_id = data_manager.get_question_id_by_answer_id(edited_comment["answer_id"])
    else:
        question_id = edited_comment["question_id"]
    url_to_question = url_for("get_question_details", question_id=question_id)
    return redirect(url_to_question)
Exemplo n.º 3
0
def edit_comment(num, comment_id):
    if request.method == 'POST':
        update = request.form['message']
        data_manager.update_comment(update, num, comment_id)
        return redirect('/question/' + num + '/q-comment')
    elif request.method == 'GET':
        comment = data_manager.get_this_comment(num, comment_id)
        return render_template("edit-question-comment.html",
                               comment_id=comment_id,
                               comment=comment,
                               num=num)
Exemplo n.º 4
0
def update_comment(comment_id):
    comment = data_manager.fetch_comments_by_id(comment_id)
    if request.method == "POST":
        data_manager.update_comment(comment)
        if comment['question_id']:
            return redirect('/list')
        else:
            answer = data_manager.fetch_answers_by_answer_id(
                comment['answer_id'])
            return redirect('/question/' + str(answer['question_id']))
    return render_template('modify_data_layout/update_comment.html',
                           comment=comment)
Exemplo n.º 5
0
def edit_comment(comment_id):
    if authenticate_user():
        comment = data_manager.get_comment_by_id(comment_id)
        question_id = comment["question_id"]
        if request.method == "GET":
            return show_question(question_id, comment_to_edit=comment_id)
        elif request.method == "POST":
            data = request.form.to_dict()
            data['id'] = comment_id
            data_manager.update_comment(data)
            return redirect(url_for("show_question", question_id=question_id))
    return redirect(url_for('login'))
Exemplo n.º 6
0
def update_comment(comment):
    message = fv.remove_parentheses(comment['message'])
    message = fv.check_is_not_empty(message)
    if message:
        comment_new = {
            'message': message,
        }
        comment.update(comment_new)
        dm.update_comment(comment)
        return True
    else:
        return False
Exemplo n.º 7
0
def update_comment_post(comment_id):
    user_id = data_manager.get_user_id_by_activity('comment', comment_id)
    question_id = data_manager.get_question_id_by_comment_id(comment_id)
    if session.get(FORM_USERNAME) and session[SESSION_ID] == user_id:
        if request.method == "POST":
            details = dict(request.form)
            details["submission_time"] = util.get_current_date_time()

            data_manager.update_comment(details, comment_id)
            return redirect(
                url_for("display_question", question_id=question_id))
    else:
        flash("Update option is available only for the author!", "warning")
        return redirect(url_for('display_question', question_id=question_id))
Exemplo n.º 8
0
def edit_comment(comment_id):
    comment_details = data_manager.get_display_comment(comment_id)
    answer_id = data_manager.get_id_from_comment(
        comment_id=comment_id)['answer_id']
    question_id = comment_details['question_id'] if comment_details[
        'question_id'] is not None else (
            data_manager.get_question_id(answer_id))['question_id']
    comment_details['question_id'] = question_id
    if request.method == 'GET':
        return render_template("edit_comment.html", comment=comment_details)
    else:
        new_message = request.form['editbody']
        data_manager.update_comment(comment_id, new_message)
        return redirect('/question/' + str(question_id))
Exemplo n.º 9
0
def edit_comment(question_id, comment_id):
    if request.method == 'POST':
        message = request.form['comment']
        data_manager.update_comment(message, comment_id)
        return redirect(url_for('route_question', question_id=question_id))

    question = data_manager.get_question_by_id(question_id)
    comment = data_manager.get_comment_by_id(comment_id)[0]
    edit = True
    return render_template('add_comment.html',
                           question=question,
                           question_id=question_id,
                           comment_id=comment_id,
                           comment=comment,
                           edit=edit)
Exemplo n.º 10
0
def edit_comment(comment_id):
    try:
        comment = data_manager.get_comment_by_comment_id(comment_id)
        if comment['question_id'] is not None:
            question_id = comment['question_id']
        elif comment['question_id'] is None and comment['answer_id'] is not None:
            question_id = data_manager.get_question_id_by_answer_id(comment['answer_id'])
        if request.method == 'GET':
            return render_template('edit-comment.html', comment_id=comment_id, comment=comment, question_id=question_id)
        elif request.method == 'POST':
            submission_time = datetime.now().isoformat(timespec='seconds')
            message = request.form['message']
            edited_count = comment['edited_count']
            if edited_count is None:
                edited_count = 0
            edited_count += 1
            data_manager.update_comment(message, submission_time, edited_count, comment_id)
            return redirect(f'/question/{question_id}')
    except (IndexError, UndefinedError):
        abort(404)
Exemplo n.º 11
0
def edit_answer_comment(comment_id):
    answer_id=data_manager.get_answerId_by_commentId(comment_id)
    if session.get('username') is not None:
        comment_user_id=data_manager.find_userid_by_commentid(comment_id)
        if comment_user_id:
            if session['user_id'] == comment_user_id['user_id'] or session['username'] == 'administrator':
                comment = data_manager.get_answer_comment(comment_id)
                if request.method == "GET":
                    return render_template('edit-answer-comment.html', comment=comment)
                elif request.method == "POST":
                    edited_comment = request.form['comment']
                    data_manager.update_edited_count(comment_id)
                    data_manager.update_comment(edited_comment, comment_id)
                    return redirect(url_for('see_answer_route', answer_id=answer_id))
            else:
                flash("You dont have access", "no_acces")
                return redirect(url_for('see_answer_route', answer_id=answer_id))
    else:
        flash('You must login before using features', 'no_user')
        return redirect(url_for('see_answer_route', answer_id=answer_id))
Exemplo n.º 12
0
def edit_comment(comment_id):
    if request.method == 'GET':
        comment = data_manager.get_comment(comment_id)
        return render_template('edit-comment.html',
                               comment_id=comment_id,
                               comment=comment)
    elif request.method == 'POST':
        comment = data_manager.get_comment(comment_id)
        if comment[0]['question_id']:
            question_id = comment[0]['question_id']
            edited_comment_message = request.form['message'].replace("'", "''")
            data_manager.update_comment(comment_id, edited_comment_message)
            return redirect(
                url_for('display_question', question_id=question_id))
        elif comment[0]['answer_id']:
            answer_id = comment[0]['answer_id']
            edited_comment_message = request.form['message'].replace("'", "''")
            data_manager.update_comment(comment_id, edited_comment_message)
            answer = data_manager.get_answer(answer_id)
            question_id = answer['question_id']
            return redirect(
                url_for('display_question', question_id=question_id))
Exemplo n.º 13
0
def form_comment(comment_id):
    form_dict = dict(request.form)
    form_dict['comment_id'] = comment_id
    comment_det = data_manager.update_comment(form_dict=form_dict)
    if comment_det['question_id'] is not None:
        return redirect(url_for('question_details', question_id=comment_det['question_id']))