Skip to content

Commit

Permalink
Merge pull request #11507 from bjester/single-user-lesson
Browse files Browse the repository at this point in the history
Fix collection on lessons assigned to subsets of users
  • Loading branch information
bjester authored Nov 9, 2023
2 parents 4020fb2 + 1141b1f commit bb1a410
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
11 changes: 7 additions & 4 deletions kolibri/core/lessons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,15 @@ def calculate_partition(self):
@classmethod
def serialize_lesson(cls, lesson):
serialized = lesson.serialize()
for key in ["is_active", "created_by_id", "date_created", "collection_id"]:
for key in ["is_active", "created_by_id", "date_created"]:
serialized.pop(key, None)
return serialized

@classmethod
def deserialize_lesson(cls, serialized_lesson):
lesson = Lesson.deserialize(serialized_lesson)
def deserialize_lesson(self):
lesson = Lesson.deserialize(self.serialized_lesson)
lesson.is_active = True
# a lesson's collection should be the classroom, but previously the serialized lesson
# did not include the collection_id, so we need to set it here to ensure it isn't null
if not lesson.collection_id:
lesson.collection_id = self.collection_id
return lesson
10 changes: 2 additions & 8 deletions kolibri/core/lessons/single_user_assignment_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ def update_assignments_from_individual_syncable_lessons(user_id):
# create new assignments and lessons for all new syncable lesson objects
for syncablelesson in to_create:

lesson = IndividualSyncableLesson.deserialize_lesson(
syncablelesson.serialized_lesson
)
lesson.collection_id = syncablelesson.collection_id
lesson = syncablelesson.deserialize_lesson()
# shouldn't need to set this field (as it's nullable, according to the model definition, but got errors)
lesson.created_by_id = user_id
lesson.save(update_dirty_bit_to=False)
Expand Down Expand Up @@ -115,10 +112,7 @@ def update_assignments_from_individual_syncable_lessons(user_id):
syncablelesson.serialized_lesson != updated_serialization
or syncablelesson.collection_id != assignment.collection_id
):
lesson = IndividualSyncableLesson.deserialize_lesson(
syncablelesson.serialized_lesson
)
lesson.collection_id = syncablelesson.collection_id
lesson = syncablelesson.deserialize_lesson()
lesson.created_by_id = user_id
lesson.save(update_dirty_bit_to=False)
assignment.lesson = lesson
Expand Down

0 comments on commit bb1a410

Please sign in to comment.