예제 #1
0
def update_comment_get(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:
        comment = data_manager.get_comment_by_id(comment_id)

        if comment.get("question_id") != None:
            question = data_manager.get_question_by_comment_id(comment_id)
            response = make_response(
                render_template("update_comment.html",
                                username=SESSION_USERNAME,
                                comment=comment,
                                item=question,
                                item_type="question"))
            # url_forr = url_for('update_question_comment', question_id = question["id"]),
            # url = 'update_comment_post'))
            return response

        elif comment.get("answer_id") != None:
            answer = data_manager.get_answer_by_comment_id(comment_id)
            response = make_response(
                render_template("update_comment.html",
                                username=SESSION_USERNAME,
                                comment=comment,
                                item=answer,
                                item_type="answer"))
            # url='update_comment_post'))
            return response
    else:
        flash("Update option is available only for the author!", "warning")
        return redirect(url_for('display_question', question_id=question_id))
예제 #2
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))
예제 #3
0
def delete_comment(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:
        data_manager.delete_comment(comment_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))
예제 #4
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))
예제 #5
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))
예제 #6
0
def edit_question_get(question_id):
    user_id = data_manager.get_user_id_by_activity('question', question_id)
    question = data_manager.get_question_by_id(question_id)
    question_image = data_manager.get_question_image_by_id(question_id)
    if session.get(FORM_USERNAME) and session[SESSION_ID] == user_id:
        if question is None:
            return redirect(
                url_for("display_question", question_id=question_id))
        else:
            response = make_response(
                render_template("add_update_question.html",
                                username=SESSION_USERNAME,
                                question=question,
                                question_image=question_image))
            return response
    else:
        flash("Update option is available only for the author!", "warning")
        return redirect(url_for('display_question', question_id=question_id))