Commit 428824c3 by David Ormsbee

Small refactoring and adding comments in response to PR comments.

parent 9a184f06
......@@ -352,6 +352,8 @@ class Assessment(models.Model):
if not assessments:
return []
# Generate a cache key that represents all the assessments we're being
# asked to grab scores from (comma separated list of assessment IDs)
cache_key = "assessments.scores_by_criterion.{}".format(
",".join(str(assessment.id) for assessment in assessments)
)
......@@ -394,6 +396,14 @@ class AssessmentPart(models.Model):
def points_possible(self):
return self.option.criterion.points_possible
@classmethod
def add_to_assessment(cls, assessment, option_ids):
"""Creates AssessmentParts and adds them to `assessment`."""
cls.objects.bulk_create([
cls(assessment=assessment, option_id=option_id)
for option_id in option_ids
])
class AssessmentFeedback(models.Model):
"""A response to a submission's feedback, judging accuracy or helpfulness."""
......
......@@ -199,10 +199,7 @@ def create_assessment(
# We do this to do a run around django-rest-framework serializer
# validation, which would otherwise require two DB queries per
# option to do validation. We already validated these options above.
AssessmentPart.objects.bulk_create([
AssessmentPart(assessment=assessment, option_id=option_id)
for option_id in option_ids
])
AssessmentPart.add_to_assessment(assessment, option_ids)
student_item = submission.student_item
student_item_dict = StudentItemSerializer(student_item).data
......
......@@ -94,10 +94,7 @@ def create_assessment(submission_uuid, user_id, options_selected, rubric_dict, s
# We do this to do a run around django-rest-framework serializer
# validation, which would otherwise require two DB queries per
# option to do validation. We already validated these options above.
AssessmentPart.objects.bulk_create([
AssessmentPart(assessment=assessment, option_id=option_id)
for option_id in option_ids
])
AssessmentPart.add_to_assessment(assessment, option_ids)
# Return the serialized assessment
return full_assessment_dict(assessment)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment