From: Charles Holbrow Date: Wed, 23 Jan 2013 21:11:22 +0000 (-0500) Subject: tweaking json db import script X-Git-Tag: release-20150131~550 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=c2abc8c41074f0541a27a491e8a6750ec77643f8;p=oweals%2Fkarmaworld.git tweaking json db import script --- diff --git a/bin/import_json/run.py b/bin/import_json/run.py index fd98853..43c2ce7 100644 --- a/bin/import_json/run.py +++ b/bin/import_json/run.py @@ -61,12 +61,16 @@ for note in note_dicts: fix_file_path(note) + # Import from json print 'updating %i schools' % len(school_dicts) for school in school_dicts: s = School(**school) s.save() +# Only Save this scool if we actually need it. +arbitrary_school = School(name='No School', slug='no_school') + print 'updating %i courses' % len(course_dicts) for course in course_dicts: course['updated_at'] = datetime.datetime.utcnow() @@ -75,7 +79,8 @@ for course in course_dicts: # Somc courses have no school_id using arbitrary one for these if not course['school_id']: print 'Using arbitrary school_id for course id:', course['id'], '-', course['name'] - course['school_id'] = School.objects.all()[0].id + course['school_id'] = arbitrary_school.id + arbitrary_school.save() c = Course(**course) c.save() @@ -83,11 +88,16 @@ for course in course_dicts: # Import the Notes print 'updating %i notes' % len(note_dicts) + +arbitrary_course = Course(name='No Course', slug='no_course', school=arbitrary_school) + for note in note_dicts: if not note['course_id']: print 'using arbitrary course id for note_id:', note['id'], '-', note['name'] - note['course_id'] = Course.objects.all()[0].id + note['course_id'] = arbitrary_course.id + arbitrary_school.save() + arbitrary_course.save() if 'slug' not in note: path, fn = split(note['file_path'])