Skip to content

Commit 68a3278

Browse files
committed
Add raw cell support
1 parent ef44180 commit 68a3278

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

nbgrader/api.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def max_score(cls):
269269
#: The cell type, either "code" or "markdown"
270270
@declared_attr
271271
def cell_type(cls):
272-
return Column(Enum("code", "markdown", name="grade_cell_type", validate_strings=True), nullable=False)
272+
return Column(Enum("code", "markdown", "raw", name="grade_cell_type", validate_strings=True), nullable=False)
273273

274274

275275
class GradeCell(BaseCell, GradedMixin):
@@ -381,7 +381,7 @@ class SourceCell(Base):
381381
name = Column(String(128), nullable=False)
382382

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

386386
#: Whether the cell is locked (e.g. the source saved in the database should
387387
#: be used to overwrite the source of students' cells)
@@ -1082,7 +1082,7 @@ def __repr__(self):
10821082
.where(and_(
10831083
Grade.notebook_id == SubmittedNotebook.id,
10841084
GradeCell.id == Grade.cell_id,
1085-
GradeCell.cell_type == "markdown"))
1085+
GradeCell.cell_type in ("markdown", "raw")))
10861086
.correlate_except(Grade)
10871087
.scalar_subquery(), deferred=True)
10881088

@@ -1092,7 +1092,7 @@ def __repr__(self):
10921092
SubmittedNotebook.assignment_id == SubmittedAssignment.id,
10931093
Grade.notebook_id == SubmittedNotebook.id,
10941094
GradeCell.id == Grade.cell_id,
1095-
GradeCell.cell_type == "markdown"))
1095+
GradeCell.cell_type in ("markdown", "raw")))
10961096
.correlate_except(Grade)
10971097
.scalar_subquery(), deferred=True)
10981098

@@ -1104,7 +1104,7 @@ def __repr__(self):
11041104
.select_from(GradeCell)
11051105
.where(and_(
11061106
GradeCell.notebook_id == Notebook.id,
1107-
GradeCell.cell_type == "markdown"))
1107+
GradeCell.cell_type in ("markdown", "raw")))
11081108
.correlate_except(GradeCell)
11091109
.scalar_subquery(), deferred=True)
11101110

@@ -1120,7 +1120,7 @@ def __repr__(self):
11201120
.where(and_(
11211121
Notebook.assignment_id == Assignment.id,
11221122
GradeCell.notebook_id == Notebook.id,
1123-
GradeCell.cell_type == "markdown"))
1123+
GradeCell.cell_type in ("markdown", "raw")))
11241124
.correlate_except(GradeCell)
11251125
.scalar_subquery(), deferred=True)
11261126

@@ -1193,7 +1193,7 @@ def __repr__(self):
11931193
.where(and_(
11941194
Grade.notebook_id == SubmittedNotebook.id,
11951195
TaskCell.id == Grade.cell_id,
1196-
TaskCell.cell_type == "markdown"))
1196+
TaskCell.cell_type in ("markdown", "raw")))
11971197
.correlate_except(Grade)
11981198
.scalar_subquery(), deferred=True)
11991199

@@ -1203,7 +1203,7 @@ def __repr__(self):
12031203
SubmittedNotebook.assignment_id == SubmittedAssignment.id,
12041204
Grade.notebook_id == SubmittedNotebook.id,
12051205
TaskCell.id == Grade.cell_id,
1206-
TaskCell.cell_type == "markdown"))
1206+
TaskCell.cell_type in ("markdown", "raw")))
12071207
.correlate_except(Grade)
12081208
.scalar_subquery(), deferred=True)
12091209

@@ -1215,7 +1215,7 @@ def __repr__(self):
12151215
.select_from(TaskCell)
12161216
.where(and_(
12171217
TaskCell.notebook_id == Notebook.id,
1218-
TaskCell.cell_type == "markdown"))
1218+
TaskCell.cell_type in ("markdown", "raw")))
12191219
.correlate_except(TaskCell)
12201220
.scalar_subquery(), deferred=True)
12211221

