def preprocess_cell(self, cell, resources, cell_index): if not (utils.is_grade(cell) or utils.is_locked(cell)): return cell, resources # if we're ignoring checksums, then remove the checksum from the # cell metadata if self.ignore_checksums and 'checksum' in cell.metadata.nbgrader: del cell.metadata.nbgrader['checksum'] # verify checksums of cells if utils.is_locked(cell) and 'checksum' in cell.metadata.nbgrader: old_checksum = cell.metadata.nbgrader['checksum'] new_checksum = utils.compute_checksum(cell) if old_checksum != new_checksum: resources['nbgrader']['checksum_mismatch'].append(cell_index) # if it's a grade cell, the check the grade if utils.is_grade(cell): score, max_score = utils.determine_grade(cell) # it's a markdown cell, so we can't do anything if score is None: pass elif score < max_score: resources['nbgrader']['failed_cells'].append(cell_index) else: resources['nbgrader']['passed_cells'].append(cell_index) return cell, resources
def preprocess_cell(self, cell, resources, cell_index): if not (utils.is_grade(cell) or utils.is_locked(cell)): return cell, resources # if we're ignoring checksums, then remove the checksum from the # cell metadata if self.ignore_checksums and 'checksum' in cell.metadata.nbgrader: del cell.metadata.nbgrader['checksum'] # verify checksums of cells if utils.is_locked(cell) and 'checksum' in cell.metadata.nbgrader: old_checksum = cell.metadata.nbgrader['checksum'] new_checksum = utils.compute_checksum(cell) if old_checksum != new_checksum: resources['nbgrader']['checksum_mismatch'].append(cell) # if it's a grade cell, the check the grade if utils.is_grade(cell): score, max_score = utils.determine_grade(cell) # it's a markdown cell, so we can't do anything if score is None: pass elif score < max_score: resources['nbgrader']['failed_cells'].append(cell) else: resources['nbgrader']['passed_cells'].append(cell) return cell, resources
def preprocess_cell(self, cell, resources, cell_index): grade_id = cell.metadata.get('nbgrader', {}).get('grade_id', None) if grade_id is None: return cell, resources try: 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 # always update the checksum, just in case cell.metadata.nbgrader["checksum"] = source_cell.checksum # if it's locked, check that the checksum hasn't changed if source_cell.locked: old_checksum = source_cell.checksum new_checksum = utils.compute_checksum(cell) if old_checksum != new_checksum: self.report_change(grade_id, "checksum", old_checksum, new_checksum) cell.source = source_cell.source # double check the the checksum is correct now if utils.compute_checksum(cell) != source_cell.checksum: raise RuntimeError("Inconsistent checksums for cell {}".format(source_cell.name)) return cell, resources
def preprocess_cell(self, cell, resources, cell_index): grade_id = cell.metadata.get('nbgrader', {}).get('grade_id', None) if grade_id is None: return cell, resources source_cell = self.gradebook.find_source_cell(grade_id, self.notebook_id, self.assignment_id) # 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 cell.metadata.nbgrader["checksum"] = source_cell.checksum # if it's locked, check that the checksum hasn't changed if source_cell.locked: old_checksum = source_cell.checksum new_checksum = utils.compute_checksum(cell) if old_checksum != new_checksum: self.report_change(grade_id, "checksum", old_checksum, new_checksum) cell.source = source_cell.source # double check the the checksum is correct now if utils.compute_checksum(cell) != source_cell.checksum: raise RuntimeError( "Inconsistent checksums for cell {}".format( source_cell.name)) return cell, resources
def _create_source_cell(self, cell: NotebookNode) -> None: grade_id = cell.metadata.nbgrader["grade_id"] try: source_cell = self.gradebook.find_source_cell( grade_id, self.notebook_id, self.assignment_id).to_dict() del source_cell["name"] del source_cell["notebook"] del source_cell["assignment"] except MissingEntry: source_cell = {} source = cell.source if is_singlechoice(cell) or is_multiplechoice(cell): source = json.dumps(cell.metadata.extended_cell) source_cell.update({ "cell_type": cell.cell_type, "locked": utils.is_locked(cell), "source": source, "checksum": cell.metadata.nbgrader.get("checksum", None), }) self.new_source_cells[grade_id] = source_cell
def preprocess_cell(self, cell, resources, cell_index): if self.lock_all_cells: cell.metadata['deletable'] = False elif self.lock_grade_cells 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_readonly_cells and utils.is_locked(cell): cell.metadata['deletable'] = False return cell, resources
def preprocess_cell(self, cell, resources, cell_index): if utils.is_grade(cell): self._create_grade_cell(cell) if utils.is_solution(cell): self._create_solution_cell(cell) if utils.is_grade(cell) or utils.is_solution(cell) or utils.is_locked(cell): self._create_source_cell(cell) return cell, resources
def preprocess_cell(self, cell, resources, cell_index): # compute checksums of grade cell and solution cells if utils.is_grade(cell) or utils.is_solution(cell) or utils.is_locked( cell): checksum = utils.compute_checksum(cell) cell.metadata.nbgrader['checksum'] = checksum if utils.is_grade(cell) or utils.is_solution(cell): self.log.debug("Checksum for '%s' is %s", cell.metadata.nbgrader['grade_id'], checksum) return cell, resources
def preprocess_cell(self, cell, resources, cell_index): if utils.is_grade(cell): self._create_grade_cell(cell) if utils.is_solution(cell): self._create_solution_cell(cell) if utils.is_grade(cell) or utils.is_solution(cell) or utils.is_locked( cell): self._create_source_cell(cell) return cell, resources
def preprocess_cell(self, cell, resources, cell_index): if not (utils.is_grade(cell) or utils.is_solution(cell) or utils.is_locked(cell)): return cell, resources grade_id = cell.metadata.nbgrader['grade_id'] if grade_id in self.grade_ids: self.log.warning("Cell with id '%s' exists multiple times!", grade_id) cell.metadata.nbgrader = {} else: self.grade_ids.add(grade_id) return cell, resources
def preprocess_cell(self, cell, resources, cell_index): # compute checksums of grade cell and solution cells if utils.is_grade(cell) or utils.is_solution(cell) or utils.is_locked(cell): checksum = utils.compute_checksum(cell) cell.metadata.nbgrader['checksum'] = checksum if utils.is_grade(cell) or utils.is_solution(cell): self.log.debug( "Checksum for '%s' is %s", cell.metadata.nbgrader['grade_id'], checksum) return cell, resources
def _create_source_cell(self, cell): grade_id = cell.metadata.nbgrader['grade_id'] try: source_cell = self.gradebook.find_source_cell(grade_id, self.notebook_id, self.assignment_id).to_dict() del source_cell['name'] del source_cell['notebook'] del source_cell['assignment'] except MissingEntry: source_cell = {} source_cell.update({ 'cell_type': cell.cell_type, 'locked': utils.is_locked(cell), 'source': cell.source, 'checksum': cell.metadata.nbgrader.get('checksum', None) }) self.new_source_cells[grade_id] = source_cell
def _create_source_cell(self, cell: NotebookNode) -> None: grade_id = cell.metadata.nbgrader['grade_id'] try: source_cell = self.gradebook.find_source_cell(grade_id, self.notebook_id, self.assignment_id).to_dict() del source_cell['name'] del source_cell['notebook'] del source_cell['assignment'] except MissingEntry: source_cell = {} source = cell.source if is_singlechoice(cell) or is_multiplechoice(cell): source = json.dumps(cell.metadata.extended_cell) source_cell.update({ 'cell_type': cell.cell_type, 'locked': utils.is_locked(cell), 'source': source, 'checksum': cell.metadata.nbgrader.get('checksum', None) }) self.new_source_cells[grade_id] = source_cell
def _create_source_cell(self, cell): grade_id = cell.metadata.nbgrader['grade_id'] try: source_cell = self.gradebook.find_source_cell( grade_id, self.notebook_id, self.assignment_id).to_dict() del source_cell['name'] del source_cell['notebook'] del source_cell['assignment'] except MissingEntry: source_cell = {} source_cell.update({ 'cell_type': cell.cell_type, 'locked': utils.is_locked(cell), 'source': cell.source, 'checksum': cell.metadata.nbgrader.get('checksum', None) }) self.new_source_cells[grade_id] = source_cell
def is_description(cell): return is_nbgrader_cell(cell) and not is_grade(cell) and is_locked(cell)
def test_is_locked(): cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=True, grade=False, locked=False) assert not utils.is_locked(cell) cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=True, grade=True, locked=False) assert not utils.is_locked(cell) cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=True, grade=False, locked=True) assert not utils.is_locked(cell) cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=True, grade=True, locked=True) assert not utils.is_locked(cell) cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=False, grade=True, locked=False) assert utils.is_locked(cell) cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=False, grade=True, locked=True) assert utils.is_locked(cell) cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=False, grade=False, locked=True) assert utils.is_locked(cell) assert utils.is_locked(cell) cell = create_code_cell() assert not utils.is_locked(cell) cell.metadata['nbgrader'] = dict(solution=False, grade=False, locked=False) assert not utils.is_locked(cell)