Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion specifyweb/backend/stored_queries/batch_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,24 @@ def _get_orig_column(string_id: str):

# We would have arbitarily sorted the columns, so our columns will not be correct.
# Rather than sifting the data, we just add a default visual order.
visual_order = Func.first(headers_enumerated)
visual_order: list[int | None] = [None for _ in key_and_headers]
new_columns: list[int] = []
for index, (key, _header) in headers_enumerated:
# Find the column's original position if it existed in the origin query
original_place = key[0]
if original_place < len(fields) and visual_order[original_place] is None:
visual_order[original_place] = index
else:
# New field/column. Add it to the end of the dataset.
new_columns.append(index)

# Fill in the gaps with the new columns
if new_columns:
for index, column in enumerate(visual_order):
if column is None:
visual_order[index] = new_columns.pop(0)
if len(new_columns) == 0:
break

headers = Func.second(key_and_headers)

Expand Down
Loading