@@ -1231,7 +1231,7 @@ def __repr__(self):
12311231
.where(and_(
12321232
Notebook.assignment_id == Assignment.id,
12331233
TaskCell.notebook_id == Notebook.id,
1234-
TaskCell.cell_type == "markdown"))
1234+
TaskCell.cell_type in ("markdown", "raw")))
12351235
.correlate_except(TaskCell)
12361236
.scalar_subquery(), deferred=True)
12371237

@@ -2826,7 +2826,7 @@ def average_assignment_task_score(self, assignment_id):
28262826
Notebook.assignment_id == Assignment.id,
28272827
TaskCell.notebook_id == Notebook.id,
28282828
Grade.cell_id == TaskCell.id,
2829-
TaskCell.cell_type == "markdown")).scalar()
2829+
TaskCell.cell_type in ("markdown", "raw"))).scalar()
28302830
return score_sum / assignment.num_submissions
28312831

28322832
def average_notebook_score(self, notebook_id: str, assignment_id: str) -> float:
@@ -2920,7 +2920,7 @@ def average_notebook_written_score(self, notebook_id: str, assignment_id: str) -
29202920
Notebook.assignment_id == Assignment.id,
29212921
GradeCell.notebook_id == Notebook.id,
29222922
Grade.cell_id == GradeCell.id,
2923-
GradeCell.cell_type == "markdown")).scalar()
2923+
GradeCell.cell_type in ("markdown", "raw"))).scalar()
29242924
return score_sum / notebook.num_submissions
29252925

29262926
def average_notebook_task_score(self, notebook_id: str, assignment_id: str) -> float:
@@ -2953,7 +2953,7 @@ def average_notebook_task_score(self, notebook_id: str, assignment_id: str) -> f
29532953
Notebook.assignment_id == Assignment.id,
29542954
TaskCell.notebook_id == Notebook.id,
29552955
Grade.cell_id == TaskCell.id,
2956-
TaskCell.cell_type == "markdown")).scalar()
2956+
TaskCell.cell_type in ("markdown", "raw"))).scalar()
29572957
return score_sum / notebook.num_submissions
29582958

29592959
def student_dicts(self):
@@ -3038,7 +3038,7 @@ def submission_dicts(self, assignment_id):
30383038
func.sum(GradeCell.max_score).label("max_written_score"),
30393039
).select_from(SubmittedAssignment
30403040
).join(SubmittedNotebook).join(Notebook).join(Assignment).join(Student).join(Grade).join(GradeCell)\
3041-
.filter(GradeCell.cell_type == "markdown")\
3041+
.filter(GradeCell.cell_type in ("markdown", "raw"))\
30423042
.group_by(SubmittedAssignment.id)\
30433043
.subquery()
30443044

@@ -3049,7 +3049,7 @@ def submission_dicts(self, assignment_id):
30493049
func.sum(TaskCell.max_score).label("max_task_score"),
30503050
).select_from(SubmittedAssignment
30513051
).join(SubmittedNotebook).join(Notebook).join(Assignment).join(Student).join(Grade).join(TaskCell)\
3052-
.filter(TaskCell.cell_type == "markdown")\
3052+
.filter(TaskCell.cell_type in ("markdown", "raw"))\
30533053
.group_by(SubmittedAssignment.id)\
30543054
.subquery()
30553055

@@ -3082,7 +3082,7 @@ def submission_dicts(self, assignment_id):
30823082
func.sum(GradeCell.max_score).label("max_score"),
30833083
).select_from(SubmittedAssignment
30843084
).join(SubmittedNotebook).join(Grade).join(GradeCell)\
3085-
.filter(GradeCell.cell_type == "markdown")\
3085+
.filter(GradeCell.cell_type in ("markdown", "raw"))\
30863086
.group_by(SubmittedAssignment.id),
30873087

