Skip to content

Commit 29c1fc1

Browse files
committed
Add function to format rows for import.
1 parent 530c9f8 commit 29c1fc1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

fishbowl/api.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,8 @@ def run_import(self, import_type, rows):
929929
"""
930930
Run the provided import type with the provided rows.
931931
932+
Ideally used with format_rows.
933+
932934
Rows can, and ideally should, contain a header entry as the first item
933935
to assist fishbowl in determining the data format. You can get the
934936
full list of headers for a specific import via the get_import_headers()
@@ -1036,3 +1038,15 @@ def check_status(element, expected=statuscodes.SUCCESS, allow_none=False):
10361038
if str(code) != expected and (code is not None or not allow_none):
10371039
raise FishbowlError(message)
10381040
return message
1041+
1042+
1043+
def format_rows(rows):
1044+
"""
1045+
Format rows for use with run_import.
1046+
"""
1047+
buff = StringIO(newline="")
1048+
writer = csv.writer(buff, quoting=csv.QUOTE_ALL)
1049+
for row in rows:
1050+
writer.writerow(row)
1051+
buff.seek(0)
1052+
return [x.strip() for x in buff.readlines()]

0 commit comments

Comments
 (0)