diff --git a/lms/djangoapps/courseware/grades.py b/lms/djangoapps/courseware/grades.py index c913f2d5e5..6a0fedfc4b 100644 --- a/lms/djangoapps/courseware/grades.py +++ b/lms/djangoapps/courseware/grades.py @@ -76,7 +76,7 @@ def grade(student, request, course, student_module_cache=None): # TODO: We may be able to speed this up by only getting a list of children IDs from section_module # Then, we may not need to instatiate any problems if they are already in the database for module in yield_module_descendents(section_module): - (correct, total) = get_score(student, module, student_module_cache) + (correct, total) = get_score(course.id, student, module, student_module_cache) if correct is None and total is None: continue @@ -171,7 +171,9 @@ def progress_summary(student, course, grader, student_module_cache): graded = s.metadata.get('graded', False) scores = [] for module in yield_module_descendents(s): - (correct, total) = get_score(student, module, student_module_cache) + # course is a module, not a descriptor... + course_id = course.descriptor.id + (correct, total) = get_score(course_id, student, module, student_module_cache) if correct is None and total is None: continue @@ -200,7 +202,7 @@ def progress_summary(student, course, grader, student_module_cache): return chapters -def get_score(user, problem, student_module_cache): +def get_score(course_id, user, problem, student_module_cache): """ Return the score for a user on a problem, as a tuple (correct, total). @@ -215,7 +217,7 @@ def get_score(user, problem, student_module_cache): correct = 0.0 # If the ID is not in the cache, add the item - instance_module = get_instance_module(user, problem, student_module_cache) + instance_module = get_instance_module(course_id, user, problem, student_module_cache) # instance_module = student_module_cache.lookup(problem.category, problem.id) # if instance_module is None: # instance_module = StudentModule(module_type=problem.category, diff --git a/lms/djangoapps/courseware/migrations/0003_done_grade_cache.py b/lms/djangoapps/courseware/migrations/0003_done_grade_cache.py index 96b320bc8f..f29f931079 100644 --- a/lms/djangoapps/courseware/migrations/0003_done_grade_cache.py +++ b/lms/djangoapps/courseware/migrations/0003_done_grade_cache.py @@ -9,6 +9,8 @@ class Migration(SchemaMigration): def forwards(self, orm): + # NOTE (vshnayder): This constraint has the wrong field order, so it doesn't actually + # do anything. Migration 0004 actually removes this index. # Removing unique constraint on 'StudentModule', fields ['module_id', 'module_type', 'student'] db.delete_unique('courseware_studentmodule', ['module_id', 'module_type', 'student_id']) diff --git a/lms/djangoapps/courseware/migrations/0004_add_field_studentmodule_course_id.py b/lms/djangoapps/courseware/migrations/0004_add_field_studentmodule_course_id.py index 71154e17fd..7433a48b0b 100644 --- a/lms/djangoapps/courseware/migrations/0004_add_field_studentmodule_course_id.py +++ b/lms/djangoapps/courseware/migrations/0004_add_field_studentmodule_course_id.py @@ -16,13 +16,17 @@ class Migration(SchemaMigration): # Removing unique constraint on 'StudentModule', fields ['module_id', 'student'] db.delete_unique('courseware_studentmodule', ['module_id', 'student_id']) + # NOTE: manually remove this constaint (from 0001)--0003 tries, but fails. + # Removing unique constraint on 'StudentModule', fields ['module_id', 'module_type', 'student'] + db.delete_unique('courseware_studentmodule', ['student_id', 'module_id', 'module_type']) + # Adding unique constraint on 'StudentModule', fields ['course_id', 'module_state_key', 'student'] - db.create_unique('courseware_studentmodule', ['course_id', 'module_id', 'student_id']) + db.create_unique('courseware_studentmodule', ['student_id', 'module_id', 'course_id']) def backwards(self, orm): - # Removing unique constraint on 'StudentModule', fields ['course_id', 'module_state_key', 'student'] - db.delete_unique('courseware_studentmodule', ['course_id', 'module_id', 'student_id']) + # Removing unique constraint on 'StudentModule', fields ['studnet_id', 'module_state_key', 'course_id'] + db.delete_unique('courseware_studentmodule', ['student_id', 'module_id', 'course_id']) # Deleting field 'StudentModule.course_id' db.delete_column('courseware_studentmodule', 'course_id') @@ -30,6 +34,9 @@ class Migration(SchemaMigration): # Adding unique constraint on 'StudentModule', fields ['module_id', 'student'] db.create_unique('courseware_studentmodule', ['module_id', 'student_id']) + # Adding unique constraint on 'StudentModule', fields ['module_id', 'module_type', 'student'] + db.create_unique('courseware_studentmodule', ['student_id', 'module_id', 'module_type']) + models = { 'auth.group': { diff --git a/lms/djangoapps/courseware/models.py b/lms/djangoapps/courseware/models.py index 4fdedfcdd3..393cb0918b 100644 --- a/lms/djangoapps/courseware/models.py +++ b/lms/djangoapps/courseware/models.py @@ -43,7 +43,7 @@ class StudentModule(models.Model): course_id = models.CharField(max_length=255, db_index=True) class Meta: - unique_together = (('course_id', 'student', 'module_state_key'),) + unique_together = (('student', 'module_state_key', 'course_id'),) ## Internal state of the object state = models.TextField(null=True, blank=True)