Skip to content

Commit a891eef

Browse files
committed
Add refetch button to assignment list
1 parent be97e17 commit a891eef

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

nbgrader/server_extensions/assignment_list/handlers.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def list_courses(self):
193193

194194
return retvalue
195195

196-
def fetch_assignment(self, course_id, assignment_id):
196+
def fetch_assignment(self, course_id, assignment_id, replace_missing_files=False):
197197
with self.get_assignment_dir_config() as config:
198198
try:
199199
config = self.load_config()
@@ -205,7 +205,9 @@ def fetch_assignment(self, course_id, assignment_id):
205205
fetch = ExchangeFactory(config=config).FetchAssignment(
206206
coursedir=coursedir,
207207
authenticator=authenticator,
208-
config=config)
208+
config=config,
209+
replace_missing_files=replace_missing_files
210+
)
209211
fetch.start()
210212

211213
except:
@@ -310,22 +312,22 @@ def post(self, action):
310312
except web.MissingArgumentError:
311313
data = self.get_json_body()
312314

315+
assignment_id = data['assignment_id']
316+
course_id = data['course_id']
317+
313318
if action == 'fetch':
314-
assignment_id = data['assignment_id']
315-
course_id = data['course_id']
316319
self.manager.fetch_assignment(course_id, assignment_id)
317320
self.finish(json.dumps(self.manager.list_assignments(course_id=course_id)))
321+
elif action == 'fetch_missing':
322+
self.manager.fetch_assignment(course_id, assignment_id, replace_missing_files=True)
323+
self.finish(json.dumps(self.manager.list_assignments(course_id=course_id)))
318324
elif action == 'submit':
319-
assignment_id = data['assignment_id']
320-
course_id = data['course_id']
321325
output = self.manager.submit_assignment(course_id, assignment_id)
322326
if output['success']:
323327
self.finish(json.dumps(self.manager.list_assignments(course_id=course_id)))
324328
else:
325329
self.finish(json.dumps(output))
326330
elif action == 'fetch_feedback':
327-
assignment_id = data['assignment_id']
328-
course_id = data['course_id']
329331
self.manager.fetch_feedback(course_id, assignment_id)
330332
self.finish(json.dumps(self.manager.list_assignments(course_id=course_id)))
331333

@@ -367,7 +369,7 @@ def get(self):
367369
#-----------------------------------------------------------------------------
368370

369371

370-
_assignment_action_regex = r"(?P<action>fetch|submit|fetch_feedback)"
372+
_assignment_action_regex = r"(?P<action>fetch|fetch_missing|submit|fetch_feedback)"
371373

372374
default_handlers = [
373375
(r"/assignments", AssignmentListHandler),

src/assignment_list/assignmentlist.ts

+30
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,36 @@ class Assignment {
293293

294294
}
295295
} else if (this.data.status == 'fetched') {
296+
var refetchButton = document.createElement('button');
297+
refetchButton.classList.add('btn', 'btn-danger', 'btn-xs');
298+
refetchButton.setAttribute('data-bs-toggle', 'tooltip');
299+
refetchButton.setAttribute('data-bs-placement', 'top');
300+
refetchButton.setAttribute('style', 'background:#d43f3a; margin-left:5px');
301+
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.')
302+
container.append(refetchButton);
303+
304+
refetchButton.innerText = 'Refetch';
305+
refetchButton.onclick = async function(){
306+
refetchButton.innerText = 'Refetching...';
307+
refetchButton.setAttribute('disabled', 'disabled');
308+
const dataToSend = { course_id: that.data['course_id'], assignment_id: that.data['assignment_id']};
309+
try {
310+
const reply = await requestAPI<any>('assignments/fetch_missing', {
311+
body: JSON.stringify(dataToSend),
312+
method: 'POST'
313+
});
314+
315+
that.on_refresh(reply);
316+
317+
} catch (reason) {
318+
remove_children(container);
319+
container.innerText = 'Error refetching assignment.';
320+
console.error(
321+
`Error on POST /assignment_list/fetch_missing ${dataToSend}.\n${reason}`
322+
);
323+
}
324+
}
325+
296326
button.innerText = "Submit";
297327
button.onclick = async function(){
298328
button.innerText = 'submitting...';

0 commit comments

Comments
 (0)