def parse_exam_grade_adjustments(self, csv_reader):
"""
Parses all rows of grade adjustment info from a CSV and yields each ProctoredExamGrade object
with its associated grade adjustment row from the CSV
Args:
csv_reader (csv.DictReader): A DictReader instance
Returns:
tuple(ProctoredExamGrade, RowProps):
A tuple containing a ProctoredExamGrade and its associated parsed CSV row
"""
parsed_row_dict = {}
for row in csv_reader:
parsed_row = self.parse_and_validate_row(row)
parsed_row_dict[parsed_row.exam_grade_id] = parsed_row
exam_grade_query = ProctoredExamGrade.objects.filter(id__in=parsed_row_dict.keys())
if exam_grade_query.count() < len(parsed_row_dict):
bad_exam_grade_ids = set(parsed_row_dict.keys()) - set(exam_grade_query.values_list('id', flat=True))
raise ParsingError(
'Some exam grade IDs do not match any ProctoredExamGrade records: {}'.format(bad_exam_grade_ids)
)
for exam_grade in exam_grade_query.all():
yield exam_grade, parsed_row_dict[exam_grade.id]
adjust_exam_grades_from_csv.py 文件源码
python
阅读 31
收藏 0
点赞 0
评论 0
评论列表
文章目录