Skip to content

Commit

Permalink
adjusting forms to make invalid forms valid
Browse files Browse the repository at this point in the history
* This could break skip logic on forms that haven't
  been explicitly naming their questions.
  • Loading branch information
dorey committed Oct 18, 2016
1 parent 4bc7b3a commit a9e9860
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions kpi/utils/autoname.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,19 @@ def _assign_row_to_name(row, suggested_name):
# cycle through existing names ane ensure that names are valid and unique
for row in filter(lambda r: _has_name(r), rows_needing_names):
_name = row['name']
if _name in other_names:
# We cannot automatically rename these because the names could be
# referenced in a skip logic string.
raise ValueError('Duplicate names: {}'.format(_name))
_attempt_count = 0
while (not is_valid_nodeName(_name) or _name in other_names):
# this will be necessary for untangling skip logic
row['$given_name'] = _name
_name = sluggify_label(_name,
other_names=other_names.keys())
if _name == '' and '$kuid' in row:
_name = '{}_{}'.format(row['type'], row['$kuid'])
elif _name == '':
_name = row['type']
if _attempt_count > 1000:
raise RuntimeError('Loop error: valid_name')
_attempt_count += 1
_assign_row_to_name(row, _name)

for row in filter(lambda r: not _has_name(r), rows_needing_names):
Expand Down

0 comments on commit a9e9860

Please sign in to comment.