Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add raw cell support #1922

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
42 changes: 21 additions & 21 deletions nbgrader/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def max_score(cls):
#: The cell type, either "code" or "markdown"
@declared_attr
def cell_type(cls):
return Column(Enum("code", "markdown", name="grade_cell_type", validate_strings=True), nullable=False)
return Column(Enum("code", "markdown", "raw", name="grade_cell_type", validate_strings=True), nullable=False)


class GradeCell(BaseCell, GradedMixin):
Expand Down Expand Up @@ -381,7 +381,7 @@ class SourceCell(Base):
name = Column(String(128), nullable=False)

#: The cell type, either "code" or "markdown"
cell_type = Column(Enum("code", "markdown", name="source_cell_type", validate_strings=True), nullable=False)
cell_type = Column(Enum("code", "markdown", "raw", name="source_cell_type", validate_strings=True), nullable=False)

#: Whether the cell is locked (e.g. the source saved in the database should
#: be used to overwrite the source of students' cells)
Expand Down Expand Up @@ -1082,7 +1082,7 @@ def __repr__(self):
.where(and_(
Grade.notebook_id == SubmittedNotebook.id,
GradeCell.id == Grade.cell_id,
GradeCell.cell_type == "markdown"))
GradeCell.cell_type.in_(["markdown", "raw"])))
.correlate_except(Grade)
.scalar_subquery(), deferred=True)

Expand All @@ -1092,7 +1092,7 @@ def __repr__(self):
SubmittedNotebook.assignment_id == SubmittedAssignment.id,
Grade.notebook_id == SubmittedNotebook.id,
GradeCell.id == Grade.cell_id,
GradeCell.cell_type == "markdown"))
GradeCell.cell_type.in_(["markdown", "raw"])))
.correlate_except(Grade)
.scalar_subquery(), deferred=True)

Expand All @@ -1104,7 +1104,7 @@ def __repr__(self):
.select_from(GradeCell)
.where(and_(
GradeCell.notebook_id == Notebook.id,
GradeCell.cell_type == "markdown"))
GradeCell.cell_type.in_(["markdown", "raw"])))
.correlate_except(GradeCell)
.scalar_subquery(), deferred=True)

Expand All @@ -1120,7 +1120,7 @@ def __repr__(self):
.where(and_(
Notebook.assignment_id == Assignment.id,
GradeCell.notebook_id == Notebook.id,
GradeCell.cell_type == "markdown"))
GradeCell.cell_type.in_(["markdown", "raw"])))
.correlate_except(GradeCell)
.scalar_subquery(), deferred=True)

Expand Down Expand Up @@ -1193,7 +1193,7 @@ def __repr__(self):
.where(and_(
Grade.notebook_id == SubmittedNotebook.id,
TaskCell.id == Grade.cell_id,
TaskCell.cell_type == "markdown"))
TaskCell.cell_type.in_(["markdown", "raw"])))
.correlate_except(Grade)
.scalar_subquery(), deferred=True)

Expand All @@ -1203,7 +1203,7 @@ def __repr__(self):
SubmittedNotebook.assignment_id == SubmittedAssignment.id,
Grade.notebook_id == SubmittedNotebook.id,
TaskCell.id == Grade.cell_id,
TaskCell.cell_type == "markdown"))
TaskCell.cell_type.in_(["markdown", "raw"])))
.correlate_except(Grade)
.scalar_subquery(), deferred=True)

Expand All @@ -1215,7 +1215,7 @@ def __repr__(self):
.select_from(TaskCell)
.where(and_(
TaskCell.notebook_id == Notebook.id,
TaskCell.cell_type == "markdown"))
TaskCell.cell_type.in_(["markdown", "raw"])))
.correlate_except(TaskCell)
.scalar_subquery(), deferred=True)

Expand All @@ -1231,7 +1231,7 @@ def __repr__(self):
.where(and_(
Notebook.assignment_id == Assignment.id,
TaskCell.notebook_id == Notebook.id,
TaskCell.cell_type == "markdown"))
TaskCell.cell_type.in_(["markdown", "raw"])))
.correlate_except(TaskCell)
.scalar_subquery(), deferred=True)

Expand Down Expand Up @@ -2826,7 +2826,7 @@ def average_assignment_task_score(self, assignment_id):
Notebook.assignment_id == Assignment.id,
TaskCell.notebook_id == Notebook.id,
Grade.cell_id == TaskCell.id,
TaskCell.cell_type == "markdown")).scalar()
TaskCell.cell_type.in_(["markdown", "raw"]))).scalar()
return score_sum / assignment.num_submissions

def average_notebook_score(self, notebook_id: str, assignment_id: str) -> float:
Expand Down Expand Up @@ -2920,7 +2920,7 @@ def average_notebook_written_score(self, notebook_id: str, assignment_id: str) -
Notebook.assignment_id == Assignment.id,
GradeCell.notebook_id == Notebook.id,
Grade.cell_id == GradeCell.id,
GradeCell.cell_type == "markdown")).scalar()
GradeCell.cell_type.in_(["markdown", "raw"]))).scalar()
return score_sum / notebook.num_submissions

def average_notebook_task_score(self, notebook_id: str, assignment_id: str) -> float:
Expand Down Expand Up @@ -2953,7 +2953,7 @@ def average_notebook_task_score(self, notebook_id: str, assignment_id: str) -> f
Notebook.assignment_id == Assignment.id,
TaskCell.notebook_id == Notebook.id,
Grade.cell_id == TaskCell.id,
TaskCell.cell_type == "markdown")).scalar()
TaskCell.cell_type.in_(["markdown", "raw"]))).scalar()
return score_sum / notebook.num_submissions

