From 2c964a21680461e7259905c973c90453b518553d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9l=C3=A8ne=20Martin?= Date: Wed, 8 Nov 2023 16:56:41 -0800 Subject: [PATCH] Update entities spec version --- pyxform/constants.py | 5 +++-- pyxform/survey.py | 17 +++++++++++++---- pyxform/xls2json.py | 6 +++++- tests/test_entities_update.py | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pyxform/constants.py b/pyxform/constants.py index 7ee3befc..73c0ed65 100644 --- a/pyxform/constants.py +++ b/pyxform/constants.py @@ -110,8 +110,9 @@ CURRENT_XFORMS_VERSION = "1.0.0" # The ODK entities spec version that generated forms comply to -CURRENT_ENTITIES_VERSION = "2022.1.0" -ENTITY_RELATED = "entity_related" +ENTITIES_CREATE_VERSION = "2022.1.0" +CURRENT_ENTITIES_VERSION = "2023.1.0" +ENTITY_FEATURES = "entity_features" ENTITIES_RESERVED_PREFIX = "__" DEPRECATED_DEVICE_ID_METADATA_FIELDS = ["subscriberid", "simserial"] diff --git a/pyxform/survey.py b/pyxform/survey.py index e708ad67..242fbceb 100644 --- a/pyxform/survey.py +++ b/pyxform/survey.py @@ -185,7 +185,7 @@ class Survey(Section): "style": str, "attribute": dict, "namespaces": str, - constants.ENTITY_RELATED: str, + constants.ENTITY_FEATURES: list, } ) # yapf: disable @@ -218,7 +218,7 @@ def _validate_uniqueness_of_section_names(self): def get_nsmap(self): """Add additional namespaces""" namespaces = getattr(self, constants.NAMESPACES, "") - if getattr(self, constants.ENTITY_RELATED, "false") == "true": + if len(getattr(self, constants.ENTITY_FEATURES, [])) > 0: namespaces += " entities=http://www.opendatakit.org/xforms/entities" if namespaces and isinstance(namespaces, str): @@ -564,8 +564,17 @@ def xml_model(self): self._add_empty_translations() model_kwargs = {"odk:xforms-version": constants.CURRENT_XFORMS_VERSION} - if getattr(self, constants.ENTITY_RELATED, "false") == "true": - model_kwargs["entities:entities-version"] = constants.CURRENT_ENTITIES_VERSION + + entity_features = getattr(self, constants.ENTITY_FEATURES, []) + if len(entity_features) > 0: + if "update" in entity_features: + model_kwargs[ + "entities:entities-version" + ] = constants.CURRENT_ENTITIES_VERSION + else: + model_kwargs[ + "entities:entities-version" + ] = constants.ENTITIES_CREATE_VERSION model_children = [] if self._translations: diff --git a/pyxform/xls2json.py b/pyxform/xls2json.py index dbcb5d14..e1fe6cae 100644 --- a/pyxform/xls2json.py +++ b/pyxform/xls2json.py @@ -1482,7 +1482,11 @@ def workbook_to_json( ) if len(entity_declaration) > 0: - json_dict[constants.ENTITY_RELATED] = "true" + json_dict[constants.ENTITY_FEATURES] = ["create"] + + if entity_declaration.get("parameters", {}).get("entity_id", None): + json_dict[constants.ENTITY_FEATURES].append("update") + meta_children.append(entity_declaration) if len(meta_children) > 0: diff --git a/tests/test_entities_update.py b/tests/test_entities_update.py index 4f58a147..4486f163 100644 --- a/tests/test_entities_update.py +++ b/tests/test_entities_update.py @@ -24,7 +24,7 @@ def test_basic_entity_update_building_blocks(self): '/h:html/h:head/x:model/x:bind[@nodeset = "/data/meta/entity/@id" and @type = "string" and @readonly = "true()" and @calculate = " /data/id "]', '/h:html/h:head/x:model/x:instance/x:data/x:meta/x:entity[@baseVersion = ""]', '/h:html/h:head/x:model/x:bind[@nodeset = "/data/meta/entity/@baseVersion" and @type = "string" and @readonly = "true()" and @calculate = "instance(\'trees\')/root/item[name= /data/id ]/__version"]', - '/h:html/h:head/x:model[@entities:entities-version = "2022.1.0"]', + '/h:html/h:head/x:model[@entities:entities-version = "2023.1.0"]', ], xml__xpath_count=[ ("/h:html/h:head/x:model/x:instance/x:data/x:meta/x:entity/x:label", 0),