First round of responses to PR feedback
This commit is contained in:
parent
c30ec49d02
commit
cc017a8695
2 changed files with 11 additions and 13 deletions
|
@ -10,7 +10,7 @@ from todo.operations.csv_importer import CSVImporter
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = """Import specifically formatted CSV file containing incoming tasks to be loaded.
|
help = """Import specifically formatted CSV file containing incoming tasks to be loaded.
|
||||||
For specfic format of inbound CSV, see data/import_example.csv.
|
For specfic format of inbound CSV, see data/import_example.csv.
|
||||||
For documentation on field formats and required fields, see README.md.
|
For documentation on upsert logic and required fields, see README.md.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def add_arguments(self, parser: CommandParser) -> None:
|
def add_arguments(self, parser: CommandParser) -> None:
|
||||||
|
@ -22,13 +22,14 @@ class Command(BaseCommand):
|
||||||
def handle(self, *args: Any, **options: Any) -> None:
|
def handle(self, *args: Any, **options: Any) -> None:
|
||||||
# Need a file to proceed
|
# Need a file to proceed
|
||||||
if not options.get("file"):
|
if not options.get("file"):
|
||||||
print("Sorry, we need a file name to work from.")
|
print("Sorry, we need a filename to work from.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
filepath = str(options.get("file"))
|
||||||
|
|
||||||
|
if not Path(filepath).exists():
|
||||||
|
print(f"Sorry, couldn't find file: {filepath}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
|
||||||
filepath = str(options.get("file"))
|
|
||||||
if not Path(filepath).exists():
|
|
||||||
print(f"Sorry, couldn't find file: {filepath}")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
with open(filepath, mode="r", encoding="utf-8-sig") as fileobj:
|
with open(filepath, mode="r", encoding="utf-8-sig") as fileobj:
|
||||||
# Pass in a file *object*, not a path
|
# Pass in a file *object*, not a path
|
||||||
|
|
|
@ -44,7 +44,7 @@ class CSVImporter:
|
||||||
# DI check: Do we have expected header row?
|
# DI check: Do we have expected header row?
|
||||||
header = csv_reader.fieldnames
|
header = csv_reader.fieldnames
|
||||||
expected = ['Title', 'Group', 'Task List', 'Created By', 'Created Date', 'Due Date', 'Completed', 'Assigned To', 'Note', 'Priority']
|
expected = ['Title', 'Group', 'Task List', 'Created By', 'Created Date', 'Due Date', 'Completed', 'Assigned To', 'Note', 'Priority']
|
||||||
if not header == expected:
|
if header != expected:
|
||||||
self.results.get('summaries').append(f"Inbound data does not have expected columns.\nShould be: {expected}")
|
self.results.get('summaries').append(f"Inbound data does not have expected columns.\nShould be: {expected}")
|
||||||
return self.results
|
return self.results
|
||||||
|
|
||||||
|
@ -93,11 +93,8 @@ class CSVImporter:
|
||||||
msg = f"Missing required task creator."
|
msg = f"Missing required task creator."
|
||||||
row_errors.append(msg)
|
row_errors.append(msg)
|
||||||
|
|
||||||
created_by = get_user_model().objects.filter(username=row.get("Created By"))
|
creator = get_user_model().objects.filter(username=row.get("Created By")).first()
|
||||||
if created_by.exists():
|
if not creator:
|
||||||
creator = created_by.first()
|
|
||||||
else:
|
|
||||||
creator = None
|
|
||||||
msg = f"Invalid task creator {row.get('Created By')}"
|
msg = f"Invalid task creator {row.get('Created By')}"
|
||||||
row_errors.append(msg)
|
row_errors.append(msg)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue