Skip to content

Commit

Permalink
Add list_name alias for dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
lognaturel committed Sep 15, 2023
1 parent f61833e commit 0381770
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
3 changes: 3 additions & 0 deletions pyxform/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
"parameters": "parameters",
constants.ENTITIES_SAVETO: "bind::entities:saveto",
}

entities_header = {"list_name": "dataset"}

# Key is the pyxform internal name, Value is the name used in error/warning messages.
TRANSLATABLE_SURVEY_COLUMNS = {
constants.LABEL: constants.LABEL,
Expand Down
6 changes: 3 additions & 3 deletions pyxform/entities/entities_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from pyxform.xlsparseutils import find_sheet_misspellings, is_valid_xml_tag


def get_entity_declaration(workbook_dict: Dict, warnings: List) -> Dict:
entities_sheet = workbook_dict.get(constants.ENTITIES, [])

def get_entity_declaration(
entities_sheet: Dict, workbook_dict: Dict, warnings: List
) -> Dict:
if len(entities_sheet) == 0:
similar = find_sheet_misspellings(
key=constants.ENTITIES, keys=workbook_dict.keys()
Expand Down
6 changes: 5 additions & 1 deletion pyxform/xls2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,11 @@ def workbook_to_json(
) # noqa

# ########## Entities sheet ###########
entity_declaration = get_entity_declaration(workbook_dict, warnings)
entities_sheet = workbook_dict.get(constants.ENTITIES, [])
entities_sheet = dealias_and_group_headers(
entities_sheet, aliases.entities_header, False
)
entity_declaration = get_entity_declaration(entities_sheet, workbook_dict, warnings)

# ########## Survey sheet ###########
survey_sheet = workbook_dict[constants.SURVEY]
Expand Down
18 changes: 17 additions & 1 deletion tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class EntitiesTest(PyxformTestCase):
def test_basic_entity_creation_building_blocks(self):
self.assertPyxformXform(
name="data",
debug=True,
md="""
| survey | | | |
| | type | name | label |
Expand Down Expand Up @@ -336,3 +335,20 @@ def test_saveto_in_group__works(self):
""",
errored=False,
)

def test_list_name_alias_to_dataset(self):
self.assertPyxformXform(
name="data",
md="""
| survey | | | |
| | type | name | label |
| | text | a | A |
| entities | | | |
| | list_name | label | |
| | trees | a | |
""",
xml__xpath_match=[
"/h:html/h:head/x:model/x:instance/x:data/x:meta/x:entity",
'/h:html/h:head/x:model/x:instance/x:data/x:meta/x:entity[@dataset = "trees"]',
],
)

0 comments on commit 0381770

Please sign in to comment.