diff options
| author | Mitch Riedstra <Mitch@riedstra.us> | 2017-10-09 15:04:39 -0400 |
|---|---|---|
| committer | Mitch Riedstra <Mitch@riedstra.us> | 2017-10-09 15:04:39 -0400 |
| commit | 0957977a439d0ca8f33cf6b3c7f2457b0bbf7cd6 (patch) | |
| tree | afcc1bb42d72e34cb64e9564d68be4576e33e24c /app/dispatch/management/commands/insert_test_data.py | |
| parent | 9f0a825ba66a37428efb178e2c6753c1373e9774 (diff) | |
| download | dispatch-tracker-0957977a439d0ca8f33cf6b3c7f2457b0bbf7cd6.tar.gz dispatch-tracker-0957977a439d0ca8f33cf6b3c7f2457b0bbf7cd6.tar.xz | |
Delete all of the old migrations, remove redundant contact model and add a script for adding fake data
Diffstat (limited to 'app/dispatch/management/commands/insert_test_data.py')
| -rw-r--r-- | app/dispatch/management/commands/insert_test_data.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/app/dispatch/management/commands/insert_test_data.py b/app/dispatch/management/commands/insert_test_data.py new file mode 100644 index 0000000..8ca9a33 --- /dev/null +++ b/app/dispatch/management/commands/insert_test_data.py @@ -0,0 +1,50 @@ +from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth import get_user_model +from dispatch.models import Company, Contact, Load + +import yaml + +User = get_user_model() + +class Command(BaseCommand): + help = "Import Objects from a YML file" + + def add_arguments(self, parser): + parser.add_argument('--file', type=str, dest='filename') + + + def handle(self, *args, **options): + + yml_data = open(options['filename']).read() + parsed = yaml.load(yml_data) + + self.parse_users(parsed['users']) + self.parse_loads(parsed['loads']) + + def parse_loads(self, loads): + for l in loads: + try: + new_user = Load( + load_number=u['load_number'], + date=u['date'], + user=u['user_email'], + user=u['user'], + ) + new_user.save() + except: + print("Error on user %s" % u['email']) + + + def parse_users(self, users): + for u in users: + try: + new_user = User( + first_name=u['firstName'], + last_name=u['lastName'], + email=u['email'], + username=u['firstName'] + is_active=u['active'] + ) + new_user.save() + except: + print("Error on user %s" % u['email']) |
