Skip to content

Commit

Permalink
Apply requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
noliveleger committed Nov 26, 2024
1 parent 214b1d0 commit 8bda894
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
2 changes: 1 addition & 1 deletion kobo/apps/openrosa/apps/logger/models/xform.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def url(self):
)

@property
def xforms_root_node_name(self):
def xform_root_node_name(self):
"""
Retrieves the name of the XML tag representing the root node of the "survey"
in the XForm XML structure.
Expand Down
15 changes: 3 additions & 12 deletions kobo/apps/openrosa/apps/viewer/models/data_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ def set_uuid_in_xml(self):
"""
Add bind to automatically set UUID node in XML.
"""
# XForm always contains a non-empty/null JSON
# `name` and `id_string` attributes should always be present
form_json = json.loads(self.json)
root_node = form_json['name']
id_string = form_json['id_string']
root_node = self.xform_root_node_name

doc = clean_and_parse_xml(self.xml)
model_nodes = doc.getElementsByTagName("model")
Expand All @@ -101,15 +97,10 @@ def set_uuid_in_xml(self):
node
for node in instance_node.childNodes
if node.nodeType == Node.ELEMENT_NODE
and (
node.tagName == root_node
and node.attributes.get('id').value == id_string
)
and node.tagName == root_node
]
if len(survey_nodes) != 1:
raise Exception(
f'Multiple survey nodes `{root_node}` with the id `{id_string}`'
)
raise Exception(f'Multiple survey nodes `{root_node}`')

survey_node = survey_nodes[0]
formhub_nodes = [
Expand Down
2 changes: 1 addition & 1 deletion kpi/models/asset_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def generate_xml_from_source(self,
return xml, details

@property
def xforms_root_node_name(self):
def xform_root_node_name(self):
"""
Retrieves the name of the XML tag representing the root node of the "survey"
in the XForm XML structure.
Expand Down
6 changes: 3 additions & 3 deletions kpi/utils/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ def __init__(self, obj: Union['kpi.AssetSnapshot', 'logger.XForm']):
self._object = obj
self._unique_id = obj.asset.uid

# Avoid initializing `_root_tag_name` immediately to prevent extra
# database queries. It will be set only when it is actually needed.
# Avoid accessing the `xform_root_node_name` property immediately to prevent
# extra database queries. It will be set only when it is actually needed.
self._root_tag_name = None
self._add_disclaimer()

Expand All @@ -394,7 +394,7 @@ def _add_disclaimer(self):
translated, disclaimers_dict, default_language_code = value

self._root_node = minidom.parseString(self._object.xml)
self._root_tag_name = self._object.xforms_root_node_name
self._root_tag_name = self._object.xform_root_node_name

if translated:
self._add_translation_nodes(disclaimers_dict, default_language_code)
Expand Down

0 comments on commit 8bda894

Please sign in to comment.