Skip to content

Commit

Permalink
adding support to delete objects one at a time in the admin panel
Browse files Browse the repository at this point in the history
  • Loading branch information
ooemperor committed Nov 24, 2023
1 parent 2d2a3bc commit deafa9a
Show file tree
Hide file tree
Showing 22 changed files with 539 additions and 31 deletions.
93 changes: 92 additions & 1 deletion codeGrader/frontend/admin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
UserListHandler, UserHandler, HomeHandler, AdminListHandler, AdminHandler, ProfileListHandler, \
ProfileHandler, SubjectListHandler, SubjectHandler, TaskHandler, TaskListHandler, ExerciseHandler, \
ExerciseListHandler, AddAdminHandler, AddProfileHandler, AddUserHandler, AddTaskHandler, AddExerciseHandler, \
AddSubjectHandler
AddSubjectHandler, DeleteUserHandler, DeleteSubjectHandler, DeleteAdminHandler, DeleteTaskHandler, \
DeleteExerciseHandler, DeleteProfileHandler

app = Flask(config.adminAppName, template_folder=templates.__path__[0])

Expand Down Expand Up @@ -121,6 +122,21 @@ def addUser():
return AddUserHandler(request).post()


@app.route("/user/delete/<int:id_>", methods=['GET', 'POST'])
@login_required
def deleteUser(id_: int):
"""
Deleting a user from the database
@param id_: The identifier of the user
@type id_: int
@return: Redirect to another view.
"""
if request.method == 'GET':
return DeleteUserHandler(request).get(id_)
elif request.method == 'POST':
return DeleteUserHandler(request).post(id_)


@app.route("/admin/<int:id_>", methods=['GET', 'POST'])
@login_required
def admin(id_):
Expand Down Expand Up @@ -158,6 +174,21 @@ def addAdmin():
return AddAdminHandler(request).post()


@app.route("/admin/delete/<int:id_>", methods=['GET', 'POST'])
@login_required
def deleteAdmin(id_: int):
"""
Deleting a Admin from the database
@param id_: The identifier of the Admin
@type id_: int
@return: Redirect to another view.
"""
if request.method == 'GET':
return DeleteAdminHandler(request).get(id_)
elif request.method == 'POST':
return DeleteAdminHandler(request).post(id_)


@app.route("/profile/<int:id_>", methods=['GET', 'POST'])
@login_required
def profile(id_):
Expand Down Expand Up @@ -196,6 +227,21 @@ def addProfile():
return AddProfileHandler(request).post()


@app.route("/profile/delete/<int:id_>", methods=['GET', 'POST'])
@login_required
def deleteProfile(id_: int):
"""
Deleting a profile from the database
@param id_: The identifier of the profile
@type id_: int
@return: Redirect to another view.
"""
if request.method == 'GET':
return DeleteProfileHandler(request).get(id_)
elif request.method == 'POST':
return DeleteProfileHandler(request).post(id_)


@app.route("/subject/<int:id_>", methods=['GET', 'POST'])
@login_required
def subject(id_):
Expand Down Expand Up @@ -234,6 +280,21 @@ def addSubject():
return AddSubjectHandler(request).post()


@app.route("/subject/delete/<int:id_>", methods=['GET', 'POST'])
@login_required
def deleteSubject(id_: int):
"""
Deleting a subject from the database
@param id_: The identifier of the subject
@type id_: int
@return: Redirect to another view.
"""
if request.method == 'GET':
return DeleteSubjectHandler(request).get(id_)
elif request.method == 'POST':
return DeleteSubjectHandler(request).post(id_)


@app.route("/exercise/<int:id_>", methods=['GET', 'POST'])
@login_required
def exercise(id_):
Expand Down Expand Up @@ -272,6 +333,21 @@ def addExercise():
return AddExerciseHandler(request).post()


@app.route("/exercise/delete/<int:id_>", methods=['GET', 'POST'])
@login_required
def deleteExercise(id_: int):
"""
Deleting a exercise from the database
@param id_: The identifier of the exercise
@type id_: int
@return: Redirect to another view.
"""
if request.method == 'GET':
return DeleteExerciseHandler(request).get(id_)
elif request.method == 'POST':
return DeleteExerciseHandler(request).post(id_)


@app.route("/task/<int:id_>", methods=['GET', 'POST'])
@login_required
def task(id_):
Expand Down Expand Up @@ -310,5 +386,20 @@ def addTask():
return AddTaskHandler(request).post()


@app.route("/task/delete/<int:id_>", methods=['GET', 'POST'])
@login_required
def deleteTask(id_: int):
"""
Deleting a exercise from the database
@param id_: The identifier of the exercise
@type id_: int
@return: Redirect to another view.
"""
if request.method == 'GET':
return DeleteTaskHandler(request).get(id_)
elif request.method == 'POST':
return DeleteTaskHandler(request).post(id_)


