Skip to content

Commit

Permalink
adding templates for deletion of attachment and files, fixing wrong f…
Browse files Browse the repository at this point in the history
…ilename being shown on download
  • Loading branch information
ooemperor committed Dec 12, 2023
1 parent 289dc6e commit 69df10d
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 27 deletions.
8 changes: 4 additions & 4 deletions codeGrader/frontend/admin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,10 @@ def deleteTaskAttachment(task_id_: int, attachment_id_:int) -> Union[Response, s
@rtype: Response/str
"""
if request.method == 'GET':
return DeleteTaskAttachmentHandler(request).get(attachment_id_)
return DeleteTaskAttachmentHandler(request).get(task_id_, attachment_id_)

elif request.method == 'POST':
return DeleteTaskAttachmentHandler(request).post(attachment_id_)
return DeleteTaskAttachmentHandler(request).post(task_id_, attachment_id_)


@app.route("/task/<int:id_>/instruction/add", methods=['POST'])
Expand Down Expand Up @@ -499,10 +499,10 @@ def deleteTaskInstruction(task_id_: int, instruction_id_: int) -> Union[Response
@rtype: Response/str
"""
if request.method == 'GET':
return DeleteTaskInstructionHandler(request).get(instruction_id_)
return DeleteTaskInstructionHandler(request).get(task_id_, instruction_id_)

elif request.method == 'DELETE':
return DeleteTaskInstructionHandler(request).post(instruction_id_)
return DeleteTaskInstructionHandler(request).post(task_id_, instruction_id_)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion codeGrader/frontend/admin/handlers/TaskAttachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, request: flask.Request) -> None:
@type request: flask.Request
"""
super().__init__(request)
self.templateName = "DeleteTaskAttachment.html"
self.templateName = "deleteTaskAttachment.html"
self.fileObject = "attachment"


Expand Down
35 changes: 22 additions & 13 deletions codeGrader/frontend/admin/handlers/TaskFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,46 +115,55 @@ def __init__(self, request: flask.Request) -> None:
self.templateName = None
self.fileObject = None

def get(self, id_: int) -> Union[str, Response]:
def get(self, task_id_: int, file_id_: int) -> Union[str, Response]:
"""
Get Handler to render the site for confirmation for deletion of a Task
@param id_: The id_ of the task
@type id_: int
@param task_id_: The id_ of the Task
@type task_id_: int
@param file_id_: The id_ of the File
@type file_id_: int
@return: Rendered Template
"""
task = self.api.get(f"/task/{id_}")
task = self.api.get(f"/task/{task_id_}")

editable = self.admin.check_permission('w', task["profile"]["id"])

attachment = self.api.get(f"/task/{task_id_}/{self.fileObject}/{file_id_}")

if editable:
return render_template(self.templateName, **task) # TODO: Create the Template
return render_template(self.templateName, **attachment) # TODO: Create the Template

else:
self.flash("You are not allowed to delete Files on this Task. ")
return redirect(url_for("tasks"))
return redirect(url_for("task", id_=task_id_))

def post(self, id_: int) -> Response:
def post(self,task_id_: int, file_id_: int) -> Response:
"""
Post Operation for Task Deletion
Deletes the task in the backend via an API Call
@param id_: The idnentifier of the Task
@type id_: int
@param task_id_: The idnentifier of the Task
@type task_id_: int
@param file_id_: The idnentifier of the File
@type file_id_: int
@return: Redirection to the Task table
"""
task = self.api.get(f"/task/{id_}")
task = self.api.get(f"/task/{task_id_}")
if self.admin.check_permission('w', task["profile"]["id"]): # admin is allowed to delete the task

if self.get_value("action_button") == "Submit":
# TODO: Implement Deletion
raise NotImplementedError
self.api.delete(f"/task/{task_id_}/{self.fileObject}/{file_id_}")

self.flash(f"{self.fileObject} has been deleted")
return redirect(url_for("task", id_=task_id_))

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

else:
pass
# TODO Implement Error

else: # admin is not allowed to delete tasks
self.flash("You are not allowed to delete Files from tasks. ")
return redirect(url_for("task", id_=id_))
return redirect(url_for("task", id_=task_id_))
4 changes: 2 additions & 2 deletions codeGrader/frontend/admin/handlers/TaskInstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, request: flask.Request) -> None:
self.fileObject = "instruction"


class TaskInstructionHandler(AddTaskFile):
class TaskInstructionHandler(TaskFile):
"""
Handles the operation on TaskInstructions
"""
Expand All @@ -53,5 +53,5 @@ def __init__(self, request: flask.Request) -> None:
@type request: flask.Request
"""
super().__init__(request)
self.templateName = "DeleteTaskInstruction.html"
self.templateName = "deleteTaskInstruction.html"
self.fileObject = "instruction"
26 changes: 26 additions & 0 deletions codeGrader/frontend/admin/templates/deleteAttachment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "base.html" %}

