From d7b46a412ad27f43f072d27f2487583fa8473145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Thu, 22 Feb 2024 10:50:54 -0300 Subject: [PATCH 1/3] feat: add get_taxonomy_by_export_id method --- openedx_tagging/core/tagging/api.py | 8 ++++++++ openedx_tagging/core/tagging/models/base.py | 2 +- tests/openedx_tagging/core/tagging/test_api.py | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/openedx_tagging/core/tagging/api.py b/openedx_tagging/core/tagging/api.py index c416f6f09..d8f2a9786 100644 --- a/openedx_tagging/core/tagging/api.py +++ b/openedx_tagging/core/tagging/api.py @@ -67,6 +67,14 @@ def get_taxonomy(taxonomy_id: int) -> Taxonomy | None: return taxonomy.cast() if taxonomy else None +def get_taxonomy_by_export_id(taxonomy_export_id: str) -> Taxonomy | None: + """ + Returns a Taxonomy cast to the appropriate subclass which has the given export ID. + """ + taxonomy = Taxonomy.objects.filter(export_id=taxonomy_export_id).first() + return taxonomy.cast() if taxonomy else None + + def get_taxonomies(enabled=True) -> QuerySet[Taxonomy]: """ Returns a queryset containing the enabled taxonomies, sorted by name. diff --git a/openedx_tagging/core/tagging/models/base.py b/openedx_tagging/core/tagging/models/base.py index 0235d7b31..8b82c751d 100644 --- a/openedx_tagging/core/tagging/models/base.py +++ b/openedx_tagging/core/tagging/models/base.py @@ -241,7 +241,7 @@ class Taxonomy(models.Model): "Indicates whether this taxonomy should be visible to object authors." ), ) - # External ID that should only be used on import/export. + # Export ID that should only be used on import/export. # NOT use for any other purposes, you can use the numeric ID of the model instead; # this id is editable. export_id = models.CharField( diff --git a/tests/openedx_tagging/core/tagging/test_api.py b/tests/openedx_tagging/core/tagging/test_api.py index 972159235..51fb3c2f6 100644 --- a/tests/openedx_tagging/core/tagging/test_api.py +++ b/tests/openedx_tagging/core/tagging/test_api.py @@ -88,6 +88,13 @@ def test_get_taxonomy(self) -> None: no_tax = tagging_api.get_taxonomy(200) assert no_tax is None + def test_get_taxonomy_by_export_id(self) -> None: + tax1 = tagging_api.get_taxonomy_by_export_id("life_on_earth") + assert tax1 == self.taxonomy + + no_tax = tagging_api.get_taxonomy_by_export_id("nope") + assert no_tax is None + def test_get_taxonomies(self) -> None: tax1 = tagging_api.create_taxonomy("Enabled") tax2 = tagging_api.create_taxonomy("Disabled", enabled=False) From 0b9a9d770954ce4615b1f78910860eefe09d100b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Wed, 28 Feb 2024 11:08:17 -0300 Subject: [PATCH 2/3] chore: bump version --- openedx_learning/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openedx_learning/__init__.py b/openedx_learning/__init__.py index a01c57cd0..e718aa232 100644 --- a/openedx_learning/__init__.py +++ b/openedx_learning/__init__.py @@ -1,4 +1,4 @@ """ Open edX Learning ("Learning Core"). """ -__version__ = "0.6.2" +__version__ = "0.6.3" From ac7bf0e66ce4532eb88f424258d2fd338fa06925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Wed, 28 Feb 2024 11:09:00 -0300 Subject: [PATCH 3/3] fix: revert comment change --- openedx_tagging/core/tagging/models/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openedx_tagging/core/tagging/models/base.py b/openedx_tagging/core/tagging/models/base.py index 8b82c751d..0235d7b31 100644 --- a/openedx_tagging/core/tagging/models/base.py +++ b/openedx_tagging/core/tagging/models/base.py @@ -241,7 +241,7 @@ class Taxonomy(models.Model): "Indicates whether this taxonomy should be visible to object authors." ), ) - # Export ID that should only be used on import/export. + # External ID that should only be used on import/export. # NOT use for any other purposes, you can use the numeric ID of the model instead; # this id is editable. export_id = models.CharField(