Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_passed_cells(self, nb: NotebookNode) -> typing.List[NotebookNode]:
passed = []
for cell in nb.cells:
if not (utils.is_grade(cell) or utils.is_locked(cell)):
continue
# if it's a grade cell, the check the grade
if utils.is_grade(cell):
score, max_score = utils.determine_grade(cell, self.log)
# it's a markdown cell, so we can't do anything
if score is None:
pass
elif score == max_score:
passed.append(cell)
return passed
def preprocess_cell(self,
cell: NotebookNode,
resources: ResourcesDict,
cell_index: int
) -> Tuple[NotebookNode, ResourcesDict]:
if (self.lock_solution_cells or self.lock_grade_cells) and utils.is_solution(cell) and utils.is_grade(cell):
cell.metadata['deletable'] = False
elif self.lock_solution_cells and utils.is_solution(cell):
cell.metadata['deletable'] = False
elif self.lock_grade_cells and utils.is_grade(cell):
cell.metadata['deletable'] = False
cell.metadata['editable'] = False
elif self.lock_readonly_cells and utils.is_locked(cell):
cell.metadata['deletable'] = False
cell.metadata['editable'] = False
elif self.lock_all_cells:
cell.metadata['deletable'] = False
cell.metadata['editable'] = False
return cell, resources
source_cell = self.gradebook.find_source_cell(
grade_id,
self.notebook_id,
self.assignment_id)
except MissingEntry:
self.log.warning("Cell '{}' does not exist in the database".format(grade_id))
del cell.metadata.nbgrader['grade_id']
return cell, resources
# check that the cell type hasn't changed
if cell.cell_type != source_cell.cell_type:
self.report_change(grade_id, "cell_type", source_cell.cell_type, cell.cell_type)
self.update_cell_type(cell, source_cell.cell_type)
# check that the locked status hasn't changed
if utils.is_locked(cell) != source_cell.locked:
self.report_change(grade_id, "locked", source_cell.locked, utils.is_locked(cell))
cell.metadata.nbgrader["locked"] = source_cell.locked
# if it's a grade cell, check that the max score hasn't changed
if utils.is_grade(cell):
grade_cell = self.gradebook.find_grade_cell(
grade_id,
self.notebook_id,
self.assignment_id)
old_points = float(grade_cell.max_score)
new_points = float(cell.metadata.nbgrader["points"])
if old_points != new_points:
self.report_change(grade_id, "points", old_points, new_points)
cell.metadata.nbgrader["points"] = old_points
grade_id,
self.notebook_id,
self.assignment_id)
except MissingEntry:
self.log.warning("Cell '{}' does not exist in the database".format(grade_id))
del cell.metadata.nbgrader['grade_id']
return cell, resources
# check that the cell type hasn't changed
if cell.cell_type != source_cell.cell_type:
self.report_change(grade_id, "cell_type", source_cell.cell_type, cell.cell_type)
self.update_cell_type(cell, source_cell.cell_type)
# check that the locked status hasn't changed
if utils.is_locked(cell) != source_cell.locked:
self.report_change(grade_id, "locked", source_cell.locked, utils.is_locked(cell))
cell.metadata.nbgrader["locked"] = source_cell.locked
# if it's a grade cell, check that the max score hasn't changed
if utils.is_grade(cell):
grade_cell = self.gradebook.find_grade_cell(
grade_id,
self.notebook_id,
self.assignment_id)
old_points = float(grade_cell.max_score)
new_points = float(cell.metadata.nbgrader["points"])
if old_points != new_points:
self.report_change(grade_id, "points", old_points, new_points)
cell.metadata.nbgrader["points"] = old_points
# always update the checksum, just in case