PR responses
This commit is contained in:
parent
bc8e6dd020
commit
474f6ef2ed
2 changed files with 11 additions and 11 deletions
|
@ -25,33 +25,33 @@ class Command(BaseCommand):
|
||||||
print("Sorry, we need a filename to work from.")
|
print("Sorry, we need a filename to work from.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
filepath = str(options.get("file"))
|
filepath = Path(options["file"])
|
||||||
|
|
||||||
if not Path(filepath).exists():
|
if not filepath.exists():
|
||||||
print(f"Sorry, couldn't find file: {filepath}")
|
print(f"Sorry, couldn't find file: {filepath}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
with open(filepath, mode="r", encoding="utf-8-sig") as fileobj:
|
# Encoding "utf-8-sig" means "ignore byte order mark (BOM), which Excel inserts when saving CSVs."
|
||||||
# Pass in a file *object*, not a path
|
with filepath.open(mode="r", encoding="utf-8-sig") as fileobj:
|
||||||
importer = CSVImporter()
|
importer = CSVImporter()
|
||||||
results = importer.upsert(fileobj, as_string_obj=True)
|
results = importer.upsert(fileobj, as_string_obj=True)
|
||||||
|
|
||||||
# Report successes, failures and summaries
|
# Report successes, failures and summaries
|
||||||
print()
|
print()
|
||||||
if results.get("upserts"):
|
if results["upserts"]:
|
||||||
for upsert_msg in results.get("upserts"):
|
for upsert_msg in results["upserts"]:
|
||||||
print(upsert_msg)
|
print(upsert_msg)
|
||||||
|
|
||||||
# Stored errors has the form:
|
# Stored errors has the form:
|
||||||
# self.errors = [{3: ["Incorrect foo", "Non-existent bar"]}, {7: [...]}]
|
# self.errors = [{3: ["Incorrect foo", "Non-existent bar"]}, {7: [...]}]
|
||||||
if results.get("errors"):
|
if results["errors"]:
|
||||||
for error_dict in results.get("errors"):
|
for error_dict in results["errors"]:
|
||||||
for k, error_list in error_dict.items():
|
for k, error_list in error_dict.items():
|
||||||
print(f"\nSkipped CSV row {k}:")
|
print(f"\nSkipped CSV row {k}:")
|
||||||
for msg in error_list:
|
for msg in error_list:
|
||||||
print(f"- {msg}")
|
print(f"- {msg}")
|
||||||
|
|
||||||
print()
|
print()
|
||||||
if results.get("summaries"):
|
if results["summaries"]:
|
||||||
for summary_msg in results.get("summaries"):
|
for summary_msg in results["summaries"]:
|
||||||
print(summary_msg)
|
print(summary_msg)
|
||||||
|
|
|
@ -186,7 +186,7 @@ class CSVImporter:
|
||||||
row["Assigned To"] = assignee
|
row["Assigned To"] = assignee
|
||||||
|
|
||||||
# Set Completed
|
# Set Completed
|
||||||
row["Completed"] = True if row.get("Completed") == "Yes" else False
|
row["Completed"] = (row["Completed"] == "Yes")
|
||||||
|
|
||||||
# #######################
|
# #######################
|
||||||
if row_errors:
|
if row_errors:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue