Skip to content

Commit

Permalink
Fix setting SPSS date formats
Browse files Browse the repository at this point in the history
Get correct variable name for use when setting date formats for SPSS fields
  • Loading branch information
ukanga committed Jun 13, 2017
1 parent 062a150 commit 6d144b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions onadata/apps/viewer/tests/test_export_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,15 @@ def test_zipped_sav_export_with_date_field(self):
| survey |
| | type | name | label |
| | date | expense_date | Expense Date |
| | begin group | A | A group |
| | date | gdate | Good Day |
| | end group | | |
| choices |
| | list name | name | label |
"""
survey = self.md_to_pyxform_survey(md, {'name': 'exp'})
data = [{"expense_date": "2013-01-03",
data = [{"expense_date": "2013-01-03", "A/gdate": "2017-06-13",
'_submission_time': u'2016-11-21T03:43:43.000-08:00'}]
export_builder = ExportBuilder()
export_builder.set_survey(survey)
Expand All @@ -442,8 +445,12 @@ def test_zipped_sav_export_with_date_field(self):
returnHeader=True) as reader:
rows = [r for r in reader]
self.assertTrue(len(rows) > 1)
self.assertEqual(rows[0][0], 'expense_date')
self.assertEqual(rows[1][0], '2013-01-03')
self.assertEqual(rows[1][4], '2016-11-21 03:43:43')
self.assertEqual(rows[0][1], 'A.gdate')
self.assertEqual(rows[1][1], '2017-06-13')
self.assertEqual(rows[0][5], '@_submission_time')
self.assertEqual(rows[1][5], '2016-11-21 03:43:43')

shutil.rmtree(temp_dir)

Expand Down
6 changes: 3 additions & 3 deletions onadata/libs/utils/export_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,9 +911,9 @@ def _is_numeric(xpath, element_type, data_dictionary):
SUBMISSION_TIME] else 255)
for item in self.EXTRA_FIELDS]
)
dates = [element for element in elements if element.get('type') ==
'date']
formats = {d['xpath']: 'EDATE40' for d in dates}
dates = [_var_types[element['xpath']] for element in elements
if element.get('type') == 'date']
formats = {d: 'EDATE40' for d in dates}
formats['@' + SUBMISSION_TIME] = 'DATETIME40'

return {
Expand Down

0 comments on commit 6d144b0

Please sign in to comment.