Skip to content

Commit

Permalink
Merge pull request #390 from ror-community/fix-dup-names-bulk-create
Browse files Browse the repository at this point in the history
fix issue w lang code removed when duplicate name vals in new records from csv
  • Loading branch information
lizkrznarich committed Apr 15, 2024
2 parents 018a3d9 + 2ff5e45 commit 0638cde
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
38 changes: 20 additions & 18 deletions rorapi/common/csv_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,29 @@ def new_record_from_csv(csv_data, version):
temp_names.append(name_obj)
print("temp names 1:")
print(temp_names)
name_values = [n['value'] for n in temp_names]
name_vals = [n['value'] for n in temp_names]
dup_names = []
for n in name_values:
if name_values.count(n) > 1:
for n in name_vals:
if name_vals.count(n) > 1:
if n not in dup_names:
dup_names.append(n)
if dup_names:
dup_names_objs = []
for d in dup_names:
types = []
for t in temp_names:
if t['value'] == d:
types.extend(t['types'])
name_obj = {
"types": types,
"value": d,
"lang": None
}
dup_names_objs.append(name_obj)
temp_names = [t for t in temp_names if t['value'] not in dup_names]
temp_names.extend(dup_names_objs)
for d in dup_names:
dup_names_objs = [t for t in temp_names if t['value'] == d]
lang_codes = [dno['lang'] for dno in dup_names_objs]
for lang_code in lang_codes:
if lang_codes.count(lang_code) > 1:
name_lang_dups = [dno for dno in dup_names_objs if dno['lang'] == lang_code]
types = []
for n in name_lang_dups:
types.extend(n['types'])
name_obj = {
"types": types,
"value": d,
"lang": lang_code
}
if name_obj not in temp_names:
temp_names = [t for t in temp_names if t not in name_lang_dups]
temp_names.append(name_obj)
print("temp names 2:")
print(temp_names)
v2_data['names'] = temp_names
Expand Down
2 changes: 1 addition & 1 deletion rorapi/common/csv_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def update_record_from_csv(csv_data, version):
# check if value, lang and type already exist
if temp_names_match or temp_names_null_lang_match:
if temp_names_match:
errors.append("Attempting to add names that already exists: {}".format(a))
errors.append("Attempting to add name that already exists: {}".format(a))
if temp_names_null_lang_match:
errors.append("Attempting to add name with lang code that already exists with no lang code: {}".format(a))
else:
Expand Down

0 comments on commit 0638cde

Please sign in to comment.