-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Manufacturing topic; update upserter to make adding child topics …
…easier (#1364) * Add Manufacturing topic; update upserter to make adding child topics easier * Updating the rollback to match on the topic's own uuid
- Loading branch information
Showing
4 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
data_fixtures/migrations/0008_topics_update_engineering_add_manufacturing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
Update the topics; add Manufacturing under Engineering | ||
This is intended to fix https://github.com/mitodl/hq/issues/5076 - no additional | ||
mappings since the topics for Principals of Manufacturing include "Manufacturing" | ||
so it should match on name directly. | ||
""" | ||
|
||
from django.db import migrations | ||
|
||
from channels.constants import ChannelType | ||
from learning_resources.utils import upsert_topic_data_string | ||
|
||
map_changes = """ | ||
--- | ||
topics: | ||
- icon: | ||
id: 4176e385-92c5-4e02-b3cc-4f34d9a4bf40 | ||
mappings: [] | ||
name: Manufacturing | ||
children: [] | ||
parent: 952604ab-ae23-45b3-a040-0e5f26fe42df | ||
""" | ||
|
||
|
||
def add_new_mapping(apps, schema_editor): | ||
"""Upsert the map_changes data above.""" | ||
|
||
upsert_topic_data_string(map_changes) | ||
|
||
|
||
def rollback_new_mapping(apps, schema_editor): | ||
"""Remove the Manufacturing topic.""" | ||
|
||
LearningResourceTopic = apps.get_model( | ||
"learning_resources", "LearningResourceTopic" | ||
) | ||
Channel = apps.get_model("channels", "Channel") | ||
|
||
topic = LearningResourceTopic.objects.filter( | ||
topic_uuid="4176e385-92c5-4e02-b3cc-4f34d9a4bf40", | ||
).get() | ||
|
||
Channel.objects.filter( | ||
channel_type=ChannelType.topic.name, | ||
topic_detail__topic=topic, | ||
).all().delete() | ||
|
||
topic.delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
( | ||
"data_fixtures", | ||
"0007_topic_mappings_edx_add_programming_coding_to_computer_science", | ||
), | ||
] | ||
|
||
operations = [migrations.RunPython(add_new_mapping, rollback_new_mapping)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters