-
Notifications
You must be signed in to change notification settings - Fork 153
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 1 commit
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
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
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,112 @@ | ||
| from pyxform import constants as const | ||
| from pyxform.errors import Detail, PyXFormError | ||
|
|
||
| NAMES001 = Detail( | ||
| name="Invalid duplicate name in same context", | ||
| msg=( | ||
| "[row : {row}] On the 'survey' sheet, the 'name' value '{value}' is invalid. " | ||
| "Questions, groups, and repeats must be unique within their context i.e. nearest " | ||
| "parent group or repeat, or the survey if not inside a group or repeat." | ||
| ), | ||
| ) | ||
| NAMES002 = Detail( | ||
| name="Invalid duplicate name in context (case-insensitive)", | ||
| msg=( | ||
| "[row : {row}] On the 'survey' sheet, the 'name' value '{value}' is problematic. " | ||
| "The name is a case-insensitive match to another name. Questions, groups, and " | ||
| "repeats must be unique within their context i.e. nearest parent group or repeat, " | ||
| "or the survey if not inside a group or repeat. Some data processing tools are not " | ||
| "case-sensitive, so the current names may make analysis difficult." | ||
|
lindsay-stevens marked this conversation as resolved.
|
||
| ), | ||
| ) | ||
| NAMES003 = Detail( | ||
| name="Invalid repeat name same as survey", | ||
| msg=( | ||
| "[row : {row}] On the 'survey' sheet, the 'name' value '{value}' is invalid. " | ||
| "Repeat names must not be the same as the survey root (which defaults to 'data')." | ||
| ), | ||
| ) | ||
| NAMES004 = Detail( | ||
| name="Invalid duplicate repeat name in the survey", | ||
| msg=( | ||
| "[row : {row}] On the 'survey' sheet, the 'name' value '{value}' is invalid. " | ||
| "Repeat names must unique anywhere the survey, at all levels of group or repeat nesting." | ||
|
lindsay-stevens marked this conversation as resolved.
Outdated
|
||
| ), | ||
| ) | ||
| NAMES005 = Detail( | ||
| name="Invalid duplicate meta name in the survey", | ||
| msg=( | ||
| "[row : {row}] On the 'survey' sheet, the 'name' value 'meta' is invalid. " | ||
| "The name 'meta' is reserved for form metadata." | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def validate_question_group_repeat_name( | ||
| name: str | None, | ||
| seen_names: set[str], | ||
| seen_names_lower: set[str], | ||
| warnings: list[str], | ||
| row_number: int | None = None, | ||
| check_reserved: bool = True, | ||
| ): | ||
| """ | ||
| Warn about duplicate or problematic names on the survey sheet. | ||
|
|
||
| May append the name to `seen_names` and `neen_names_lower`. May append to `warnings`. | ||
|
|
||
| :param name: Question or group name. | ||
| :param seen_names: Names already processed in the sheet. | ||
| :param seen_names_lower: Same as seen_names but lower case. | ||
| :param warnings: Warnings list. | ||
| :param row_number: Current sheet row number. | ||
| :param check_reserved: If True, check the name against any reserved names. When | ||
| checking names in the context of SurveyElement processing, it's difficult to | ||
| differentiate user-specified names from names added by pyxform. | ||
| """ | ||
| if not name: | ||
| return | ||
|
|
||
| if check_reserved and not seen_names >= const.RESERVED_NAMES_SURVEY_SHEET: | ||
| seen_names.update(const.RESERVED_NAMES_SURVEY_SHEET) | ||
|
|
||
| if name in seen_names: | ||
| if name == const.META: | ||
| raise PyXFormError(NAMES005.format(row=row_number)) | ||
| else: | ||
| raise PyXFormError(NAMES001.format(row=row_number, value=name)) | ||
| seen_names.add(name) | ||
|
|
||
| question_name_lower = name.lower() | ||
| if question_name_lower in seen_names_lower: | ||
| # No case-insensitive warning for 'meta' since it's not an exported data table. | ||
| warnings.append(NAMES002.format(row=row_number, value=name)) | ||
| seen_names_lower.add(question_name_lower) | ||
|
|
||
|
|
||
| def validate_repeat_name( | ||
| name: str | None, | ||
| control_type: str, | ||
| instance_element_name: str, | ||
| seen_names: set[str], | ||
| row_number: int | None = None, | ||
| ): | ||
| """ | ||
| Warn about duplicate or problematic names. | ||
|
|
||
| May appends the name to `seen_names` and `neen_names_lower`. May append to `warnings`. | ||
| These checks are additional to the above in validate_survey_sheet_name so does not | ||
| re-check reserved names etc. | ||
|
|
||
| :param row_number: Current sheet row number. | ||
| :param name: Question or group name. | ||
| :param control_type: E.g. group, repeat, or loop. | ||
| :param instance_element_name: Name of the main survey instance element. | ||
| :param seen_names: Names already processed in the sheet. | ||
| """ | ||
| if control_type == const.REPEAT: | ||
| if name == instance_element_name: | ||
| raise PyXFormError(NAMES003.format(row=row_number, value=name)) | ||
| elif name in seen_names: | ||
| raise PyXFormError(NAMES004.format(row=row_number, value=name)) | ||
| seen_names.add(name) | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.