Skip to content

Commit

Permalink
Update entities spec version
Browse files Browse the repository at this point in the history
  • Loading branch information
lognaturel committed Nov 9, 2023
1 parent 6b5b7ed commit 2c964a2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
5 changes: 3 additions & 2 deletions pyxform/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
17 changes: 13 additions & 4 deletions pyxform/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class Survey(Section):
"style": str,
"attribute": dict,
"namespaces": str,
constants.ENTITY_RELATED: str,
constants.ENTITY_FEATURES: list,
}
) # yapf: disable

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion pyxform/xls2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_entities_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 2c964a2

Please sign in to comment.