This repository has been archived by the owner on Sep 16, 2022. It is now read-only.
-
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.
* Reference data fixes
- Loading branch information
Toni
committed
Oct 29, 2021
1 parent
aa5ead8
commit a6d3b71
Showing
2 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
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,72 @@ | ||
# Generated by Django 3.1.12 on 2021-10-06 08:16 | ||
|
||
from django.db import migrations | ||
|
||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def replace_relation_type_labels(cr, language, old_label, new_label): | ||
logger.info(f"replacing relation type label ({language}): {old_label} with {new_label}") | ||
if cr.research_dataset.get("relation"): | ||
for item in cr.research_dataset["relation"]: | ||
if item.get("relation_type"): | ||
if item.get("relation_type").get("pref_label"): | ||
if item.get("relation_type").get("pref_label").get(language): | ||
if item["relation_type"]["pref_label"][language] == old_label: | ||
item["relation_type"]["pref_label"][language] = new_label | ||
logger.info("relation type label changed") | ||
|
||
datasets = [ | ||
"c1974353-a4f6-40c3-9c1c-a7ec99e28ac8", | ||
"7c12b39b-0bd4-4611-a764-85f328450e2b", | ||
"ddd9854f-eb6a-4a8b-8f0d-2d2b9c405436", | ||
"ef224b4b-6f0b-4776-ba33-6f8bd31855cc", | ||
"0cfa3182-48a8-4483-8ebd-2636509b8363", | ||
"0b6cfb0e-ea71-414f-abd3-88bb415b85fe", | ||
"fe5e67ba-fc36-449d-b83e-e1e286cc9dda", | ||
"254acb9a-32c7-45cd-9ac1-e52ef2d6174e", | ||
"69b0360e-2ac8-4008-ac8d-c47b8c76d47e", | ||
"087f9d18-5196-4e6e-83a0-dfe2d94c5aa6", | ||
"a3aa061f-1263-4fb5-887b-a465f4c3a912", | ||
"acf70d04-31f3-4e13-a422-666e39524b71", | ||
"5cf11735-8422-4113-beb0-997c11b7c797", | ||
"a5a04b82-6270-4e44-b357-a1344180bc1f" | ||
] | ||
|
||
def change_relation_type_labels(apps, schema_editor): | ||
CatalogRecord = apps.get_model('metax_api', 'CatalogRecord') | ||
for cr in CatalogRecord.objects.filter(identifier__in=datasets): | ||
try: | ||
logger.info(f"changing relation type labels for cr {cr.identifier}") | ||
replace_relation_type_labels(cr, "fi", "Liittyvä aineisto", "Liittyy") | ||
replace_relation_type_labels(cr, "und", "Liittyvä aineisto", "Liittyy") | ||
replace_relation_type_labels(cr, "en", "Related dataset", "Relation") | ||
cr.save() | ||
logger.info("cr save successful") | ||
except Exception as e: | ||
logger.error(e) | ||
|
||
def revert(apps, schema_editor): | ||
CatalogRecord = apps.get_model('metax_api', 'CatalogRecord') | ||
for cr in CatalogRecord.objects.filter(identifier__in=datasets): | ||
try: | ||
logger.info(f"changing relation type labels for cr {cr.identifier}") | ||
replace_relation_type_labels(cr, "fi", "Liittyy", "Liittyvä aineisto") | ||
replace_relation_type_labels(cr, "und", "Liittyy", "Liittyvä aineisto") | ||
replace_relation_type_labels(cr, "en", "Relation", "Related dataset") | ||
cr.save() | ||
logger.info("cr save successful") | ||
except Exception as e: | ||
logger.error(e) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('metax_api', '0039_auto_20210908_1151'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(change_relation_type_labels, revert), | ||
] |
2 changes: 1 addition & 1 deletion
2
src/metax_api/tasks/refdata/refdata_indexer/resources/local-refdata/relation_type.json
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