def student_dicts(self):
Expand Down Expand Up @@ -3038,7 +3038,7 @@ def submission_dicts(self, assignment_id):
func.sum(GradeCell.max_score).label("max_written_score"),
).select_from(SubmittedAssignment
).join(SubmittedNotebook).join(Notebook).join(Assignment).join(Student).join(Grade).join(GradeCell)\
.filter(GradeCell.cell_type == "markdown")\
.filter(GradeCell.cell_type.in_(["markdown", "raw"]))\
.group_by(SubmittedAssignment.id)\
.subquery()

Expand All @@ -3049,7 +3049,7 @@ def submission_dicts(self, assignment_id):
func.sum(TaskCell.max_score).label("max_task_score"),
).select_from(SubmittedAssignment
).join(SubmittedNotebook).join(Notebook).join(Assignment).join(Student).join(Grade).join(TaskCell)\
.filter(TaskCell.cell_type == "markdown")\
.filter(TaskCell.cell_type.in_(["markdown", "raw"]))\
.group_by(SubmittedAssignment.id)\
.subquery()

Expand Down Expand Up @@ -3082,7 +3082,7 @@ def submission_dicts(self, assignment_id):
func.sum(GradeCell.max_score).label("max_score"),
).select_from(SubmittedAssignment
).join(SubmittedNotebook).join(Grade).join(GradeCell)\
.filter(GradeCell.cell_type == "markdown")\
.filter(GradeCell.cell_type.in_(["markdown", "raw"]))\
.group_by(SubmittedAssignment.id),

self.db.query(
Expand All @@ -3091,7 +3091,7 @@ def submission_dicts(self, assignment_id):
func.sum(TaskCell.max_score).label("max_score"),
).select_from(SubmittedAssignment
).join(SubmittedNotebook).join(Grade).join(TaskCell)\
.filter(TaskCell.cell_type == "markdown")\
.filter(TaskCell.cell_type.in_(["markdown", "raw"]))\
.group_by(SubmittedAssignment.id)
).subquery()

Expand Down Expand Up @@ -3186,7 +3186,7 @@ def notebook_submission_dicts(self, notebook_id, assignment_id):
func.sum(GradeCell.max_score).label("max_written_score"),
).select_from(SubmittedNotebook
).join(SubmittedAssignment).join(Notebook).join(Assignment).join(Student).join(Grade).join(GradeCell)\
.filter(GradeCell.cell_type == "markdown")\
.filter(GradeCell.cell_type.in_(["markdown", "raw"]))\
.group_by(SubmittedNotebook.id)\
.subquery()
# subquery for the written scores
Expand All @@ -3196,7 +3196,7 @@ def notebook_submission_dicts(self, notebook_id, assignment_id):
func.sum(TaskCell.max_score).label("max_task_score"),
).select_from(SubmittedNotebook
).join(SubmittedAssignment).join(Notebook).join(Assignment).join(Student).join(Grade).join(TaskCell)\
.filter(TaskCell.cell_type == "markdown")\
.filter(TaskCell.cell_type.in_(["markdown", "raw"]))\
.group_by(SubmittedNotebook.id)\
.subquery()

Expand Down Expand Up @@ -3224,7 +3224,7 @@ def notebook_submission_dicts(self, notebook_id, assignment_id):
func.sum(GradeCell.max_score).label("max_score"),
).select_from(SubmittedNotebook
).join(Grade).join(GradeCell)\
.filter(GradeCell.cell_type == "markdown")\
.filter(GradeCell.cell_type.in_(["markdown", "raw"]))\
.group_by(SubmittedNotebook.id),

self.db.query(
Expand All @@ -3233,7 +3233,7 @@ def notebook_submission_dicts(self, notebook_id, assignment_id):
func.sum(TaskCell.max_score).label("max_score"),
).select_from(SubmittedNotebook
).join(Grade).join(TaskCell)\
.filter(TaskCell.cell_type == "markdown")\
.filter(TaskCell.cell_type.in_(["markdown", "raw"]))\
.group_by(SubmittedNotebook.id)
).subquery()

Expand Down
12 changes: 6 additions & 6 deletions nbgrader/nbgraderformat/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ def validate_cell(self, cell: NotebookNode) -> None:

# check that markdown cells are grade AND solution (not either/or)
if not task:
if cell.cell_type == "markdown" and grade and not solution:
if cell.cell_type in ("markdown", "raw") and grade and not solution:
raise ValidationError(
"Markdown grade cell '{}' is not marked as a solution cell".format(
"Markdown/raw grade cell '{}' is not marked as a solution cell".format(
meta['grade_id']))
if cell.cell_type == "markdown" and not grade and solution:
if cell.cell_type in ("markdown", "raw") and not grade and solution:
raise ValidationError(
"Markdown solution cell is not marked as a grade cell: {}".format(cell.source))
"Markdown/raw solution cell is not marked as a grade cell: {}".format(cell.source))
else:
if cell.cell_type != "markdown":
if cell.cell_type not in ("markdown", "raw"):
raise ValidationError(
"Task cells have to be markdown: {}".format(cell.source))
"Task cells have to be markdown or raw: {}".format(cell.source))

def validate_nb(self, nb: NotebookNode) -> None:
super(MetadataValidatorV3, self).validate_nb(nb)
Expand Down
Loading