From 102234c0a5530d1e91e5f4457882a7de76f596bc Mon Sep 17 00:00:00 2001 From: Bryan Date: Tue, 7 Jan 2014 19:08:04 -0500 Subject: [PATCH] Added department, professor models, updated courses as appropriate. OCW importer uses new models. --- karmaworld/apps/courses/admin.py | 6 + ...course_academic_year__add_field_course.py} | 0 ...soraffiliation__add_unique_professoraff.py | 104 ++++++++++++++++++ ...unique_professortaught_professor_course.py | 91 +++++++++++++++ .../0009_auto__del_field_course_professor.py | 81 ++++++++++++++ karmaworld/apps/courses/models.py | 47 +++++++- .../management/commands/import_ocw_json.py | 28 ++++- 7 files changed, 352 insertions(+), 5 deletions(-) rename karmaworld/apps/courses/migrations/{0005_auto__add_department__del_field_course_academic_year__add_field_course.py => 0006_auto__add_department__del_field_course_academic_year__add_field_course.py} (100%) create mode 100644 karmaworld/apps/courses/migrations/0007_auto__add_professor__add_professoraffiliation__add_unique_professoraff.py create mode 100644 karmaworld/apps/courses/migrations/0008_auto__add_professortaught__add_unique_professortaught_professor_course.py create mode 100644 karmaworld/apps/courses/migrations/0009_auto__del_field_course_professor.py diff --git a/karmaworld/apps/courses/admin.py b/karmaworld/apps/courses/admin.py index b0eb89f..902333b 100644 --- a/karmaworld/apps/courses/admin.py +++ b/karmaworld/apps/courses/admin.py @@ -5,7 +5,10 @@ from django.contrib import admin +from karmaworld.apps.courses.models import School from karmaworld.apps.courses.models import Course +from karmaworld.apps.courses.models import Professor +from karmaworld.apps.courses.models import ProfessorAffiliation class CourseAdmin(admin.ModelAdmin): """ an Admin handler for the Course model that handles fk search """ @@ -14,4 +17,7 @@ class CourseAdmin(admin.ModelAdmin): 'fk': ['school'] } +admin.site.register(School) +admin.site.register(Professor) admin.site.register(Course, CourseAdmin) +admin.site.register(ProfessorAffiliation) diff --git a/karmaworld/apps/courses/migrations/0005_auto__add_department__del_field_course_academic_year__add_field_course.py b/karmaworld/apps/courses/migrations/0006_auto__add_department__del_field_course_academic_year__add_field_course.py similarity index 100% rename from karmaworld/apps/courses/migrations/0005_auto__add_department__del_field_course_academic_year__add_field_course.py rename to karmaworld/apps/courses/migrations/0006_auto__add_department__del_field_course_academic_year__add_field_course.py diff --git a/karmaworld/apps/courses/migrations/0007_auto__add_professor__add_professoraffiliation__add_unique_professoraff.py b/karmaworld/apps/courses/migrations/0007_auto__add_professor__add_professoraffiliation__add_unique_professoraff.py new file mode 100644 index 0000000..5eac9d2 --- /dev/null +++ b/karmaworld/apps/courses/migrations/0007_auto__add_professor__add_professoraffiliation__add_unique_professoraff.py @@ -0,0 +1,104 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding model 'Professor' + db.create_table('courses_professor', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('name', self.gf('django.db.models.fields.CharField')(max_length=255)), + ('email', self.gf('django.db.models.fields.EmailField')(max_length=75, null=True, blank=True)), + )) + db.send_create_signal('courses', ['Professor']) + + # Adding model 'ProfessorAffiliation' + db.create_table('courses_professoraffiliation', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('professor', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['courses.Professor'])), + ('department', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['courses.Department'])), + )) + db.send_create_signal('courses', ['ProfessorAffiliation']) + + # Adding unique constraint on 'ProfessorAffiliation', fields ['professor', 'department'] + db.create_unique('courses_professoraffiliation', ['professor_id', 'department_id']) + + # Adding field 'Course.professor' + db.add_column('courses_course', 'professor', + self.gf('django.db.models.fields.related.ForeignKey')(to=orm['courses.Professor'], null=True, blank=True), + keep_default=False) + + + def backwards(self, orm): + # Removing unique constraint on 'ProfessorAffiliation', fields ['professor', 'department'] + db.delete_unique('courses_professoraffiliation', ['professor_id', 'department_id']) + + # Deleting model 'Professor' + db.delete_table('courses_professor') + + # Deleting model 'ProfessorAffiliation' + db.delete_table('courses_professoraffiliation') + + # Deleting field 'Course.professor' + db.delete_column('courses_course', 'professor_id') + + + models = { + 'courses.course': { + 'Meta': {'ordering': "['-file_count', 'school', 'name']", 'unique_together': "(('school', 'name', 'instructor_name'),)", 'object_name': 'Course'}, + 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'department': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Department']", 'null': 'True', 'blank': 'True'}), + 'desc': ('django.db.models.fields.TextField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'}), + 'file_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'flags': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'instructor_email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}), + 'instructor_name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'professor': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Professor']", 'null': 'True', 'blank': 'True'}), + 'school': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.School']"}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}), + 'updated_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.utcnow'}), + 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'}) + }, + 'courses.department': { + 'Meta': {'object_name': 'Department'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'school': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.School']"}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}), + 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'}) + }, + 'courses.professor': { + 'Meta': {'object_name': 'Professor'}, + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + 'courses.professoraffiliation': { + 'Meta': {'unique_together': "(('professor', 'department'),)", 'object_name': 'ProfessorAffiliation'}, + 'department': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Department']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'professor': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Professor']"}) + }, + 'courses.school': { + 'Meta': {'ordering': "['-file_count', '-priority', 'name']", 'object_name': 'School'}, + 'alias': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'facebook_id': ('django.db.models.fields.BigIntegerField', [], {'null': 'True', 'blank': 'True'}), + 'file_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'hashtag': ('django.db.models.fields.CharField', [], {'max_length': '16', 'unique': 'True', 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'location': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'priority': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}), + 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'blank': 'True'}), + 'usde_id': ('django.db.models.fields.BigIntegerField', [], {'null': 'True', 'blank': 'True'}) + } + } + + complete_apps = ['courses'] diff --git a/karmaworld/apps/courses/migrations/0008_auto__add_professortaught__add_unique_professortaught_professor_course.py b/karmaworld/apps/courses/migrations/0008_auto__add_professortaught__add_unique_professortaught_professor_course.py new file mode 100644 index 0000000..e1ada97 --- /dev/null +++ b/karmaworld/apps/courses/migrations/0008_auto__add_professortaught__add_unique_professortaught_professor_course.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding model 'ProfessorTaught' + db.create_table('courses_professortaught', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('professor', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['courses.Professor'])), + ('course', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['courses.Course'])), + )) + db.send_create_signal('courses', ['ProfessorTaught']) + + # Adding unique constraint on 'ProfessorTaught', fields ['professor', 'course'] + db.create_unique('courses_professortaught', ['professor_id', 'course_id']) + + + def backwards(self, orm): + # Removing unique constraint on 'ProfessorTaught', fields ['professor', 'course'] + db.delete_unique('courses_professortaught', ['professor_id', 'course_id']) + + # Deleting model 'ProfessorTaught' + db.delete_table('courses_professortaught') + + + models = { + 'courses.course': { + 'Meta': {'ordering': "['-file_count', 'school', 'name']", 'unique_together': "(('school', 'name', 'instructor_name'),)", 'object_name': 'Course'}, + 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'department': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Department']", 'null': 'True', 'blank': 'True'}), + 'desc': ('django.db.models.fields.TextField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'}), + 'file_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'flags': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'instructor_email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}), + 'instructor_name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'professor': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Professor']", 'null': 'True', 'blank': 'True'}), + 'school': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.School']"}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}), + 'updated_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.utcnow'}), + 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'}) + }, + 'courses.department': { + 'Meta': {'object_name': 'Department'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'school': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.School']"}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}), + 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'}) + }, + 'courses.professor': { + 'Meta': {'object_name': 'Professor'}, + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + 'courses.professoraffiliation': { + 'Meta': {'unique_together': "(('professor', 'department'),)", 'object_name': 'ProfessorAffiliation'}, + 'department': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Department']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'professor': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Professor']"}) + }, + 'courses.professortaught': { + 'Meta': {'unique_together': "(('professor', 'course'),)", 'object_name': 'ProfessorTaught'}, + 'course': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Course']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'professor': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Professor']"}) + }, + 'courses.school': { + 'Meta': {'ordering': "['-file_count', '-priority', 'name']", 'object_name': 'School'}, + 'alias': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'facebook_id': ('django.db.models.fields.BigIntegerField', [], {'null': 'True', 'blank': 'True'}), + 'file_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'hashtag': ('django.db.models.fields.CharField', [], {'max_length': '16', 'unique': 'True', 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'location': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'priority': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}), + 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'blank': 'True'}), + 'usde_id': ('django.db.models.fields.BigIntegerField', [], {'null': 'True', 'blank': 'True'}) + } + } + + complete_apps = ['courses'] \ No newline at end of file diff --git a/karmaworld/apps/courses/migrations/0009_auto__del_field_course_professor.py b/karmaworld/apps/courses/migrations/0009_auto__del_field_course_professor.py new file mode 100644 index 0000000..eb5b05f --- /dev/null +++ b/karmaworld/apps/courses/migrations/0009_auto__del_field_course_professor.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Deleting field 'Course.professor' + db.delete_column('courses_course', 'professor_id') + + + def backwards(self, orm): + # Adding field 'Course.professor' + db.add_column('courses_course', 'professor', + self.gf('django.db.models.fields.related.ForeignKey')(to=orm['courses.Professor'], null=True, blank=True), + keep_default=False) + + + models = { + 'courses.course': { + 'Meta': {'ordering': "['-file_count', 'school', 'name']", 'unique_together': "(('school', 'name', 'instructor_name'),)", 'object_name': 'Course'}, + 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'department': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Department']", 'null': 'True', 'blank': 'True'}), + 'desc': ('django.db.models.fields.TextField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'}), + 'file_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'flags': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'instructor_email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}), + 'instructor_name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'school': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.School']"}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}), + 'updated_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.utcnow'}), + 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'}) + }, + 'courses.department': { + 'Meta': {'object_name': 'Department'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'school': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.School']"}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}), + 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'}) + }, + 'courses.professor': { + 'Meta': {'object_name': 'Professor'}, + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + 'courses.professoraffiliation': { + 'Meta': {'unique_together': "(('professor', 'department'),)", 'object_name': 'ProfessorAffiliation'}, + 'department': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Department']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'professor': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Professor']"}) + }, + 'courses.professortaught': { + 'Meta': {'unique_together': "(('professor', 'course'),)", 'object_name': 'ProfessorTaught'}, + 'course': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Course']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'professor': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['courses.Professor']"}) + }, + 'courses.school': { + 'Meta': {'ordering': "['-file_count', '-priority', 'name']", 'object_name': 'School'}, + 'alias': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'facebook_id': ('django.db.models.fields.BigIntegerField', [], {'null': 'True', 'blank': 'True'}), + 'file_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'hashtag': ('django.db.models.fields.CharField', [], {'max_length': '16', 'unique': 'True', 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'location': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'priority': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}), + 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'blank': 'True'}), + 'usde_id': ('django.db.models.fields.BigIntegerField', [], {'null': 'True', 'blank': 'True'}) + } + } + + complete_apps = ['courses'] \ No newline at end of file diff --git a/karmaworld/apps/courses/models.py b/karmaworld/apps/courses/models.py index 56fb2d8..60ceec1 100644 --- a/karmaworld/apps/courses/models.py +++ b/karmaworld/apps/courses/models.py @@ -19,6 +19,33 @@ from karmaworld.apps.schools.models import Department from karmaworld.apps.professors.models import Professor +class Professor(models.Model): + """ + Track professors for courses. + """ + name = models.CharField(max_length=255) + email = models.EmailField(blank=True, null=True) + + def __unicode__(self): + return u'Professor: {0}'.format(self.name) + + +class ProfessorAffiliation(models.Model): + """ + Track professors for departments. (many-to-many) + """ + professor = models.ForeignKey(Professor) + department = models.ForeignKey(Department) + + def __unicode__(self): + return u'Professor {0} working for {1}'.format(self.professor.name, self.department.name) + + class Meta: + # many-to-many across both fields, + # but (prof, dept) as a tuple should only appear once. + unique_together = ('professor', 'department',) + + class Course(models.Model): """ First class object that contains many notes.Note objects """ # Core metadata @@ -34,6 +61,7 @@ class Course(models.Model): desc = models.TextField(max_length=511, blank=True, null=True) url = models.URLField(max_length=511, blank=True, null=True) + # instructor_* is vestigial, replaced by Professor+ProfessorTaught models. instructor_name = models.CharField(max_length=255, blank=True, null=True) instructor_email = models.EmailField(blank=True, null=True) @@ -79,7 +107,24 @@ class Course(models.Model): self.save() +class ProfessorTaught(models.Model): + """ + Track professors teaching courses. (many-to-many) + """ + professor = models.ForeignKey(Professor) + course = models.ForeignKey(Course) + + def __unicode__(self): + return u'Professor {0} taught {1}'.format(self.professor.name, self.course.name) + + class Meta: + # many-to-many across both fields, + # but (prof, course) as a tuple should only appear once. + unique_together = ('professor', 'course',) + + # Enforce unique constraints even when we're using a database like # SQLite that doesn't understand them auto_add_check_unique_together(Course) - +auto_add_check_unique_together(ProfessorAffiliation) +auto_add_check_unique_together(ProfessorTaught) diff --git a/karmaworld/apps/notes/management/commands/import_ocw_json.py b/karmaworld/apps/notes/management/commands/import_ocw_json.py index 660be7f..3fc2459 100644 --- a/karmaworld/apps/notes/management/commands/import_ocw_json.py +++ b/karmaworld/apps/notes/management/commands/import_ocw_json.py @@ -9,8 +9,11 @@ import requests from apps.notes.models import Note from apps.notes.gdrive import convert_raw_document from apps.courses.models import Course -from apps.schools.models import School -from apps.schools.models import Department +from apps.courses.models import School +from apps.courses.models import Professor +from apps.courses.models import Department +from apps.courses.models import ProfessorTaught +from apps.courses.models import ProfessorAffiliation from apps.licenses.models import License from apps.document_upload.models import RawDocument from django.core.management.base import BaseCommand @@ -44,7 +47,10 @@ class Command(BaseCommand): # for now, assume license is the default OCW license: CC-BY-NC 3 # TODO for later, do something more clever. - dblicense = License.objects.filter(name='cc-by-nc-3.0')[0] + dblicense = License.objects.get_or_create( + name='cc-by-nc-3.0', + html='Creative Commons License' + )[0] # build Filepicker upload URL # http://stackoverflow.com/questions/14115280/store-files-to-filepicker-io-from-the-command-line @@ -75,6 +81,16 @@ class Command(BaseCommand): # process courses for course in parsed['courses']: + # Assume first hit is always right. Solving the identity + # problem by name alone will always be a fool's errand. + dbprof = Professor.objects.get_or_create(name=course['professor'])[0] + + # Associate the professor with the department. + # (no need to track the result) + ProfessorAffiliation.objects.get_or_create( + professor=dbprof, + department=dbdept) + # Extract the course info course_info = { 'name': course['courseTitle'], @@ -83,10 +99,14 @@ class Command(BaseCommand): } # Create or Find the Course object. dbcourse = Course.objects.get_or_create(**course_info)[0] - dbcourse.department = dbdept; + dbcourse.professor = dbprof dbcourse.save() print "Course is in the database: {0}".format(dbcourse.name) + ProfessorTaught.objects.get_or_create( + professor=dbprof, + course=dbcourse) + if 'noteLinks' not in course: print "No Notes in course." continue -- 2.25.1