Esempio n. 1
0
 def _xlsform_structure(self, content, ordered=True):
     if ordered:
         if not isinstance(content, OrderedDict):
             raise TypeError('content must be an ordered dict if '
                             'ordered=True')
         flatten_to_spreadsheet_content(content, in_place=True,
                                        **FLATTEN_OPTS)
     else:
         flatten_content(content, in_place=True, **FLATTEN_OPTS)
Esempio n. 2
0
 def _xlsform_structure(self, content, ordered=True, kobo_specific=False):
     opts = copy.deepcopy(FLATTEN_OPTS)
     if not kobo_specific:
         opts['remove_columns']['survey'].append('$kuid')
         opts['remove_columns']['survey'].append('$autoname')
         opts['remove_columns']['choices'].append('$kuid')
         opts['remove_columns']['choices'].append('$autovalue')
     if ordered:
         if not isinstance(content, OrderedDict):
             raise TypeError('content must be an ordered dict if '
                             'ordered=True')
         flatten_to_spreadsheet_content(content, in_place=True, **opts)
     else:
         flatten_content(content, in_place=True, **opts)
def test_flatten_to_spreadsheet_content():
    _e = {
        'survey': [
            {'type': 'text', 'name': 'q1',
                'label': ['lang1'],
             },
        ],
        'choices': [
            {'list_name': 'xyz',
                'name': 'x',
                'label': ['X']},
            {'list_name': 'xyz',
                'name': 'y',
                'label': ['Y']},
            {'list_name': 'xyz',
                'name': 'z',
                'label': ['Z']},
        ],
        'settings': {
            'xyz': 'abc',
        },
        'translated': ['label'],
        'translations': ['lang1'],
    }
    _c = flatten_to_spreadsheet_content(_e)
    assert isinstance(_c, OrderedDict)
    assert list(_c) == ['survey', 'choices', 'settings']
def test_flatten_to_spreadsheet_content():
    _e = {
        'survey': [
            {'type': 'text', 'name': 'q1',
                'label': ['lang1'],
             },
        ],
        'choices': [
            {'list_name': 'xyz',
                'name': 'x',
                'label': ['X']},
            {'list_name': 'xyz',
                'name': 'y',
                'label': ['Y']},
            {'list_name': 'xyz',
                'name': 'z',
                'label': ['Z']},
        ],
        'settings': {
            'xyz': 'abc',
        },
        'translated': ['label'],
        'translations': ['lang1'],
    }
    _c = flatten_to_spreadsheet_content(_e)
    assert isinstance(_c, OrderedDict)
    assert _c.keys() == ['survey', 'choices', 'settings']
def test_flatten_tags():
    _e = {
        'survey': [
            {'type': 'text', 'name': 'q1',
                'label': 'lang1',
                'tags': ['hxl:x', 'hxl:y', 'hxl:z'],
             },
        ],
    }
    _c = flatten_to_spreadsheet_content(_e)
    assert _c['survey'][0]['hxl'] == 'xyz'
def test_flatten_translated_to_spreadsheet_content_with_null_lang():
    s1 = {'survey': [{'type': 'note',
                      'label': ['lang1 label', 'lang2 label', 'label nolang'],
                      'hint': ['lang1 hint', 'lang2 hint',  None],
                      }],
          'translations': ['Lang1', 'Lang2', None],
          'translated': ['label', 'hint']}
    _c = flatten_to_spreadsheet_content(s1)
    _r1 = _c['survey'][0]
    assert 'label' in _r1
    # ok that hint is in there, even though all the hints are None
    assert 'hint' in _r1
    assert 'label::Lang1' in _r1
    assert 'label::Lang2' in _r1
    assert 'hint::Lang1' in _r1
    assert 'hint::Lang2' in _r1
def test_flatten_translated_to_spreadsheet_content():
    s1 = {'survey': [{'type': 'note',
                      'label': ['lang1 label', 'lang2 label'],
                      'hint': ['lang1 hint', 'lang2 hint'],
                      }],
          'translations': ['Lang1', 'Lang2'],
          'translated': ['label', 'hint']}
    _c = flatten_to_spreadsheet_content(s1)
    _r1 = _c['survey'][0]
    assert _r1['type'] == 'note'
    # we should do this
    assert 'label' not in _r1
    assert 'label::Lang1' in _r1
    assert 'label::Lang2' in _r1
    assert 'hint::Lang1' in _r1
    assert 'hint::Lang2' in _r1
def test_flatten_translated_to_spreadsheet_content_with_null_lang():
    s1 = {'survey': [{'type': 'note',
                      'label': ['lang1 label', 'lang2 label', 'label nolang'],
                      'hint': ['lang1 hint', 'lang2 hint',  None],
                      }],
          'translations': ['Lang1', 'Lang2', None],
          'translated': ['label', 'hint']}
    _c = flatten_to_spreadsheet_content(s1)
    _r1 = _c['survey'][0]
    assert 'label' in _r1
    # ok that hint is in there, even though all the hints are None
    assert 'hint' in _r1
    assert 'label::Lang1' in _r1
    assert 'label::Lang2' in _r1
    assert 'hint::Lang1' in _r1
    assert 'hint::Lang2' in _r1
def test_flatten_translated_to_spreadsheet_content():
    s1 = {'survey': [{'type': 'note',
                      'label': ['lang1 label', 'lang2 label'],
                      'hint': ['lang1 hint', 'lang2 hint'],
                      }],
          'translations': ['Lang1', 'Lang2'],
          'translated': ['label', 'hint']}
    _c = flatten_to_spreadsheet_content(s1)
    _r1 = _c['survey'][0]
    assert _r1['type'] == 'note'
    # we should do this
    assert 'label' not in _r1
    assert 'label::Lang1' in _r1
    assert 'label::Lang2' in _r1
    assert 'hint::Lang1' in _r1
    assert 'hint::Lang2' in _r1