Skip to content

Commit f7ba636

Browse files
committed
make requested changes
1 parent 2698832 commit f7ba636

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/formpack/utils/kobo_locking.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ def get_kobo_locking_profiles(xls_file_object: io.BytesIO) -> list:
5353
return
5454

5555
locks = survey_dict[KOBO_LOCK_SHEET]
56-
# Get a unique list of profile names if they have at least one value set to
57-
# 'locked' from the matrix of values
58-
profiles = set(itertools.chain(*[lock.keys() for lock in locks]))
56+
57+
# Get a unique list of profile names
58+
profiles = set()
59+
for lock in locks:
60+
profiles.update(lock.keys())
5961

6062
# So some basic validation of locking profiles
6163
profiles = _validate_locking_profiles(profiles)
@@ -78,7 +80,7 @@ def get_kobo_locking_profiles(xls_file_object: io.BytesIO) -> list:
7880

7981
return list(locking_profiles.values())
8082

81-
def revert_kobo_lock_structre(content: dict) -> None:
83+
def revert_kobo_lock_structure(content: dict) -> None:
8284
"""
8385
Revert the structure of the locks to one that is ready to be exported into
8486
an XLSForm again -- the reverse of `get_kobo_locking_profiles`

src/formpack/utils/replace_aliases.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from .future import iteritems, OrderedDict
1414
from .string import str_types
15+
from ..constants import KOBO_LOCK_ALL
1516

1617
# This file is a mishmash of things which culminate in the
1718
# "replace_aliases" method which iterates through a survey and
@@ -301,10 +302,13 @@ def replace_aliases_in_place(content, allowed_types=None):
301302
' first been parsed through "expand_content".')
302303

303304
if settings:
304-
content['settings'] = dict([
305-
(
306-
kobo_specific_sub(settings_header_columns.get(key, key)),
307-
pyxform_aliases.yes_no.get(val, val),
305+
_settings = {}
306+
for key, val in settings.items():
307+
_key = kobo_specific_sub(settings_header_columns.get(key, key))
308+
_val = (
309+
pyxform_aliases.yes_no.get(val, val)
310+
if _key == KOBO_LOCK_ALL
311+
else val
308312
)
309-
for key, val in settings.items()
310-
])
313+
_settings[_key] = _val
314+
content['settings'] = _settings

tests/test_kobo_locking.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from formpack.constants import KOBO_LOCK_SHEET
1010
from formpack.utils.kobo_locking import (
1111
get_kobo_locking_profiles,
12-
revert_kobo_lock_structre,
12+
revert_kobo_lock_structure,
1313
strip_kobo_locking_profile,
1414
)
1515
from formpack.utils.exceptions import FormPackLibraryLockingError
@@ -126,7 +126,7 @@ def test_get_kobo_locking_profiles(self):
126126
][0]
127127
assert expected_restrictions == actual_restrictions
128128

129-
def test_revert_kobo_lock_structre(self):
129+
def test_revert_kobo_lock_structure(self):
130130
expected_reverted_locking_profiles = [
131131
{'restriction': 'choice_add', 'core': 'locked', 'flex': 'locked'},
132132
{'restriction': 'choice_delete', 'delete': 'locked'},
@@ -210,7 +210,7 @@ def test_revert_kobo_lock_structre(self):
210210
actual_reverted_locks = {
211211
KOBO_LOCK_SHEET: get_kobo_locking_profiles(xls)
212212
}
213-
revert_kobo_lock_structre(actual_reverted_locks)
213+
revert_kobo_lock_structure(actual_reverted_locks)
214214

215215
def _get_sorted_restrictions(restrictions):
216216
return sorted(restrictions, key=lambda k: k['restriction'])

0 commit comments

Comments
 (0)