30883088
self.db.query(
@@ -3091,7 +3091,7 @@ def submission_dicts(self, assignment_id):
30913091
func.sum(TaskCell.max_score).label("max_score"),
30923092
).select_from(SubmittedAssignment
30933093
).join(SubmittedNotebook).join(Grade).join(TaskCell)\
3094-
.filter(TaskCell.cell_type == "markdown")\
3094+
.filter(TaskCell.cell_type in ("markdown", "raw"))\
30953095
.group_by(SubmittedAssignment.id)
30963096
).subquery()
30973097

@@ -3186,7 +3186,7 @@ def notebook_submission_dicts(self, notebook_id, assignment_id):
31863186
func.sum(GradeCell.max_score).label("max_written_score"),
31873187
).select_from(SubmittedNotebook
31883188
).join(SubmittedAssignment).join(Notebook).join(Assignment).join(Student).join(Grade).join(GradeCell)\
3189-
.filter(GradeCell.cell_type == "markdown")\
3189+
.filter(GradeCell.cell_type in ("markdown", "raw"))\
31903190
.group_by(SubmittedNotebook.id)\
31913191
.subquery()
31923192
# subquery for the written scores
@@ -3196,7 +3196,7 @@ def notebook_submission_dicts(self, notebook_id, assignment_id):
31963196
func.sum(TaskCell.max_score).label("max_task_score"),
31973197
).select_from(SubmittedNotebook
31983198
).join(SubmittedAssignment).join(Notebook).join(Assignment).join(Student).join(Grade).join(TaskCell)\
3199-
.filter(TaskCell.cell_type == "markdown")\
3199+
.filter(TaskCell.cell_type in ("markdown", "raw"))\
32003200
.group_by(SubmittedNotebook.id)\
32013201
.subquery()
32023202

@@ -3224,7 +3224,7 @@ def notebook_submission_dicts(self, notebook_id, assignment_id):
32243224
func.sum(GradeCell.max_score).label("max_score"),
32253225
).select_from(SubmittedNotebook
32263226
).join(Grade).join(GradeCell)\
3227-
.filter(GradeCell.cell_type == "markdown")\
3227+
.filter(GradeCell.cell_type in ("markdown", "raw"))\
32283228
.group_by(SubmittedNotebook.id),
32293229

32303230
self.db.query(
@@ -3233,7 +3233,7 @@ def notebook_submission_dicts(self, notebook_id, assignment_id):
32333233
func.sum(TaskCell.max_score).label("max_score"),
32343234
).select_from(SubmittedNotebook
32353235
).join(Grade).join(TaskCell)\
3236-
.filter(TaskCell.cell_type == "markdown")\
3236+
.filter(TaskCell.cell_type in ("markdown", "raw"))\
32373237
.group_by(SubmittedNotebook.id)
32383238
).subquery()
32393239

nbgrader/nbgraderformat/v3.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ def validate_cell(self, cell: NotebookNode) -> None:
7777

7878
# check that markdown cells are grade AND solution (not either/or)
7979
if not task:
80-
if cell.cell_type == "markdown" and grade and not solution:
80+
if cell.cell_type in ("markdown", "raw") and grade and not solution:
8181
raise ValidationError(
82-
"Markdown grade cell '{}' is not marked as a solution cell".format(
82+
"Markdown/raw grade cell '{}' is not marked as a solution cell".format(
8383
meta['grade_id']))
84-
if cell.cell_type == "markdown" and not grade and solution:
84+
if cell.cell_type in ("markdown", "raw") and not grade and solution:
8585
raise ValidationError(
86-
"Markdown solution cell is not marked as a grade cell: {}".format(cell.source))
86+
"Markdown/raw solution cell is not marked as a grade cell: {}".format(cell.source))
8787
else:
88-
if cell.cell_type != "markdown":
88+
if cell.cell_type not in ("markdown", "raw"):
8989
raise ValidationError(
90-
"Task cells have to be markdown: {}".format(cell.source))
90+
"Task cells have to be markdown or raw: {}".format(cell.source))
9191

9292
def validate_nb(self, nb: NotebookNode) -> None:
9393
super(MetadataValidatorV3, self).validate_nb(nb)

0 commit comments

Comments
 (0)