Skip to content

Commit bd4cefd

Browse files
lindsay-stevenslognaturel
authored andcommitted
add: odk:client-editable submission config
- similar to auto_send / auto_delete, but requested to allow more true/false-y values than just 'true' accepted for those.
1 parent b0ae3c6 commit bd4cefd

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed

pyxform/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
SUBMISSION_URL = "submission_url"
3535
AUTO_SEND = "auto_send"
3636
AUTO_DELETE = "auto_delete"
37+
CLIENT_EDITABLE = "client_editable"
3738
DEFAULT_FORM_NAME = "data"
3839
DEFAULT_LANGUAGE_KEY = "default_language"
3940
DEFAULT_LANGUAGE_VALUE = "default"

pyxform/survey.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def recursive_dict():
215215
"title",
216216
"version",
217217
constants.ALLOW_CHOICE_DUPLICATES,
218+
constants.CLIENT_EDITABLE,
218219
constants.COMPACT_DELIMITER,
219220
constants.COMPACT_PREFIX,
220221
constants.ENTITY_FEATURES,
@@ -262,6 +263,7 @@ def __init__(self, **kwargs):
262263
self.auto_delete: str | None = None
263264
self.auto_send: str | None = None
264265
self.clean_text_values: bool = False
266+
self.client_editable: bool = False
265267
self.instance_xmlns: str | None = None
266268
self.namespaces: str | None = None
267269
self.omit_instanceID: bool = False
@@ -727,7 +729,15 @@ def xml_model(self):
727729
node("instance", self.xml_instance()),
728730
)
729731

730-
if self.submission_url or self.public_key or self.auto_send or self.auto_delete:
732+
if any(
733+
(
734+
self.submission_url,
735+
self.public_key,
736+
self.auto_send,
737+
self.auto_delete,
738+
self.client_editable,
739+
)
740+
):
731741
submission_attrs = {}
732742
if self.submission_url:
733743
submission_attrs["action"] = self.submission_url
@@ -738,6 +748,8 @@ def xml_model(self):
738748
submission_attrs["orx:auto-send"] = self.auto_send
739749
if self.auto_delete:
740750
submission_attrs["orx:auto-delete"] = self.auto_delete
751+
if self.client_editable:
752+
submission_attrs["odk:client-editable"] = "true"
741753
submission_node = node("submission", **submission_attrs)
742754
model_children.insert(0, submission_node)
743755

pyxform/xls2json.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,10 @@ def workbook_to_json(
481481
settings["add_none_option"] = aliases.yes_no.get(
482482
settings["add_none_option"], False
483483
)
484+
if constants.CLIENT_EDITABLE in settings:
485+
settings[constants.CLIENT_EDITABLE] = aliases.yes_no.get(
486+
settings.get(constants.CLIENT_EDITABLE, "no"), False
487+
)
484488

485489
# Here we create our json dict root with default settings:
486490
id_string = settings.get(

tests/test_settings.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,71 @@ def test_primary_instance_attribute__multiple(self):
292292
""",
293293
],
294294
)
295+
296+
def test_client_editable_setting__active(self):
297+
"""Should find the odk:client-editable attribute in the submission config."""
298+
# Set to an alias of True.
299+
md1 = """
300+
| settings |
301+
| | client_editable |
302+
| | yes |
303+
| survey | | | |
304+
| | type | name | label |
305+
| | text | q1 | hello |
306+
"""
307+
# Set the same way as another submission setting (e.g. auto_send).
308+
md2 = """
309+
| settings |
310+
| | client_editable |
311+
| | true |
312+
| survey | | | |
313+
| | type | name | label |
314+
| | text | q1 | hello |
315+
"""
316+
for md in (md1, md2):
317+
self.assertPyxformXform(
318+
md=md,
319+
xml__xpath_match=[
320+
"""/h:html/h:head/x:model/x:submission[@odk:client-editable = 'true']""",
321+
],
322+
)
323+
324+
def test_client_editable_setting__inactive(self):
325+
"""Should not find the odk:client-editable attribute in the submission config."""
326+
# Set to an alias of False.
327+
md1 = """
328+
| settings |
329+
| | client_editable |
330+
| | no |
331+
| survey | | | |
332+
| | type | name | label |
333+
| | text | q1 | hello |
334+
"""
335+
# Not set.
336+
md2 = """
337+
| survey | | | |
338+
| | type | name | label |
339+
| | text | q1 | hello |
340+
"""
341+
for md in (md1, md2):
342+
self.assertPyxformXform(
343+
md=md,
344+
xml__xpath_match=[
345+
"""/h:html/h:head/x:model[not(./x:submission/@odk:client-editable)]""",
346+
],
347+
)
348+
# Set to false, with other setting that triggers `submission` element.
349+
md3 = """
350+
| settings |
351+
| | client_editable | auto_send |
352+
| | false | true |
353+
| survey | | | |
354+
| | type | name | label |
355+
| | text | q1 | hello |
356+
"""
357+
self.assertPyxformXform(
358+
md=md3,
359+
xml__xpath_match=[
360+
"""/h:html/h:head/x:model/x:submission[not(@odk:client-editable)]""",
361+
],
362+
)

0 commit comments

Comments
 (0)