Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions nbgrader/exchange/default/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,36 @@ def do_copy(self, src, dest, log=None):
specified by the options coursedir.ignore, coursedir.include
and coursedir.max_file_size.
"""
shutil.copytree(src, dest,
ignore=ignore_patterns(exclude=self.coursedir.ignore,
include=self.coursedir.include,
max_file_size=self.coursedir.max_file_size,
log=self.log))
# copytree copies access mode too - so we must add go+rw back to it if
# we are in groupshared.
if self.coursedir.groupshared:
for dirname, _, filenames in os.walk(dest):
# dirs become ug+rwx
st_mode = os.stat(dirname).st_mode
if st_mode & 0o2770 != 0o2770:
try:
os.chmod(dirname, (st_mode|0o2770) & 0o2777)
except PermissionError:
self.log.warning("Could not update permissions of %s to make it groupshared", dirname)

for filename in filenames:
filename = os.path.join(dirname, filename)
st_mode = os.stat(filename).st_mode
if st_mode & 0o660 != 0o660:
try:
shutil.copytree(src, dest,
ignore=ignore_patterns(exclude=self.coursedir.ignore,
include=self.coursedir.include,
max_file_size=self.coursedir.max_file_size,
log=self.log))
except OSError as err:
raise err
# Set permissions for copied files, even if some failed to copy
finally:
# copytree copies access mode too - so we must add go+rw back to it if
# we are in groupshared.
if self.coursedir.groupshared:
for dirname, _, filenames in os.walk(dest):
# dirs become ug+rwx
st_mode = os.stat(dirname).st_mode
if st_mode & 0o2770 != 0o2770:
try:
os.chmod(filename, (st_mode|0o660) & 0o777)
os.chmod(dirname, (st_mode|0o2770) & 0o2777)
except PermissionError:
self.log.warning("Could not update permissions of %s to make it groupshared", filename)
self.log.warning("Could not update permissions of %s to make it groupshared", dirname)

for filename in filenames:
filename = os.path.join(dirname, filename)
st_mode = os.stat(filename).st_mode
if st_mode & 0o660 != 0o660:
try:
os.chmod(filename, (st_mode|0o660) & 0o777)
except PermissionError:
self.log.warning("Could not update permissions of %s to make it groupshared", filename)

def start(self):
if sys.platform == 'win32':
Expand Down
30 changes: 22 additions & 8 deletions nbgrader/exchange/default/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,23 @@ def copy_files(self):
self.log.info("Source: {}".format(self.src_path))
self.log.info("Destination: {}".format(dest_path))

errors = []

# copy to the real location
self.check_filename_diff()
self.do_copy(self.src_path, dest_path)
with open(os.path.join(dest_path, "timestamp.txt"), "w") as fh:
fh.write(self.timestamp)
self.set_perms(
dest_path,
fileperms=(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH),
dirperms=(S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
try:
self.do_copy(self.src_path, dest_path)
except OSError as err:
errors.append(err)

# Create timestamp even if copying is incomplete to not break later functions
if os.path.isdir(dest_path):
with open(os.path.join(dest_path, "timestamp.txt"), "w") as fh:
fh.write(self.timestamp)
self.set_perms(
dest_path,
fileperms=(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH),
dirperms=(S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))

# Make this 0777=ugo=rwx so the instructor can delete later. Hidden from other users by the timestamp.
os.chmod(
Expand All @@ -150,10 +158,16 @@ def copy_files(self):
# also copy to the cache
if not os.path.isdir(self.cache_path):
os.makedirs(self.cache_path)
self.do_copy(self.src_path, cache_path)
try:
self.do_copy(self.src_path, cache_path)
except OSError as err:
errors.append(err) # probably duplicates from above
with open(os.path.join(cache_path, "timestamp.txt"), "w") as fh:
fh.write(self.timestamp)

self.log.info("Submitted as: {} {} {}".format(
self.coursedir.course_id, self.coursedir.assignment_id, str(self.timestamp)
))

if errors:
raise OSError(errors)
58 changes: 56 additions & 2 deletions nbgrader/nbextensions/assignment_list/assignment_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,25 @@ define([
return container;
};

Assignment.prototype.fetch_error = function (data) {
var body = $('<div/>').attr('id', 'fetch-message');

body.append(
$('<div/>').append(
$('<p/>').text('Assignment not fetched:')
)
);
body.append(
$('<pre/>').text(data.value)
);

dialog.modal({
title: "Fetch failed",
body: body,
buttons: { OK: { class : "btn-primary" } }
});
};

Assignment.prototype.submit_error = function (data) {
var body = $('<div/>').attr('id', 'submission-message');

Expand All @@ -400,6 +419,25 @@ define([
});
};

Assignment.prototype.fetchfeedback_error = function (data) {
var body = $('<div/>').attr('id', 'fetchfeedback-message');

body.append(
$('<div/>').append(
$('<p/>').text('Feedback not fetched:')
)
);
body.append(
$('<pre/>').text(data.value)
);

dialog.modal({
title: "Fetch Feedback failed",
body: body,
buttons: { OK: { class : "btn-primary" } }
});
};

Assignment.prototype.make_button = function () {
var that = this;
var container = $('<span/>').addClass('item_status col-sm-4');
Expand All @@ -417,7 +455,15 @@ define([
},
type : "POST",
dataType : "json",
success : $.proxy(that.on_refresh, that),
success : function (data, status, xhr) {
if (!data.success) {
that.fetch_error(data);
button.text('Fetch');
button.removeAttr('disabled');
} else {
that.on_refresh(data, status, xhr);
}
},
error : function (xhr, status, error) {
container.empty().text("Error fetching assignment.");
utils.log_ajax_error(xhr, status, error);
Expand Down Expand Up @@ -479,7 +525,15 @@ define([
},
type : "POST",
dataType : "json",
success : $.proxy(that.on_refresh, that),
success : function (data, status, xhr) {
if (!data.success) {
that.fetchfeedback_error();
button.text('Fetch Feedback');
button.removeAttr('disabled');
} else {
that.on_refresh(data, status, xhr);
}
},
error : function (xhr, status, error) {
container.empty().text("Error fetching feedback.");
utils.log_ajax_error(xhr, status, error);
Expand Down
14 changes: 10 additions & 4 deletions nbgrader/server_extensions/assignment_list/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,11 @@ def post(self, action):
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)))
output = self.manager.fetch_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 == 'submit':
assignment_id = data['assignment_id']
course_id = data['course_id']
Expand All @@ -320,8 +323,11 @@ def post(self, action):
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)))
output = self.manager.fetch_feedback(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))


class CourseListHandler(BaseAssignmentHandler):
Expand Down
48 changes: 45 additions & 3 deletions src/assignment_list/assignmentlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,21 @@ class Assignment {
return container;
};

private fetch_error(data: { value: any; }): void {

const body_title = React.createElement('p', null, 'Assignment not fetched:');
const body_content = React.createElement('pre', null, data.value);
const body = React.createElement("div", {'id': 'fetch-message'}, [body_title, body_content]);

showNbGraderDialog({
title: "Fetch Failed",
body: body,
buttons: [Dialog.okButton()]
}, true);


};

private submit_error(data: { value: any; }): void {

const body_title = React.createElement('p', null, 'Assignment not submitted:');
Expand All @@ -260,6 +275,21 @@ class Assignment {
}, true);


};

private fetchfeedback_error(data: { value: any; }): void {

const body_title = React.createElement('p', null, 'Feedback not fetched:');
const body_content = React.createElement('pre', null, data.value);
const body = React.createElement("div", {'id': 'fetchfeedback-message'}, [body_title, body_content]);

showNbGraderDialog({
title: "Fetch Failed",
body: body,
buttons: [Dialog.okButton()]
}, true);


};

private make_button(): HTMLSpanElement{
Expand All @@ -271,7 +301,7 @@ class Assignment {
var that = this;
if (this.data['status'] === 'released') {

button.innerText = "fetch";
button.innerText = "Fetch";
button.onclick = async function(){
button.innerText = 'Fetching...';
button.setAttribute('disabled', 'disabled');
Expand All @@ -282,7 +312,13 @@ class Assignment {
method: 'POST'
});

that.on_refresh(reply);
if(!reply.success){
that.fetch_error(reply);
button.innerText = 'Fetch'
button.removeAttribute('disabled')
}else{
that.on_refresh(reply);
}
} catch (reason) {
remove_children(container);
container.innerText = 'Error fetching assignment.';
Expand Down Expand Up @@ -335,7 +371,13 @@ class Assignment {
method: 'POST'
});

that.on_refresh(reply);
if(!reply.success){
that.fetchfeedback_error(reply);
button.innerText = 'Fetch Feedback'
button.removeAttribute('disabled')
}else{
that.on_refresh(reply);
}

} catch (reason) {
remove_children(container);
Expand Down
4 changes: 4 additions & 0 deletions style/validation_message.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#fetch-message p,
#submission-message p,
#fetchfeedback-message p,
#validation-message p {
margin-bottom: 1em;
padding-top: 1em;
}

#fetch-message pre,
#submission-message pre,
#fetchfeedback-message pre,
#validation-message pre {
border: solid var(--jp-border-color2) 1px;
padding: 5px;
Expand Down