Skip to content

Commit e26a3fb

Browse files
rpenidoChrisChV
andauthored
fix: add course name on collection description on import (#37817)
Co-authored-by: Chris Chávez <xnpiochv@gmail.com>
1 parent a37528d commit e26a3fb

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

cms/djangoapps/modulestore_migrator/tasks.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,11 @@ def _populate_collection(user_id: int, migration: models.ModulestoreMigration) -
417417
log.warning("No target entities found to add to collection")
418418

419419

420-
def _create_collection(library_key: LibraryLocatorV2, title: str) -> Collection:
420+
def _create_collection(
421+
library_key: LibraryLocatorV2,
422+
title: str,
423+
course_name: str | None = None,
424+
) -> Collection:
421425
"""
422426
Creates a collection in the given library
423427
@@ -428,7 +432,10 @@ def _create_collection(library_key: LibraryLocatorV2, title: str) -> Collection:
428432
collection: Collection | None = None
429433
attempt = 0
430434
created_at = strftime_localized(datetime.now(timezone.utc), DEFAULT_DATE_TIME_FORMAT)
431-
description = f"{_('This collection contains content migrated from a legacy library on')}: {created_at}"
435+
if course_name:
436+
description = f"{_('This collection contains content imported from the course')} {course_name} on: {created_at}"
437+
else:
438+
description = f"{_('This collection contains content migrated from a legacy library on')}: {created_at}"
432439
while not collection:
433440
modified_key = key if attempt == 0 else key + '-' + str(attempt)
434441
try:
@@ -694,7 +701,11 @@ def bulk_migrate_from_modulestore(
694701
pass
695702
migration.target_collection = (
696703
existing_collection_to_use or
697-
_create_collection(library_key=target_library_locator, title=legacy_root_list[i].display_name)
704+
_create_collection(
705+
library_key=target_library_locator,
706+
title=legacy_root_list[i].display_name,
707+
course_name=legacy_root_list[i].display_name if source_data.source.key.is_course else None,
708+
)
698709
)
699710
_populate_collection(user_id, migration)
700711
models.ModulestoreMigration.objects.bulk_update(

cms/djangoapps/modulestore_migrator/tests/test_tasks.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,11 +1118,12 @@ def test_bulk_migrate_create_collections(self):
11181118
"""
11191119
source = ModulestoreSource.objects.create(key=self.legacy_library.location.library_key)
11201120
source_2 = ModulestoreSource.objects.create(key=self.legacy_library_2.location.library_key)
1121+
source_3 = ModulestoreSource.objects.create(key=self.course.id)
11211122

11221123
task = bulk_migrate_from_modulestore.apply_async(
11231124
kwargs={
11241125
"user_id": self.user.id,
1125-
"sources_pks": [source.id, source_2.id],
1126+
"sources_pks": [source.id, source_2.id, source_3.id],
11261127
"target_library_key": str(self.lib_key),
11271128
"target_collection_pks": [],
11281129
"create_collections": True,
@@ -1142,13 +1143,32 @@ def test_bulk_migrate_create_collections(self):
11421143
self.assertEqual(migration.composition_level, CompositionLevel.Unit.value)
11431144
self.assertEqual(migration.repeat_handling_strategy, RepeatHandlingStrategy.Skip.value)
11441145
self.assertEqual(migration.target_collection.title, self.legacy_library.display_name)
1146+
self.assertIn(
1147+
"This collection contains content migrated from a legacy library on:",
1148+
migration.target_collection.description,
1149+
)
11451150

11461151
migration_2 = ModulestoreMigration.objects.get(
11471152
source=source_2, target=self.learning_package
11481153
)
11491154
self.assertEqual(migration_2.composition_level, CompositionLevel.Unit.value)
11501155
self.assertEqual(migration_2.repeat_handling_strategy, RepeatHandlingStrategy.Skip.value)
11511156
self.assertEqual(migration_2.target_collection.title, self.legacy_library_2.display_name)
1157+
self.assertIn(
1158+
"This collection contains content migrated from a legacy library on:",
1159+
migration_2.target_collection.description,
1160+
)
1161+
1162+
migration_3 = ModulestoreMigration.objects.get(
1163+
source=source_3, target=self.learning_package
1164+
)
1165+
self.assertEqual(migration_3.composition_level, CompositionLevel.Unit.value)
1166+
self.assertEqual(migration_3.repeat_handling_strategy, RepeatHandlingStrategy.Skip.value)
1167+
self.assertEqual(migration_3.target_collection.title, self.course.display_name)
1168+
self.assertIn(
1169+
f"This collection contains content imported from the course {self.course.display_name} on:",
1170+
migration_3.target_collection.description,
1171+
)
11521172

11531173
@ddt.data(
11541174
RepeatHandlingStrategy.Skip,

0 commit comments

Comments
 (0)