{% block core %}
<div id="main" class="main">
<div>
<h1 class="header1 core_content">Delete Attachment {{ file['filename'] }}</h1>
</div>
<p class="core_content">Attachment {{ file['filename'] }}</p>
<div class="core_content">
Are you sure you wanna delete Attachment {{ file['filename'] }}?
</div>

<form action="{{url_for('deleteAttachment', attachment_id_ = id)}}" method="POST" class="core_content">
<div id="control_buttons">
<button name="action_button" id="btn_submit" class="btn btn_submit" type="submit"
value="Submit">Submit</button>
<button name="action_button" id="btn_submit" class="btn btn_submit" type="submit"
value="Cancel">Cancel</button>
</div>
</form>




</div>
{% endblock core %}
6 changes: 3 additions & 3 deletions codeGrader/frontend/admin/templates/deleteExercise.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
{% block core %}
<div id="main" class="main">
<div>
<h1 class="header1 core_content">Delete Exercise {{ username }}</h1>
<h1 class="header1 core_content">Delete Exercise {{ name }}</h1>
</div>
<p class="core_content">Exercise {{ username }}</p>
<p class="core_content">Exercise {{ name }}</p>
<div class="core_content">
Are you sure you wanna delete Exercise {{ username }}?
Are you sure you wanna delete Exercise {{ name }}?
</div>

<form action="{{url_for('deleteExercise', id_ = id)}}" method="POST" class="core_content">
Expand Down
26 changes: 26 additions & 0 deletions codeGrader/frontend/admin/templates/deleteInstructions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "base.html" %}

{% block core %}
<div id="main" class="main">
<div>
<h1 class="header1 core_content">Delete Instruction {{ file['filename'] }}</h1>
</div>
<p class="core_content">Instruction {{ file['filename'] }}</p>
<div class="core_content">
Are you sure you wanna delete Instruction {{ file['filename'] }}?
</div>

<form action="{{url_for('deleteInstruction', instruction_id_ = id)}}" method="POST" class="core_content">
<div id="control_buttons">
<button name="action_button" id="btn_submit" class="btn btn_submit" type="submit"
value="Submit">Submit</button>
<button name="action_button" id="btn_submit" class="btn btn_submit" type="submit"
value="Cancel">Cancel</button>
</div>
</form>




</div>
{% endblock core %}
4 changes: 3 additions & 1 deletion codeGrader/frontend/admin/templates/exercise.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ <h1 class="header1 core_content">Exercise {{ name }}</h1>
<h2 class="collapsible core_content">Tasks</h2>
<div class="collapsible_content">
{% for t in tasks %}
<p class="core_content">{{ t['name'] }}</p>
<a class="core_content" href="{{ url_for('task', id_ = t['id']|string) }}">
{{ t["name"] }}
</a>
{% endfor %}
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion codeGrader/frontend/admin/templates/subject.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ <h1 class="header1 core_content">Subject {{ name }}</h1>
<h2 class="collapsible core_content">Exercises</h2>
<div class="collapsible_content">
{% for ex in exercises %}
<p class="core_content">{{ ex['name'] }}</p>
<a class="core_content" href="{{ url_for('exercise', id_ = ex['id']|string) }}">
{{ ex["name"] }}
</a>
{% endfor %}
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions codeGrader/frontend/admin/templates/task.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ <h2 class="collapsible core_content">Instructions</h2>
{% if instructions %}
{% for inst in instructions %}
<br>
<a href="{{ url_for('TaskInstruction', task_id_= id, instruction_id_ = inst['id']) }}" target="_blank" download>
<a href="{{ url_for('TaskInstruction', task_id_= id, instruction_id_ = inst['id']) }}" target="_blank" download="{{ inst['file']['filename'] }}">
{{ inst["file"]["filename"] }}
</a>
<br>
Expand All @@ -92,7 +92,7 @@ <h2 class="collapsible core_content">Attachments</h2>
{% if attachments %}
{% for att in attachments %}
<br>
<a href="{{ url_for('TaskAttachment', task_id_= id, attachment_id_ = att['id']) }}" target="_blank" download>
<a href="{{ url_for('TaskAttachment', task_id_= id, attachment_id_ = att['id']) }}" target="_blank" download="{{ att['file']['filename'] }}">
{{ att["file"]["filename"] }}
</a>
<br>
Expand Down

0 comments on commit 69df10d

Please sign in to comment.