Commit a6a58d0e by Brian Wilson

pearson_dump: prettify, add missing error, provide default filename

parent 15a11e9c
from optparse import make_option from optparse import make_option
from json import dump from json import dump
from datetime import datetime
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
...@@ -32,10 +33,9 @@ class Command(BaseCommand): ...@@ -32,10 +33,9 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
if len(args) < 1: if len(args) < 1:
raise CommandError("Missing single argument: output JSON file") outputfile = datetime.utcnow().strftime("pearson-dump-%Y%m%d-%H%M%S.json")
else:
# get output location: outputfile = args[0]
outputfile = args[0]
# construct the query object to dump: # construct the query object to dump:
registrations = TestCenterRegistration.objects.all() registrations = TestCenterRegistration.objects.all()
...@@ -65,6 +65,8 @@ class Command(BaseCommand): ...@@ -65,6 +65,8 @@ class Command(BaseCommand):
} }
if len(registration.upload_error_message) > 0: if len(registration.upload_error_message) > 0:
record['registration_error'] = registration.upload_error_message record['registration_error'] = registration.upload_error_message
if len(registration.testcenter_user.upload_error_message) > 0:
record['demographics_error'] = registration.testcenter_user.upload_error_message
if registration.needs_uploading: if registration.needs_uploading:
record['needs_uploading'] = True record['needs_uploading'] = True
...@@ -72,5 +74,5 @@ class Command(BaseCommand): ...@@ -72,5 +74,5 @@ class Command(BaseCommand):
# dump output: # dump output:
with open(outputfile, 'w') as outfile: with open(outputfile, 'w') as outfile:
dump(output, outfile) dump(output, outfile, indent=2)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment