Esempio n. 1
0
def delete_only_comment(question_id, comment_id, answer_id):
    if request.path == f'/question/{question_id}/delete_this/{comment_id}/{answer_id}':
        user = session['username']
        data_handler.delete_comment(comment_id, user)
        return redirect(
            url_for('show_answer_comments',
                    question_id=question_id,
                    answer_id=answer_id))
    if request.path == f'/question/{question_id}/edit_this/{comment_id}/{answer_id}':
        if request.method == 'POST':
            user = session['username']
            new_comment = request.form['message']
            new_sub_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            data_handler.update_comment(new_comment, new_sub_time, comment_id,
                                        user)
            return redirect(
                url_for('show_answer_comments',
                        question_id=question_id,
                        answer_id=answer_id))
    question = data_handler.get_question_SQL(question_id)
    answer = data_handler.get_answer_for_question_SQL_with_ans_id(answer_id)
    comment = data_handler.get_comment_for_edit(comment_id)
    return render_template('edit-comment.html',
                           comment=comment,
                           question=question,
                           answer=answer)
Esempio n. 2
0
def route_delete_comment(comment_id):
    question_id = data_handler.get_question_id_from_comment_id(comment_id)
    if question_id is None:
        answer_id = data_handler.get_answer_id_from_comment_id(comment_id)
        question_id = data_handler.get_question_id_from_answer_id(answer_id)
    data_handler.delete_comment(comment_id)
    return redirect(url_for("route_list_answers", question_id=question_id))
Esempio n. 3
0
def del_comment(comment_id):
    q_and_a_id = data_handler.get_q_and_a_id_from_comment(comment_id)
    data_handler.delete_comment(comment_id)
    if q_and_a_id[0]['answer_id']:
        answer_id = q_and_a_id[0]['answer_id']
        question_id = data_handler.get_question_id_from_answer_id(answer_id)
        question_id = question_id[0]['id']
    else:
        question_id = q_and_a_id[0]['question_id']
    return redirect(url_for('view_question', question_id=question_id))
Esempio n. 4
0
def comment(id=None):
    if request.path == f'/comment/{id}/delete-comment':
        user = session['username']
        data_handler.delete_comment(id, user)
        return redirect(url_for('route_list'))
    if request.path == f'/comment/{id}/edit-comment':
        if request.method == 'GET':
            comment = data_handler.get_comment_for_edit(id)
            return render_template('edit-comment.html', comment=comment)
        if request.method == 'POST':
            user = session['username']
            user_row = data_handler.get_owner_by_id(id)
            user_infos = []
            for i in user_row:
                user_infos.append(i)
            if user_infos[0]['owner'] == user:
                new_comment = request.form['message']
                new_sub_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                data_handler.update_comment(new_comment, new_sub_time, id,
                                            user)
                return redirect(url_for('route_list'))
        return render_template('edit-comment.html', comment=comment)
Esempio n. 5
0
def delete_comment(comment_id):
    question_id = data_handler.delete_comment(comment_id)
    return redirect(url_for('show_answers', question_id=question_id))
Esempio n. 6
0
def delete_comment(question_id):
    if request.method == 'POST':
        data_handler.delete_comment(question_id)
        return redirect(url_for("display_question", id=question_id))
Esempio n. 7
0
def delete_comment(comment_id):
    comment = data_handler.get_comment_by_id(comment_id)
    data_handler.delete_comment(comment_id)

    return redirect(url_for('question', question_id=comment['question_id']))