예제 #1
0
def delete_question(question_id):
    user_id = data_manager.get_user_id_by_activity('question', question_id)
    if session.get(FORM_USERNAME) and session[SESSION_ID] == user_id:
        answer_pictures_paths = data_manager.get_answer_pictures_paths(
            question_id)
        for image in answer_pictures_paths:
            data_manager.delete_answer_image(image['answer_id'])
        util.delete_all_images(answer_pictures_paths)

        question_pictures_paths = data_manager.get_question_pictures_paths(
            question_id)
        data_manager.delete_question_image(question_id)
        util.delete_all_images(question_pictures_paths)

        if data_manager.has_question_comment(question_id) is not None:
            data_manager.delete_comment_for_question(question_id)
        data_manager.delete_question_from_question_tag(question_id)

        data_manager.delete_comment_for_answers_for_question(question_id)
        data_manager.delete_answers_for_question(question_id)

        data_manager.delete_question(question_id)

        return redirect(url_for("question_page"))
    else:
        flash("Delete option is available only for the author!", "rejection")
        return redirect(url_for('display_question', question_id=question_id))
예제 #2
0
def delete_image(question_id, filename):
    data_manager.delete_question_image_by_name({
        "question_id": question_id,
        "filename": filename
    })
    util.delete_all_images([{'image': f"uploads\\{filename}"}])
    return redirect(url_for('edit_question_get', question_id=question_id))
예제 #3
0
def delete_image_answer(question_id, answer_id, filename):
    data_manager.delete_answer_image_by_name_s(({
        "answer_id": answer_id,
        "filename": filename
    }))
    util.delete_all_images([{'image': f"uploads\\{filename}"}])
    return redirect(
        url_for('edit_answer_get',
                question_id=question_id,
                answer_id=answer_id))
예제 #4
0
def delete_answer(question_id, answer_id):
    user_id = data_manager.get_user_id_by_activity('answer', answer_id)
    if session.get(FORM_USERNAME) and session[SESSION_ID] == user_id:
        answer_pictures_paths = data_manager.get_answer_id_pictures_paths(
            answer_id)
        util.delete_all_images(answer_pictures_paths)
        data_manager.delete_answer_image(answer_id)
        if data_manager.has_answer_comment(answer_id) is not None:
            data_manager.delete_comment_for_answer(answer_id)

        data_manager.delete_answer_from_answers(answer_id)

        return redirect(url_for("display_question", question_id=question_id))
    else:
        flash("Delete option is available only for the author!", "rejection")
        return redirect(url_for('display_question', question_id=question_id))