From 680206d3676df5dafb8b38644bf9b1714b869102 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 20 Feb 2020 16:51:13 +0000 Subject: renamed generate_people command to populate_db because it has much more to do --- .../management/commands/generate_people.py | 29 ---------------------- .../management/commands/populate_db.py | 29 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 29 deletions(-) delete mode 100644 ctrack/organisations/management/commands/generate_people.py create mode 100644 ctrack/organisations/management/commands/populate_db.py (limited to 'ctrack/organisations/management') diff --git a/ctrack/organisations/management/commands/generate_people.py b/ctrack/organisations/management/commands/generate_people.py deleted file mode 100644 index 53ece21..0000000 --- a/ctrack/organisations/management/commands/generate_people.py +++ /dev/null @@ -1,29 +0,0 @@ -from django.core.management import BaseCommand -from django.core.management import CommandParser - -from ctrack.organisations.tests.factories import PersonFactory -from ctrack.organisations.tests.factories import RoleFactory -from ctrack.organisations.tests.factories import UserFactory - - -class Command(BaseCommand): - help = """ - Creates a bunch of people and organisations for them to work in. - - Also creates users and roles as these are required fields. - """ - - def add_arguments(self, parser: CommandParser) -> None: - parser.add_argument("number", nargs=1, type=int) - - def handle(self, *args, **options): - number = options["number"][0] - user = UserFactory.create() # we need to have at least one user for the updated_by field - role = RoleFactory.create() # because we have a many-to-many relationship with Role, we need to create one and pass it in - PersonFactory.create_batch(number, role=role, updated_by=user, - predecessor__predecessor=None) # we do this so we don't get a loop - self.stdout.write( - self.style.SUCCESS( - f"Created {number} Person object[s]! Go forth and multiply." - ) - ) diff --git a/ctrack/organisations/management/commands/populate_db.py b/ctrack/organisations/management/commands/populate_db.py new file mode 100644 index 0000000..53ece21 --- /dev/null +++ b/ctrack/organisations/management/commands/populate_db.py @@ -0,0 +1,29 @@ +from django.core.management import BaseCommand +from django.core.management import CommandParser + +from ctrack.organisations.tests.factories import PersonFactory +from ctrack.organisations.tests.factories import RoleFactory +from ctrack.organisations.tests.factories import UserFactory + + +class Command(BaseCommand): + help = """ + Creates a bunch of people and organisations for them to work in. + + Also creates users and roles as these are required fields. + """ + + def add_arguments(self, parser: CommandParser) -> None: + parser.add_argument("number", nargs=1, type=int) + + def handle(self, *args, **options): + number = options["number"][0] + user = UserFactory.create() # we need to have at least one user for the updated_by field + role = RoleFactory.create() # because we have a many-to-many relationship with Role, we need to create one and pass it in + PersonFactory.create_batch(number, role=role, updated_by=user, + predecessor__predecessor=None) # we do this so we don't get a loop + self.stdout.write( + self.style.SUCCESS( + f"Created {number} Person object[s]! Go forth and multiply." + ) + ) -- cgit v1.2.3