Skip to content

Commit

Permalink
Add migration to adjust mappings, make some minor changes to the dump…
Browse files Browse the repository at this point in the history
… to yaml util function (#1408)

dump_topic_to_yaml now will include the parent ID if there is one, and fixes a bug where dumping a single topic failed
  • Loading branch information
jkachel authored Aug 19, 2024
1 parent bca683f commit 4cac0c3
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""
Update the topics:
- Add mapping "Sustainability" to "Sustainable Business" for mitxpro, mitpe, see
- Add mapping "Economics & Finance" to "Finance & Accounting" for mitx
"""

from django.db import migrations

from learning_resources.utils import upsert_topic_data_string

forward_map_changes = """
---
topics:
- children: []
icon: RiLightbulbFlashLine
id: d18ae735-9eb0-42ec-982d-798590f78b68
mappings:
mitxpro:
- Sustainability
mitpe:
- Sustainability
see:
- Sustainability
name: Sustainable Business
parent: 58eeca97-031c-432f-89f5-5b6493bf0dd2
- children: []
icon: RiBriefcase3Line
id: b84810f6-b232-4443-9471-eff7823a5f93
mappings:
mitpe:
- Finance
ocw:
- Accounting
- Finance
see:
- Finance
xpro:
- Finance
mitx:
- Economics & Finance
name: Finance & Accounting
parent: 99ec5b40-e929-4ad9-bccf-7305ef6938b1
"""

reverse_map_changes = """
---
topics:
- children: []
icon: RiLightbulbFlashLine
id: d18ae735-9eb0-42ec-982d-798590f78b68
mappings: {}
name: Sustainable Business
parent: 58eeca97-031c-432f-89f5-5b6493bf0dd2
- children: []
icon: RiBriefcase3Line
id: b84810f6-b232-4443-9471-eff7823a5f93
mappings:
mitpe:
- Finance
ocw:
- Accounting
- Finance
see:
- Finance
xpro:
- Finance
name: Finance & Accounting
parent: 99ec5b40-e929-4ad9-bccf-7305ef6938b1
"""


def add_new_mapping(apps, schema_editor):
"""Upsert the forward_map_changes data above."""

upsert_topic_data_string(forward_map_changes)


def rollback_new_mapping(apps, schema_editor):
"""Upsert the reverse_map_changes data above."""

upsert_topic_data_string(reverse_map_changes)


class Migration(migrations.Migration):
dependencies = [
("data_fixtures", "0011_unit_page_copy_updates"),
]

operations = [migrations.RunPython(add_new_mapping, rollback_new_mapping)]
3 changes: 2 additions & 1 deletion learning_resources/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ def _dump_subtopic_to_yaml(topic: LearningResourceTopic):
"icon": topic.icon,
"mappings": {},
"children": [],
"parent": str(topic.parent.topic_uuid) if topic.parent else None,
}

for mapping in LearningResourceTopicMapping.objects.filter(topic=topic).all():
Expand All @@ -705,7 +706,7 @@ def _dump_subtopic_to_yaml(topic: LearningResourceTopic):
return yaml_ready_data

if topic_id:
parent_topics = LearningResourceTopic.objects.get(pk=topic_id)
parent_topics = [LearningResourceTopic.objects.get(pk=topic_id)]
else:
parent_topics = LearningResourceTopic.objects.filter(parent__isnull=True).all()

Expand Down

0 comments on commit 4cac0c3

Please sign in to comment.