if __name__ == "__main__":
app.run(port=config.adminPort)
47 changes: 46 additions & 1 deletion codeGrader/frontend/admin/handlers/AdminUser.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get(self, id_: int):
@return: The rendered page of the AdminUser
@rtype: HTML
"""
admin = self.api.get(f"/adminUser/{id_}")
admin = self.api.get(f"/admin/{id_}")

admin_types = self.api.get(f"/adminTypes")
admin["types"] = admin_types["admin_type"]
Expand Down Expand Up @@ -140,3 +140,48 @@ def post(self):
self.api.post(f"/admin/add", body=admin_data)

return redirect(url_for("admins"))


class DeleteAdminHandler(BaseHandler):
"""
Handler to delete a Task from the api backend
"""

def __init__(self, request: flask.Request):
"""
Constructor of the DeleteAdminHandler Handler
@param request: The request from the app route of flask
@type request: flask.Request
"""
super().__init__(request)

def get(self, id_: int):
"""
Get Handler to render the site for confirmation for deletion of an Admin
@param id_: The id_ of the Admin
@type id_: int
@return: Rendered Template
"""
task = self.api.get(f"/admin/{id_}")

return render_template("deleteAdmin.html", **task)

def post(self, id_: int):
"""
Post Operation for Admin Deletion
Deletes the task in the backend via an API Call
@param id_: The idnentifier of the Admin
@type id_: int
@return: Redirection to the Admin table
"""
if self.get_value("action_button") == "Submit":
response = self.api.delete(f"/admin/{id_}")

return redirect(url_for("admins"))

elif self.get_value("action_button") == "Cancel":
return redirect(url_for("admin", id_=id_))

else:
pass
# TODO Implement Error
45 changes: 45 additions & 0 deletions codeGrader/frontend/admin/handlers/Exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,48 @@ def post(self):
self.api.post("/exercise/add", body=exercise_data)

return redirect(url_for("exercises"))


class DeleteExerciseHandler(BaseHandler):
"""
Handler to delete a Exercise from the api backend
"""

def __init__(self, request: flask.Request):
"""
Constructor of the DeleteExerciseHandler Handler
@param request: The request from the app route of flask
@type request: flask.Request
"""
super().__init__(request)

def get(self, id_: int):
"""
Get Handler to render the site for confirmation for deletion of a Exercise
@param id_: The id_ of the Exercise
@type id_: int
@return: Rendered Template
"""
task = self.api.get(f"/exercise/{id_}")

return render_template("deleteExercise.html", **task)

def post(self, id_: int):
"""
Post Operation for Exercise Deletion
Deletes the task in the backend via an API Call
@param id_: The idnentifier of the Exercise
@type id_: int
@return: Redirection to the Exercise table
"""
if self.get_value("action_button") == "Submit":
response = self.api.delete(f"/exercise/{id_}")

return redirect(url_for("exercises"))

elif self.get_value("action_button") == "Cancel":
return redirect(url_for("exercise", id_=id_))

else:
pass
# TODO Implement Error
45 changes: 45 additions & 0 deletions codeGrader/frontend/admin/handlers/Profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,48 @@ def post(self):
self.api.post("/profile/add", body=profile_data)

return redirect(url_for("profiles"))


class DeleteProfileHandler(BaseHandler):
"""
Handler to delete a Profile from the api backend
"""

def __init__(self, request: flask.Request):
"""
Constructor of the DeleteProfileHandler Handler
@param request: The request from the app route of flask
@type request: flask.Request
"""
super().__init__(request)

def get(self, id_: int):
"""
Get Handler to render the site for confirmation for deletion of a Profile
@param id_: The id_ of the Profile
@type id_: int
@return: Rendered Template
"""
task = self.api.get(f"/profile/{id_}")

return render_template("deleteProfile.html", **task)

def post(self, id_: int):
"""
Post Operation for Profile Deletion
Deletes the task in the backend via an API Call
@param id_: The idnentifier of the Profile
@type id_: int
@return: Redirection to the Profile table
"""
if self.get_value("action_button") == "Submit":
response = self.api.delete(f"/profile/{id_}")

return redirect(url_for("profiles"))

elif self.get_value("action_button") == "Cancel":
return redirect(url_for("profile", id_=id_))

else:
pass
# TODO Implement Error
45 changes: 45 additions & 0 deletions codeGrader/frontend/admin/handlers/Subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,48 @@ def post(self):
self.api.post("/subject/add", body=subject_data)

return redirect(url_for("subjects"))


class DeleteSubjectHandler(BaseHandler):
"""
Handler to delete a Subject from the api backend
"""

def __init__(self, request: flask.Request):
"""
Constructor of the DeleteSubjectHandler Handler
@param request: The request from the app route of flask
@type request: flask.Request
"""
super().__init__(request)

def get(self, id_: int):
"""
Get Handler to render the site for confirmation for deletion of a Subject
@param id_: The id_ of the Subject
@type id_: int
@return: Rendered Template
"""
subject = self.api.get(f"/subject/{id_}")

return render_template("deleteSubject.html", **subject)

def post(self, id_: int):
"""
Post Operation for Subject Deletion
Deletes the subject in the backend via an API Call
@param id_: The idnentifier of the Subject
@type id_: int
@return: Redirection to the Subject table
"""
if self.get_value("action_button") == "Submit":
response = self.api.delete(f"/subject/{id_}")

return redirect(url_for("subjects"))

elif self.get_value("action_button") == "Cancel":
return redirect(url_for("subject", id_=id_))

else:
pass
# TODO Implement Error
Loading

0 comments on commit deafa9a

Please sign in to comment.