Skip to content

Commit

Permalink
Process only standard XLSForm sheets
Browse files Browse the repository at this point in the history
Fix #229
  • Loading branch information
ukanga committed Dec 3, 2018
1 parent 643bf2f commit 9249534
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
12 changes: 11 additions & 1 deletion pyxform/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@
OSM = u"osm"
OSM_TYPE = u"binary"

NAMESPACES = u'namespaces'
NAMESPACES = u"namespaces"

SUPPORTED_SHEET_NAMES = [
SURVEY,
CASCADING_CHOICES,
CHOICES,
COLUMNS,
CHOICES_AND_COLUMNS,
SETTINGS,
OSM,
]
Binary file not shown.
13 changes: 12 additions & 1 deletion pyxform/tests/bug_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,16 @@ def test_blank_second_row(self):
self.assertTrue(len(survey_dict) > 0)


if __name__ == '__main__':
class TestXLDateAmbigous(unittest.TestCase):
"""Test non standard sheet with exception is processed successfully."""
def test_xl_date_ambigous(self):
"""Test non standard sheet with exception is processed successfully."""
filename = "xl_date_ambiguous.xlsx"
path_to_excel_file = os.path.join(DIR, "bug_example_xls", filename)
xls_reader = SurveyReader(path_to_excel_file)
survey_dict = xls_reader.to_json_dict()
self.assertTrue(len(survey_dict) > 0)


if __name__ == "__main__":
unittest.main()
9 changes: 7 additions & 2 deletions pyxform/xls2json_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,16 @@ def slugify(s):

result = OrderedDict()
for sheet in workbook.sheets():
# Do not process sheets that have nothing to do with XLSForm.
if sheet.name not in constants.SUPPORTED_SHEET_NAMES:
continue
if sheet.name == constants.CASCADING_CHOICES:
result[sheet.name] = _xls_to_dict_cascade_sheet(sheet)
else:
result[sheet.name], result[u"%s_header" % sheet.name] = \
xls_to_dict_normal_sheet(sheet)
result[sheet.name], result[
u"%s_header" % sheet.name
] = xls_to_dict_normal_sheet(sheet)

return result


Expand Down

0 comments on commit 9249534

Please sign in to comment.