From 462ea08baf5ad9895354b1895012dcf7f7de774b Mon Sep 17 00:00:00 2001 From: Johnathan Clementi Date: Thu, 17 Oct 2024 10:34:40 -0400 Subject: [PATCH 1/3] Guard against null values #42 --- arches_references/datatypes/datatypes.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/arches_references/datatypes/datatypes.py b/arches_references/datatypes/datatypes.py index 6111ba1..5571f18 100644 --- a/arches_references/datatypes/datatypes.py +++ b/arches_references/datatypes/datatypes.py @@ -104,13 +104,15 @@ def get_display_value(self, tile, node, **kwargs): labels = [] requested_language = kwargs.pop("language", None) current_language = requested_language or get_language() - for item in self.get_tile_data(tile)[str(node.nodeid)]: - for label in item["labels"]: - if ( - label["language_id"] == current_language - and label["valuetype_id"] == "prefLabel" - ): - labels.append(label.get("value", "")) + node_data = self.get_tile_data(tile)[str(node.nodeid)] + if node_data: + for item in node_data: + for label in item["labels"]: + if ( + label["language_id"] == current_language + and label["valuetype_id"] == "prefLabel" + ): + labels.append(label.get("value", "")) return ", ".join(labels) def collects_multiple_values(self): From d4d62b59a65e3f2a4a0532b62c55ffd61d2b4bc1 Mon Sep 17 00:00:00 2001 From: Johnathan Clementi Date: Thu, 17 Oct 2024 13:24:08 -0400 Subject: [PATCH 2/3] Return listid not listitemid #40 --- arches_references/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arches_references/models.py b/arches_references/models.py index be92282..b2dc0ce 100644 --- a/arches_references/models.py +++ b/arches_references/models.py @@ -215,7 +215,7 @@ def build_tile_value(self): tile_value = { "uri": self.uri or self.generate_uri(), "labels": [label.serialize() for label in self.list_item_values.labels()], - "listid": str(self.id), + "listid": str(self.list_id), } return tile_value From 09d965b2369531c1276481684f3ad573082af1ec Mon Sep 17 00:00:00 2001 From: Johnathan Clementi Date: Thu, 17 Oct 2024 13:25:41 -0400 Subject: [PATCH 3/3] Add tests for ref dt get_display_value method #42 --- tests/reference_datatype_tests.py | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/reference_datatype_tests.py b/tests/reference_datatype_tests.py index c1c5fa7..4233136 100644 --- a/tests/reference_datatype_tests.py +++ b/tests/reference_datatype_tests.py @@ -2,6 +2,7 @@ from arches.app.models.tile import Tile from arches_references.models import List, ListItem, ListItemValue from django.test import TestCase +from types import SimpleNamespace # these tests can be run from the command line via # python manage.py test tests.reference_datatype_tests --settings="tests.test_settings" @@ -123,3 +124,57 @@ def test_transform_value_for_tile(self): self.assertEqual( tile_value2[0]["labels"][0]["list_item_id"], expected_list_item_pk ) + + def test_get_display_value(self): + reference = DataTypeFactory().get_instance("reference") + mock_node = SimpleNamespace(nodeid="72048cb3-adbc-11e6-9ccf-14109fd34195") + mock_tile1 = Tile( + { + "resourceinstance_id": "40000000-0000-0000-0000-000000000000", + "parenttile_id": "", + "nodegroup_id": "72048cb3-adbc-11e6-9ccf-14109fd34195", + "tileid": "", + "data": { + "72048cb3-adbc-11e6-9ccf-14109fd34195": [ + { + "uri": "https://rdm.dev.fargeo.com/plugins/controlled-list-manager/item/9baf3cd5-33d4-4fbc-b1d1-a2d218732f1e", + "labels": [ + { + "id": "ea5c8af7-9933-4356-b537-0330c9da4690", + "value": "identifier", + "language_id": "en", + "list_item_id": "d8ba08f9-b265-4288-9412-857c77fe2581", + "valuetype_id": "prefLabel", + }, + { + "id": "ea5c8af7-9933-4356-b537-0330c9da4690", + "value": "identificateur", + "language_id": "fr", + "list_item_id": "d8ba08f9-b265-4288-9412-857c77fe2692", + "valuetype_id": "prefLabel", + }, + ], + "listid": "a8da34eb-575b-498c-ada7-161ee745fd16", + } + ] + }, + } + ) + self.assertEqual( + reference.get_display_value(mock_tile1, mock_node), "identifier" + ) + self.assertEqual( + reference.get_display_value(mock_tile1, mock_node, language="fr"), + "identificateur", + ) + + mock_tile2 = Tile( + { + "resourceinstance_id": "50000000-0000-0000-0000-000000000000", + "parenttile_id": "", + "nodegroup_id": "72048cb3-adbc-11e6-9ccf-14109fd34195", + "tileid": "", + "data": {"72048cb3-adbc-11e6-9ccf-14109fd34195": None}, + } + ) + self.assertEqual(reference.get_display_value(mock_tile2, mock_node), "")