def to_kpi_content_schema(self): ''' parses xlsform structure into json representation of spreadsheet structure. ''' if not xls_to_dicts: raise ImportError('formpack module needed') content = xls_to_dicts(self._xls_file_io()) # a temporary fix to the problem of list_name alias return json.loads(re.sub('list name', 'list_name', json.dumps(content, indent=4)))
def to_kpi_content_schema(self): """ Parses xlsform structure into json representation of spreadsheet structure. """ if not xls_to_dicts: raise ImportError('formpack module needed') content = xls_to_dicts(self._xls_file_io()) # a temporary fix to the problem of list_name alias return json.loads( re.sub('list name', 'list_name', json.dumps(content, indent=4)))
def _xlsform_to_kpi_content_schema(xlsform): ''' parses xlsform structure into json representation of spreadsheet structure. ''' content = xls_to_dicts(xlsform) # Remove the __version__ calculate question content['survey'] = [ row for row in content['survey'] if not ('calculation' in row and row.get('type', None) == 'calculate' and row.get('name', None) == '__version__') ] # a temporary fix to the problem of list_name alias # credit to @dorey return json.loads( re.sub('list name', 'list_name', json.dumps(content, indent=4)))
def _xlsform_to_kpi_content_schema(xlsform): ''' parses xlsform structure into json representation of spreadsheet structure. ''' content = xls_to_dicts(xlsform) # Remove the __version__ calculate question content['survey'] = [ row for row in content['survey'] if not ( 'calculation' in row and row.get('type', None) == 'calculate' and row.get('name', None) == '__version__' ) ] # a temporary fix to the problem of list_name alias # credit to @dorey return json.loads(re.sub('list name', 'list_name', json.dumps(content, indent=4)))
def test_xls_to_dicts(): with open('tests/fixtures/xlsforms/library-locking-example.xls', 'rb') as f: data = xls_to_dicts(f) assert list(data.keys()) == [ 'survey', 'choices', 'settings', 'kobo--locking-profiles', ] expected_result = OrderedDict([ ( 'survey', [ OrderedDict([ ('type', 'select_one countries'), ('name', 'country'), ('label', 'Select your country'), ('kobo--locking-profile', 'profile_1'), ]), OrderedDict([ ('type', 'select_one cities'), ('name', 'city'), ('label', 'Select your city'), ('kobo--locking-profile', 'profile_2'), ]), ], ), ( 'choices', [ OrderedDict([ ('list_name', 'countries'), ('name', 'canada'), ('label', 'Canada'), ]), OrderedDict([ ('list_name', 'countries'), ('name', 'usa'), ('label', 'United States of America'), ]), OrderedDict([ ('list_name', 'cities'), ('name', 'vancouver'), ('label', 'Vancouver'), ]), OrderedDict([ ('list_name', 'cities'), ('name', 'toronto'), ('label', 'Toronto'), ]), OrderedDict([ ('list_name', 'cities'), ('name', 'baltimore'), ('label', 'Baltimore'), ]), OrderedDict([ ('list_name', 'cities'), ('name', 'boston'), ('label', 'Boston'), ]), ], ), ( 'settings', [ OrderedDict([ ('kobo--locking-profile', 'profile_3'), ('kobo--lock_all', 'false'), ('form_title', 'Library Locking'), ]) ], ), ( 'kobo--locking-profiles', [ OrderedDict([('restriction', 'choice_add'), ('profile_1', 'locked')]), OrderedDict([ ('restriction', 'choice_delete'), ('profile_2', 'locked'), ]), OrderedDict([ ('restriction', 'choice_label_edit'), ('profile_1', 'locked'), ]), OrderedDict([ ('restriction', 'choice_order_edit'), ('profile_1', 'locked'), ('profile_2', 'locked'), ]), OrderedDict([ ('restriction', 'form_appearance'), ('profile_3', 'locked'), ]), ], ), ]) assert data == expected_result