-
-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(OpenRosa): support XLSForm name
setting TASK-1074
#5137
Conversation
…nfirmation messages
2 similar comments
survey.update({ | ||
'name': survey.id_string, | ||
}) | ||
if not survey.name or survey.name == 'None': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @rajpatel24, thanks for working on this! I'm curious: were there conditions where the string None
gets passed in as the name
? It seems a bit surprising to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jnm, When the form lacked a 'name' setting, the name was being set as the string 'None'.
Previously, we ignored the name setting value, whether it was 'None' or an actual string, and always assigned survey.id_string as the default name.
Now, if a valid name string is present, we leave it unchanged. If the name setting is absent, we assign survey.id_string as the default name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to hassle on this, but I wanted to know where the string None
was coming from. It bothers me because someone could have their XLSForm settings
sheet look like this:
name |
---|
None |
It would be weird, but it'd be valid, and we wouldn't be able to tell the difference between a user-provided None
and the one that gets generated when the settings
sheet lacks a name
altogether.
I did some digging and found that the None
string is set by pyxform:
- It's a string because of this: https://github.com/XLSForm/pyxform/blob/9d20bfec5128f53ec0d555f7187f3bc4881f667e/pyxform/xls2json.py#L396-L397
None
itself comes fromdefault_name=None
in https://github.com/XLSForm/pyxform/blob/9d20bfec5128f53ec0d555f7187f3bc4881f667e/pyxform/builder.py#L327default_name
gets overridden by thename
value in thesettings
sheet of the XLSForm here: https://github.com/XLSForm/pyxform/blob/9d20bfec5128f53ec0d555f7187f3bc4881f667e/pyxform/xls2json.py#L469-L470
I see that even though create_survey_from_xls()
has a handy default_name
parameter, create_survey_from_xls(self.xls, default_name=self.id_string)
won't work because our logic relies on create_survey_from_xls()
pulling the id_string
out of the XLS file in the first place. This is a historical artifact; nowadays, we're always the ones generating the XLS file internally¹, and we always know the id_string
in advance.
Let's do a hack, though, instead of blowing up the scope of this PR. Please invent some constant that's unlikely ever to be a user-provided value, like PLACEHOLDER_NAME = '__kobo_placeholder_name_value__'
, call survey = create_survey_from_xls(self.xls, default_name=PLACEHOLDER_NAME)
, and then overwrite survey.name
only if it's equal to PLACEHOLDER_NAME
.
¹ Even when someone uploads their own XLSForm, we convert that to JSON, and then we convert it back to XLS again when deploying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have a unit test for this? I think it would ideally:
- Create an
Asset
with thename
setting (this can be in theAsset.content
; we do not need to mess around with importing an XLSX file) - Deploy that
Asset
- Inspect the resulting
XForm.xml
to verify that the first child of the primary instance (the first<instance>
) has a node name that matches thename
setting set in theAsset.content
.
Please ping me on Zulip if you have any questions 🙏
bcd064b
to
001425c
Compare
kpi/tests/test_assets.py
Outdated
'survey': [ | ||
{ | ||
'text': 'select_one', | ||
'label': 'q1' | ||
}, | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! I'm surprised the unit tests don't fail since there's no type
. I'll look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out that the entire question gets silently discarded (!) Note the empty "survey": [],
(Pdb) l
809 )
810 asset.deploy(backend='mock', active=True)
811 breakpoint()
812
813 # Get the deployed XForm and parse it
814 -> xform = XForm.objects.get(id_string=asset.uid)
815 parser = XFormInstanceParser(xform.xml, xform.data_dictionary())
816
817 # Access the first child element of the <instance> node
818 instance_node = parser.get_root_node().getElementsByTagName('instance')[0]
819 root_element = instance_node.firstChild
(Pdb) import json
(Pdb) print(json.dumps(asset.content, indent=2))
{
"survey": [],
"settings": {
"name": "custom_root_node_name"
},
"translations": [
null
],
"translated": [
"label"
],
"schema": "1"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! I'm surprised the unit tests don't fail since there's no
type
. I'll look into it.
I'm ashamed. I completely misunderstood this and replaced type
with text
🤦
Thanks @jnm for the correction :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made an internal thread to discuss the weird (existing) behavior of silently discarding invalid rows:
https://chat.kobotoolbox.org/#narrow/stream/4-Kobo-Dev/topic/Invalid.20asset.20content.20rows.20silently.20disarded
kpi/tests/test_assets.py
Outdated
'survey': [ | ||
{ | ||
'text': 'select_one', | ||
'label': 'q1', | ||
}, | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above
name
setting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed and tested locally. Thanks!
name
settingname
setting TASK-1074
1. [x] If you've added code that should be tested, add tests 2. [ ] If you've changed APIs, update (or create!) the documentation 3. [x] Ensure the tests pass 4. [x] Run `./python-format.sh` to make sure that your code lints and that you've followed [our coding style](https://github.com/kobotoolbox/kpi/blob/main/CONTRIBUTING.md) 5. [x] Write a title and, if necessary, a description of your work suitable for publishing in our [release notes](https://community.kobotoolbox.org/tag/release-notes) 6. [x] Mention any related issues in this repository (as #ISSUE) and in other repositories (as kobotoolbox/other#ISSUE) 7. [x] Open an issue in the [docs](https://github.com/kobotoolbox/docs/issues/new) if there are UI/UX changes This is an advanced feature for unusual cases where it's necessary to [override the root XML node name](https://xlsform.org/en/#specify-xforms-root-node-name) used in submissions. This may be used for an upcoming feature to allow customizable confirmation messages in Enketo. - Implemented logic to check and set the name attribute from XLSForms in the survey object. - The existing behavior where name was not utilized has been modified to honor the name setting, defaulting to the id_string if name is not provided or is invalid. Part of #5112 --------- Co-authored-by: John N. Milner <[email protected]>
1. [x] If you've added code that should be tested, add tests 2. [ ] If you've changed APIs, update (or create!) the documentation 3. [x] Ensure the tests pass 4. [x] Run `./python-format.sh` to make sure that your code lints and that you've followed [our coding style](https://github.com/kobotoolbox/kpi/blob/main/CONTRIBUTING.md) 5. [x] Write a title and, if necessary, a description of your work suitable for publishing in our [release notes](https://community.kobotoolbox.org/tag/release-notes) 6. [x] Mention any related issues in this repository (as #ISSUE) and in other repositories (as kobotoolbox/other#ISSUE) 7. [x] Open an issue in the [docs](https://github.com/kobotoolbox/docs/issues/new) if there are UI/UX changes This is an advanced feature for unusual cases where it's necessary to [override the root XML node name](https://xlsform.org/en/#specify-xforms-root-node-name) used in submissions. This may be used for an upcoming feature to allow customizable confirmation messages in Enketo. - Implemented logic to check and set the name attribute from XLSForms in the survey object. - The existing behavior where name was not utilized has been modified to honor the name setting, defaulting to the id_string if name is not provided or is invalid. Part of #5112 --------- Co-authored-by: John N. Milner <[email protected]>
1. [x] If you've added code that should be tested, add tests 2. [ ] If you've changed APIs, update (or create!) the documentation 3. [x] Ensure the tests pass 4. [x] Run `./python-format.sh` to make sure that your code lints and that you've followed [our coding style](https://github.com/kobotoolbox/kpi/blob/main/CONTRIBUTING.md) 5. [x] Write a title and, if necessary, a description of your work suitable for publishing in our [release notes](https://community.kobotoolbox.org/tag/release-notes) 6. [x] Mention any related issues in this repository (as #ISSUE) and in other repositories (as kobotoolbox/other#ISSUE) 7. [x] Open an issue in the [docs](https://github.com/kobotoolbox/docs/issues/new) if there are UI/UX changes This is an advanced feature for unusual cases where it's necessary to [override the root XML node name](https://xlsform.org/en/#specify-xforms-root-node-name) used in submissions. This may be used for an upcoming feature to allow customizable confirmation messages in Enketo. - Implemented logic to check and set the name attribute from XLSForms in the survey object. - The existing behavior where name was not utilized has been modified to honor the name setting, defaulting to the id_string if name is not provided or is invalid. Part of #5112 --------- Co-authored-by: John N. Milner <[email protected]>
Checklist
./python-format.sh
to make sure that your code lints and that you've followed our coding styleDescription
This is an advanced feature for unusual cases where it's necessary to override the root XML node name used in submissions. This may be used for an upcoming feature to allow customizable confirmation messages in Enketo.
Notes
Related issues
Part of #5112