From a891eef5b36d781458fcf6612bd121aa592c2bee Mon Sep 17 00:00:00 2001 From: KrKOo Date: Tue, 15 Oct 2024 15:05:42 +0200 Subject: [PATCH 1/2] Add refetch button to assignment list --- .../assignment_list/handlers.py | 20 +++++++------ src/assignment_list/assignmentlist.ts | 30 +++++++++++++++++++ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/nbgrader/server_extensions/assignment_list/handlers.py b/nbgrader/server_extensions/assignment_list/handlers.py index 2e83aa1a8..f05c5557a 100644 --- a/nbgrader/server_extensions/assignment_list/handlers.py +++ b/nbgrader/server_extensions/assignment_list/handlers.py @@ -193,7 +193,7 @@ def list_courses(self): return retvalue - def fetch_assignment(self, course_id, assignment_id): + def fetch_assignment(self, course_id, assignment_id, replace_missing_files=False): with self.get_assignment_dir_config() as config: try: config = self.load_config() @@ -205,7 +205,9 @@ def fetch_assignment(self, course_id, assignment_id): fetch = ExchangeFactory(config=config).FetchAssignment( coursedir=coursedir, authenticator=authenticator, - config=config) + config=config, + replace_missing_files=replace_missing_files + ) fetch.start() except: @@ -310,22 +312,22 @@ def post(self, action): except web.MissingArgumentError: data = self.get_json_body() + assignment_id = data['assignment_id'] + course_id = data['course_id'] + if action == 'fetch': - assignment_id = data['assignment_id'] - course_id = data['course_id'] self.manager.fetch_assignment(course_id, assignment_id) self.finish(json.dumps(self.manager.list_assignments(course_id=course_id))) + elif action == 'fetch_missing': + self.manager.fetch_assignment(course_id, assignment_id, replace_missing_files=True) + self.finish(json.dumps(self.manager.list_assignments(course_id=course_id))) elif action == 'submit': - assignment_id = data['assignment_id'] - course_id = data['course_id'] output = self.manager.submit_assignment(course_id, assignment_id) if output['success']: self.finish(json.dumps(self.manager.list_assignments(course_id=course_id))) else: self.finish(json.dumps(output)) elif action == 'fetch_feedback': - assignment_id = data['assignment_id'] - course_id = data['course_id'] self.manager.fetch_feedback(course_id, assignment_id) self.finish(json.dumps(self.manager.list_assignments(course_id=course_id))) @@ -367,7 +369,7 @@ def get(self): #----------------------------------------------------------------------------- -_assignment_action_regex = r"(?Pfetch|submit|fetch_feedback)" +_assignment_action_regex = r"(?Pfetch|fetch_missing|submit|fetch_feedback)" default_handlers = [ (r"/assignments", AssignmentListHandler), diff --git a/src/assignment_list/assignmentlist.ts b/src/assignment_list/assignmentlist.ts index 7c61db091..d6d185c0e 100644 --- a/src/assignment_list/assignmentlist.ts +++ b/src/assignment_list/assignmentlist.ts @@ -293,6 +293,36 @@ class Assignment { } } else if (this.data.status == 'fetched') { + var refetchButton = document.createElement('button'); + refetchButton.classList.add('btn', 'btn-danger', 'btn-xs'); + refetchButton.setAttribute('data-bs-toggle', 'tooltip'); + refetchButton.setAttribute('data-bs-placement', 'top'); + refetchButton.setAttribute('style', 'background:#d43f3a; margin-left:5px'); + refetchButton.setAttribute('title', 'If you broke any of your assignment files and you want to redownload them, delete those files and click this button to refetch the original version of those files.') + container.append(refetchButton); + + refetchButton.innerText = 'Refetch'; + refetchButton.onclick = async function(){ + refetchButton.innerText = 'Refetching...'; + refetchButton.setAttribute('disabled', 'disabled'); + const dataToSend = { course_id: that.data['course_id'], assignment_id: that.data['assignment_id']}; + try { + const reply = await requestAPI('assignments/fetch_missing', { + body: JSON.stringify(dataToSend), + method: 'POST' + }); + + that.on_refresh(reply); + + } catch (reason) { + remove_children(container); + container.innerText = 'Error refetching assignment.'; + console.error( + `Error on POST /assignment_list/fetch_missing ${dataToSend}.\n${reason}` + ); + } + } + button.innerText = "Submit"; button.onclick = async function(){ button.innerText = 'submitting...'; From 2b1c016fa2ca087e79df748583bd87db136a44ba Mon Sep 17 00:00:00 2001 From: KrKOo Date: Tue, 15 Oct 2024 17:04:52 +0200 Subject: [PATCH 2/2] Rename "Refetch" button to "Fetch missing files" --- src/assignment_list/assignmentlist.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/assignment_list/assignmentlist.ts b/src/assignment_list/assignmentlist.ts index d6d185c0e..61c8da381 100644 --- a/src/assignment_list/assignmentlist.ts +++ b/src/assignment_list/assignmentlist.ts @@ -301,9 +301,9 @@ class Assignment { refetchButton.setAttribute('title', 'If you broke any of your assignment files and you want to redownload them, delete those files and click this button to refetch the original version of those files.') container.append(refetchButton); - refetchButton.innerText = 'Refetch'; + refetchButton.innerText = 'Fetch missing files'; refetchButton.onclick = async function(){ - refetchButton.innerText = 'Refetching...'; + refetchButton.innerText = 'Fetching missing files...'; refetchButton.setAttribute('disabled', 'disabled'); const dataToSend = { course_id: that.data['course_id'], assignment_id: that.data['assignment_id']}; try { @@ -316,7 +316,7 @@ class Assignment { } catch (reason) { remove_children(container); - container.innerText = 'Error refetching assignment.'; + container.innerText = 'Error fetching missing files.'; console.error( `Error on POST /assignment_list/fetch_missing ${dataToSend}.\n${reason}` );