Commit a10bcb31 by Sofiya Semenova

?

parent f76d9925
...@@ -213,8 +213,9 @@ class CourseGradeBase(object): ...@@ -213,8 +213,9 @@ class CourseGradeBase(object):
""" """
Returns a list of subsection grades for the given chapter. Returns a list of subsection grades for the given chapter.
""" """
enrollment_track_changed = False if self.enrollment_track_changed is None else self.enrollment_track_changed
return [ return [
self._get_subsection_grade(course_structure[subsection_key]) self._get_subsection_grade(course_structure[subsection_key], enrollment_track_changed)
for subsection_key in _uniqueify_and_keep_order(course_structure.get_children(chapter_key)) for subsection_key in _uniqueify_and_keep_order(course_structure.get_children(chapter_key))
] ]
...@@ -276,9 +277,9 @@ class CourseGrade(CourseGradeBase): ...@@ -276,9 +277,9 @@ class CourseGrade(CourseGradeBase):
return True return True
return False return False
def _get_subsection_grade(self, subsection): def _get_subsection_grade(self, subsection, enrollment_track_changed):
if self.force_update_subsections: if self.force_update_subsections:
return self._subsection_grade_factory.update(subsection, self.persist_after_track_change) return self._subsection_grade_factory.update(subsection, enrollment_track_changed)
else: else:
# Pass read_only here so the subsection grades can be persisted in bulk at the end. # Pass read_only here so the subsection grades can be persisted in bulk at the end.
return self._subsection_grade_factory.create(subsection, read_only=True) return self._subsection_grade_factory.create(subsection, read_only=True)
......
...@@ -76,7 +76,7 @@ class CourseGradeFactory(object): ...@@ -76,7 +76,7 @@ class CourseGradeFactory(object):
user, user,
course_data, course_data,
force_update_subsections=force_update_subsections, force_update_subsections=force_update_subsections,
persist_after_track_change=enrollment_track_changed enrollment_track_changed=enrollment_track_changed
) )
def iter( def iter(
...@@ -163,7 +163,7 @@ class CourseGradeFactory(object): ...@@ -163,7 +163,7 @@ class CourseGradeFactory(object):
) )
@staticmethod @staticmethod
def _update(user, course_data, force_update_subsections=False, persist_after_track_change=False): def _update(user, course_data, force_update_subsections=False, enrollment_track_changed=False):
""" """
Computes, saves, and returns a CourseGrade object for the Computes, saves, and returns a CourseGrade object for the
given user and course. given user and course.
...@@ -179,11 +179,11 @@ class CourseGradeFactory(object): ...@@ -179,11 +179,11 @@ class CourseGradeFactory(object):
user, user,
course_data, course_data,
force_update_subsections=force_update_subsections, force_update_subsections=force_update_subsections,
persist_after_track_change=persist_after_track_change enrollment_track_changed=enrollment_track_changed
) )
course_grade = course_grade.update() course_grade = course_grade.update()
should_persist = should_persist and (course_grade.attempted or persist_after_track_change) should_persist = should_persist and course_grade.attempted
if should_persist: if should_persist:
course_grade._subsection_grade_factory.bulk_create_unsaved() course_grade._subsection_grade_factory.bulk_create_unsaved()
PersistentCourseGrade.update_or_create( PersistentCourseGrade.update_or_create(
......
...@@ -230,11 +230,11 @@ class CreateSubsectionGrade(NonZeroSubsectionGrade): ...@@ -230,11 +230,11 @@ class CreateSubsectionGrade(NonZeroSubsectionGrade):
super(CreateSubsectionGrade, self).__init__(subsection, all_total, graded_total) super(CreateSubsectionGrade, self).__init__(subsection, all_total, graded_total)
def update_or_create_model(self, student, score_deleted=False, persist_after_track_change=False): def update_or_create_model(self, student, score_deleted=False, enrollment_track_changed=False):
""" """
Saves or updates the subsection grade in a persisted model. Saves or updates the subsection grade in a persisted model.
""" """
if self._should_persist_per_attempted(score_deleted, persist_after_track_change=False): if self._should_persist_per_attempted(score_deleted, enrollment_track_changed):
return PersistentSubsectionGrade.update_or_create_grade(**self._persisted_model_params(student)) return PersistentSubsectionGrade.update_or_create_grade(**self._persisted_model_params(student))
@classmethod @classmethod
...@@ -250,7 +250,7 @@ class CreateSubsectionGrade(NonZeroSubsectionGrade): ...@@ -250,7 +250,7 @@ class CreateSubsectionGrade(NonZeroSubsectionGrade):
] ]
return PersistentSubsectionGrade.bulk_create_grades(params, student.id, course_key) return PersistentSubsectionGrade.bulk_create_grades(params, student.id, course_key)
def _should_persist_per_attempted(self, score_deleted=False, persist_after_track_change=False): def _should_persist_per_attempted(self, score_deleted=False, enrollment_track_changed=False):
""" """
Returns whether the SubsectionGrade's model should be Returns whether the SubsectionGrade's model should be
persisted based on settings and attempted status. persisted based on settings and attempted status.
...@@ -263,7 +263,7 @@ class CreateSubsectionGrade(NonZeroSubsectionGrade): ...@@ -263,7 +263,7 @@ class CreateSubsectionGrade(NonZeroSubsectionGrade):
return ( return (
self.all_total.first_attempted is not None or self.all_total.first_attempted is not None or
score_deleted or score_deleted or
persist_after_track_change enrollment_track_changed
) )
def _persisted_model_params(self, student): def _persisted_model_params(self, student):
......
...@@ -63,7 +63,7 @@ class SubsectionGradeFactory(object): ...@@ -63,7 +63,7 @@ class SubsectionGradeFactory(object):
) )
self._unsaved_subsection_grades.clear() self._unsaved_subsection_grades.clear()
def update(self, subsection, only_if_higher=None, score_deleted=False, persist_after_track_change=False): def update(self, subsection, only_if_higher=None, score_deleted=False, enrollment_track_changed=False):
""" """
Updates the SubsectionGrade object for the student and subsection. Updates the SubsectionGrade object for the student and subsection.
""" """
...@@ -92,7 +92,7 @@ class SubsectionGradeFactory(object): ...@@ -92,7 +92,7 @@ class SubsectionGradeFactory(object):
grade_model = calculated_grade.update_or_create_model( grade_model = calculated_grade.update_or_create_model(
self.student, self.student,
score_deleted, score_deleted,
persist_after_track_change) enrollment_track_changed)
self._update_saved_subsection_grade(subsection.location, grade_model) self._update_saved_subsection_grade(subsection.location, grade_model)
return calculated_grade return calculated_grade
......
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