-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Backend Changes for Customizable Confirmation Screen #5112
base: main
Are you sure you want to change the base?
Conversation
…ML based on a custom attribute
d8f8458
to
f11a723
Compare
Note, it is probably worth double-checking that the ODK COllect/KoboCollect mobile client ignores - or is otherwise not negatively impacted - by having a non-empty Specifically, the |
# Conflicts: # kobo/apps/audit_log/tests/test_models.py # kobo/apps/audit_log/tests/test_one_time_auth.py # kobo/apps/openrosa/apps/api/viewsets/xform_submission_api.py # kobo/apps/openrosa/apps/logger/models/attachment.py # kobo/apps/openrosa/apps/main/tests/test_process.py
…lbox/kpi into customizable_confirmation_screen
def extract_confirmation_message(xml_string: str) -> str | None: | ||
""" | ||
Extracts the confirmation message from the XML string based on the | ||
`kobo:submitMessage` attribute. | ||
""" | ||
if isinstance(xml_string, str): | ||
xml_string = xml_string.encode('utf-8') | ||
parser = etree.XMLParser(recover=True) | ||
root = etree.fromstring(xml_string, parser=parser) | ||
namespaces = root.nsmap | ||
|
||
# Extract the kobo:submitMessage attribute from the root element | ||
try: | ||
confirmation_message_xpath = root.xpath( | ||
'@kobo:submitMessage', namespaces=namespaces | ||
) | ||
except etree.XPathEvalError: | ||
return | ||
|
||
if not confirmation_message_xpath: | ||
return | ||
|
||
# Blocked by kpi#5137, this block below works as-is but won't work | ||
# when kpi#5137 is merged. | ||
confirmation_message_xpath = confirmation_message_xpath[0].replace( | ||
'/data', f'/{root.tag}' | ||
).strip() | ||
|
||
try: | ||
# Evaluate the XPath expression to find the message | ||
confirmation_message_element = root.xpath(confirmation_message_xpath) | ||
except etree.XPathEvalError as e: | ||
logging.error( | ||
'Failed to extract confirmation message: ' + str(e), | ||
exc_info=True | ||
) | ||
else: | ||
if confirmation_message_element: | ||
return confirmation_message_element[0].text | ||
|
||
return |
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.
I took the liberty to make some changes to understand how it worked and to make it work.
The tests were passing because in your XML, submitMessage
starts with the root tag.
In real world, Kobo uses the id_string
for the XForm which always changes and cannot be set in the settings
for the XLS file (i.e. attribute::kobo:submitMessage
)
See https://chat.kobotoolbox.org/#narrow/stream/4-Kobo-Dev/topic/Customizable.20confirmation.20screen.20in.20Enketo/near/469885 , IMO this PR is blocked by kpi#5137.
We should add a test to be sure everything work if no attribute::kobo:submitMessage
is present.
a4df9e4
to
7375725
Compare
7375725
to
a60fede
Compare
## Checklist 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 ## Description 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. ## Notes - 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. ## Related issues Part of #5112 --------- Co-authored-by: John N. Milner <[email protected]>
Checklist
Description
This PR implements the backend changes for a customizable confirmation screen feature in Enketo, enhancing the user experience by providing personalized feedback based on their survey responses. The changes enable OpenRosa to dynamically extract and return customized confirmation messages, leveraging the flexibility of XLSForm's calculation capabilities.
The feature utilizes the
kobo:submitResponseMessage
attribute, allowing form designers to specify the XPath to the element containing the confirmation message. This PR modifies OpenRosa to recognize and extract this XPath, retrieve the corresponding message from the XML submission payload, and return it in the 201 response.Notes
kobo:submitResponseMessage
attribute