From bbbd976671d616c1941d56bca3ea48522fb6d408 Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Wed, 24 Oct 2012 15:02:05 -0400 Subject: [PATCH] Added some more sample data. The command to export to Pearson reads from the table, but currently just adds the entries it needs at runtime. --- .../management/commands/pearson_export_cdd.py | 99 ++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/common/djangoapps/student/management/commands/pearson_export_cdd.py b/common/djangoapps/student/management/commands/pearson_export_cdd.py index ce90531941..e9433f15d5 100644 --- a/common/djangoapps/student/management/commands/pearson_export_cdd.py +++ b/common/djangoapps/student/management/commands/pearson_export_cdd.py @@ -1,5 +1,6 @@ import csv -from collections import OrderedDict +import uuid +from collections import defaultdict, OrderedDict from datetime import datetime from django.core.management.base import BaseCommand, CommandError @@ -43,6 +44,7 @@ class Command(BaseCommand): print Command.help return + self.reset_sample_data() with open(args[0], "wb") as outfile: writer = csv.DictWriter(outfile, @@ -58,3 +60,98 @@ class Command(BaseCommand): record["LastUpdate"] = record["LastUpdate"].strftime("%Y/%m/%d %H:%M:%S") writer.writerow(record) + def reset_sample_data(self): + def make_sample(**kwargs): + data = dict((model_field, kwargs.get(model_field, "")) + for model_field in Command.CSV_TO_MODEL_FIELDS.values()) + return TestCenterUser(**data) + + def generate_id(): + sub_uuid = str(uuid.uuid4()).upper() + return sub_uuid[-12:-8] + '-' + sub_uuid[-8:-4] + '-' + sub_uuid[-4:] + + TestCenterUser.objects.all().delete() + + samples = [ + make_sample( + client_candidate_id=generate_id(), + first_name="Jack", + last_name="Doe", + middle_name="C", + address_1="11 Cambridge Center", + address_2="Suite 101", + city="Cambridge", + state="MA", + postal_code="02140", + country="USA", + phone="(617)555-5555", + phone_country_code="1", + user_updated_at=datetime.utcnow() + ), + make_sample( + client_candidate_id=generate_id(), + first_name="Clyde", + last_name="Smith", + middle_name="J", + suffix="Jr.", + salutation="Mr.", + address_1="1 Penny Lane", + city="Honolulu", + state="HI", + postal_code="96792", + country="USA", + phone="555-555-5555", + phone_country_code="1", + user_updated_at=datetime.utcnow() + ), + make_sample( + client_candidate_id=generate_id(), + first_name="Patty", + last_name="Lee", + salutation="Dr.", + address_1="P.O. Box 555", + city="Honolulu", + state="HI", + postal_code="96792", + country="USA", + phone="808-555-5555", + phone_country_code="1", + user_updated_at=datetime.utcnow() + ), + make_sample( + client_candidate_id=generate_id(), + first_name="Jimmy", + last_name="James", + address_1="2020 Palmer Blvd.", + city="Springfield", + state="MA", + postal_code="96792", + country="USA", + phone="917-555-5555", + phone_country_code="1", + extension="2039", + fax="917-555-5556", + fax_country_code="1", + company_name="ACME Traps", + user_updated_at=datetime.utcnow() + ), + make_sample( + client_candidate_id=generate_id(), + first_name="Yeong-Un", + last_name="Seo", + address_1="Duryu, Lotte 101", + address_2="Apt 55", + city="Daegu", + country="KOR", + phone="917-555-5555", + phone_country_code="011", + user_updated_at=datetime.utcnow() + ), + + ] + + for tcu in samples: + tcu.save() + + + \ No newline at end of file