-
Notifications
You must be signed in to change notification settings - Fork 150
775: Support Entities from repeats #778
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
588c3b9
chg: remove unused question_type xls + code
lindsay-stevens 848117f
chg: update and expand tests on loops
lindsay-stevens e296c9c
add: test coverage for unmatched group begin/end
lindsay-stevens 9002113
chg: improve error messages for unmatched groups
lindsay-stevens a4e05b1
add: test coverage for name uniqueness rules
lindsay-stevens f8fd743
chg: make name uniqueness rules more consistent
lindsay-stevens 7a3d3cd
chg: move entities tests into folder
lindsay-stevens a187792
add: allow entities to be declared for a repeat
lindsay-stevens ba42054
add: name to unmatched control error messages
lindsay-stevens cdce738
chg: improve error messages
lindsay-stevens c736045
dev: merge branch 'master' into 'pyxform-775'
lindsay-stevens 2caa1e2
add: set entity id when creating new repeat
lindsay-stevens 0af166a
chg: set new entities version when repeat used
lindsay-stevens df6eee6
chg: improve entities xpath helper, refactor tests
lindsay-stevens 1e481b9
chg: standardise/fix/split action node output
lindsay-stevens 026bfe0
fix: repeat entity label binding path too low
lindsay-stevens 0014ca9
fix: repeat entity attribute binding paths too low
lindsay-stevens 983b990
add: error if entity save_to in undeclared repeat
lindsay-stevens 3c8287e
fix: only emit repeat setvalue with create mode
lindsay-stevens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| from enum import Enum | ||
|
|
||
| from pyxform.elements.element import Element | ||
| from pyxform.util.enum import StrEnum | ||
| from pyxform.utils import node | ||
|
|
||
|
|
||
| class Event(StrEnum): | ||
| """ | ||
| Supported W3C XForms 1.1 Events and ODK extensions. | ||
| """ | ||
|
|
||
| # For actions in model under /html/head/model | ||
| ODK_INSTANCE_FIRST_LOAD = "odk-instance-first-load" | ||
| ODK_INSTANCE_LOAD = "odk-instance-load" | ||
| # For actions in repeat control under /html/body | ||
| ODK_NEW_REPEAT = "odk-new-repeat" | ||
| # For actions in question control under /html/body | ||
| XFORMS_VALUE_CHANGED = "xforms-value-changed" | ||
|
|
||
|
|
||
| class Action(Element): | ||
| """ | ||
| Base class for supported Action elements. | ||
|
|
||
| https://getodk.github.io/xforms-spec/#actions | ||
| """ | ||
|
|
||
| __slots__ = ("event", "kwargs", "ref", "value") | ||
|
|
||
| def __init__( | ||
| self, | ||
| ref: str, | ||
| event: Event, | ||
| value: str | None = None, | ||
| **kwargs, | ||
| ): | ||
| super().__init__() | ||
| self.ref: str = ref | ||
| self.event: Event = event | ||
| self.value: str | None = value | ||
|
|
||
| def node(self): | ||
| return node(self.name, ref=self.ref, event=self.event.value) | ||
|
|
||
|
|
||
| class Setvalue(Action): | ||
| """ | ||
| Explicitly sets the value of the specified instance data node. | ||
|
|
||
| https://getodk.github.io/xforms-spec/#action:setvalue | ||
| """ | ||
|
|
||
| name = "setvalue" | ||
|
|
||
| def __init__(self, ref: str, event: Event, value: str | None = None, **kwargs): | ||
| super().__init__(ref=ref, event=event, value=value, **kwargs) | ||
|
|
||
| def node(self): | ||
| result = super().node() | ||
| if self.value: | ||
| result.setAttribute("value", self.value) | ||
| return result | ||
|
|
||
|
|
||
| class ODKSetGeopoint(Action): | ||
| """ | ||
| Sets the current location's geopoint value in the instance data node specified in the | ||
| ref attribute. | ||
|
|
||
| https://getodk.github.io/xforms-spec/#action:setgeopoint | ||
| """ | ||
|
|
||
| name = "odk:setgeopoint" | ||
|
|
||
| def __init__( | ||
| self, | ||
| ref: str, | ||
| event: Event, | ||
| value: str | None = None, | ||
| **kwargs, | ||
| ): | ||
| super().__init__(ref=ref, event=event, value=value, **kwargs) | ||
|
|
||
|
|
||
| class ODKRecordAudio(Action): | ||
| """ | ||
| Records audio starting at the triggering event, saves the audio to a file, and writes | ||
| the filename to the node specified in the ref attribute. | ||
|
|
||
| https://getodk.github.io/xforms-spec/#action:recordaudio | ||
| """ | ||
|
|
||
| __slots__ = ("quality",) | ||
| name = "odk:recordaudio" | ||
|
|
||
| def __init__( | ||
| self, | ||
| ref: str, | ||
| event: Event, | ||
| value: str | None = None, | ||
| **kwargs, | ||
| ): | ||
| super().__init__(ref=ref, event=event, value=value, **kwargs) | ||
| self.quality: str | None = kwargs.get("odk:quality") | ||
|
|
||
| def node(self): | ||
| result = super().node() | ||
| if self.quality: | ||
| result.setAttribute("odk:quality", self.quality) | ||
| return result | ||
|
|
||
|
|
||
| ACTION_CLASSES = { | ||
| "setvalue": Setvalue, | ||
| "odk:setgeopoint": ODKSetGeopoint, | ||
| "odk:recordaudio": ODKRecordAudio, | ||
| } | ||
|
|
||
|
|
||
| class LibraryMember: | ||
lindsay-stevens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def __init__(self, name: str, event: str): | ||
| self.name: str = name | ||
| self.event: str = event | ||
|
|
||
| def to_dict(self): | ||
| return {"name": self.name, "event": self.event} | ||
|
|
||
|
|
||
| class ActionLibrary(Enum): | ||
| """ | ||
| A collection of action/event configs used by pyxform. | ||
| """ | ||
|
|
||
| setvalue_first_load = LibraryMember( | ||
| name=Setvalue.name, | ||
| event=Event.ODK_INSTANCE_FIRST_LOAD.value, | ||
| ) | ||
| setvalue_new_repeat = LibraryMember( | ||
| name=Setvalue.name, | ||
| event=Event.ODK_NEW_REPEAT.value, | ||
| ) | ||
| setvalue_value_changed = LibraryMember( | ||
| name=Setvalue.name, | ||
| event=Event.XFORMS_VALUE_CHANGED.value, | ||
| ) | ||
| odk_setgeopoint_first_load = LibraryMember( | ||
| name=ODKSetGeopoint.name, | ||
| event=Event.ODK_INSTANCE_FIRST_LOAD.value, | ||
| ) | ||
| odk_setgeopoint_value_changed = LibraryMember( | ||
| name=ODKSetGeopoint.name, | ||
| event=Event.XFORMS_VALUE_CHANGED.value, | ||
| ) | ||
| odk_recordaudio_instance_load = LibraryMember( | ||
| name=ODKRecordAudio.name, | ||
| event=Event.ODK_INSTANCE_LOAD.value, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| from pyxform.utils import DetachableElement | ||
|
|
||
|
|
||
| class Element: | ||
| """ | ||
| Base class for Element interface and default behaviour. | ||
|
|
||
| Unlike SurveyElement which may emit multiple elements for a particular survey | ||
| component, this class is for defining individual elements for output. | ||
| """ | ||
|
|
||
| name: str | ||
|
|
||
| def node(self) -> "DetachableElement": | ||
| """ | ||
| Create the element. | ||
| """ | ||
| raise NotImplementedError() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 feels slightly uncomfortable to me to hard code the namespace prefix here since it has to match the namespace declaration. An alternative would be to define a constant for the prefix somewhere and use it consistently here and in the declaration. It's not super important because it's an obviously good convention that doesn't require much discipline to maintain but wanted to mention it. I probably feel discomfort because I'm used to seeing code on the form client side where it's important to support any prefix.
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.
good point for improvement though it was hard-coded previously (question_type_dictionary.py etc)