diff --git a/openedx/core/djangoapps/content_tagging/api.py b/openedx/core/djangoapps/content_tagging/api.py index e28541ea2121..f7bf95c88ab1 100644 --- a/openedx/core/djangoapps/content_tagging/api.py +++ b/openedx/core/djangoapps/content_tagging/api.py @@ -230,10 +230,17 @@ def generate_csv_rows(object_id, buffer) -> Iterator[str]: # Iterate over the blocks and yield the rows for item, level in iterate_with_level(tagged_content): + block_key = get_content_key_from_string(item.block_id) + block_id = None + if isinstance(block_key, CourseKey): + block_id = block_key + else: + block_id = block_key.block_id + block_data = { "name": level * " " + item.display_name, "type": item.category, - "id": item.block_id, + "id": block_id, } # Add the tags for each taxonomy diff --git a/openedx/core/djangoapps/content_tagging/tests/test_api.py b/openedx/core/djangoapps/content_tagging/tests/test_api.py index 794555092b61..2debbbbe0a1f 100644 --- a/openedx/core/djangoapps/content_tagging/tests/test_api.py +++ b/openedx/core/djangoapps/content_tagging/tests/test_api.py @@ -284,19 +284,14 @@ class TestExportTags(TaggedCourseMixin): def setUp(self): super().setUp() self.expected_csv = ( - '"Name","Type","ID","1-taxonomy-1","2-taxonomy-2"\r\n' - '"Test Course","course","course-v1:orgA+test_course+test_run","Tag 1.1",""\r\n' - '" test sequential","sequential","block-v1:orgA+test_course+test_run+type@sequential+block@test_' - 'sequential","Tag 1.1, Tag 1.2","Tag 2.1"\r\n' - '" test vertical1","vertical","block-v1:orgA+test_course+test_run+type@vertical+block@test_' - 'vertical1","","Tag 2.2"\r\n' - '" test vertical2","vertical","block-v1:orgA+test_course+test_run+type@vertical+block@test_' - 'vertical2","",""\r\n' - '" test html","html","block-v1:orgA+test_course+test_run+type@html+block@test_html","","Tag 2.1"\r\n' - '" untagged sequential","sequential","block-v1:orgA+test_course+test_run+type@sequential+block@untagged_' - 'sequential","",""\r\n' - '" untagged vertical","vertical","block-v1:orgA+test_course+test_run+type@vertical+block@untagged_' - 'vertical","",""\r\n' + '"Name","Type","ID","1-taxonomy-1","2-taxonomy-2"\n' + '"Test Course","course","course-v1:orgA+test_course+test_run","Tag 1.1",""\n' + '" test sequential","sequential","test_sequential","Tag 1.1, Tag 1.2","Tag 2.1"\n' + '" test vertical1","vertical","test_vertical1","","Tag 2.2"\n' + '" test vertical2","vertical","test_vertical2","",""\n' + '" test html","html","test_html","","Tag 2.1"\n' + '" untagged sequential","sequential","untagged_sequential","",""\n' + '" untagged vertical","vertical","untagged_vertical","",""\n' ) def test_generate_csv_rows(self) -> None: @@ -304,7 +299,9 @@ def test_generate_csv_rows(self) -> None: list(api.generate_csv_rows(str(self.course.id), buffer)) buffer.seek(0) csv_content = buffer.getvalue() - assert csv_content == self.expected_csv + cleaned_content = csv_content.replace('\r\n', '\n') + + assert cleaned_content == self.expected_csv def test_export_tags_in_csv_file(self) -> None: file_dir_name = tempfile.mkdtemp() @@ -320,7 +317,4 @@ def test_export_tags_in_csv_file(self) -> None: with open(file_path, 'r') as f: content = f.read() - cleaned_content = content.replace('\r\n', '\n') - cleaned_expected_csv = self.expected_csv.replace('\r\n', '\n') - - self.assertEqual(cleaned_content, cleaned_expected_csv) + self.assertEqual(content, self.expected_csv) diff --git a/xmodule/modulestore/xml_exporter.py b/xmodule/modulestore/xml_exporter.py index 29141936732d..a48c84ac20c1 100644 --- a/xmodule/modulestore/xml_exporter.py +++ b/xmodule/modulestore/xml_exporter.py @@ -291,6 +291,7 @@ def process_extra(self, root, courselike, root_courselike_dir, xml_centric_cours tags_count = get_object_tag_counts(block_id_pattern) + # TODO Verify with course, sections and subsections if tags_count: export_tags_in_csv_file(courselike_key_str, export_fs, 'tags.csv')