def make_test_course():

  course = CourseraCourse()
  course.cid = 'introstats2'
  course.n_seq = 1 # '001'

  course.title = 'Introduction to Statistics'
  course.description = 'Introduction to Statistics is nice course!'

  course.start_date = datetime.date(2013, 4, 5)
  course.duration_in_weeks = 8
  # course.workload_in_hours_per_day = 3
  course.workload_in_hours_per_week = 3

  institution = Institution()
  institution.id = 10
  institution.name = 'Harvard Univ.'
  course.institutions = [institution] 

  professor =  Instructor()
  professor.id = 10
  professor.name = 'John Joey'
  professor.institution = institution
  course.instructors = [professor]

  category =  Category()
  category.id = 10
  category.name = 'Mathematics & Statistics'
  course.categories = [category]
  
  print 'course', course
  print 'Instructors', course.instructors.values()

  return course  
 def save_courses_subset_to_db(self):
   for i, course_subset in enumerate(self.courses_subset):
     #if course_subset.university == None:
       #continue
     try:
       print str(i+1).zfill(3), 'Saving to db', course_subset
     except UnicodeEncodeError:
       print str(i+1).zfill(3), 'Saving to db'
     course = CourseraCourse()
     course.cid = course_subset.cid
     course.n_seq = course_subset.get_n_seq()
     course.title = course_subset.title
     if course_subset.start_date != None:
       course.start_date = course_subset.start_date
     if course_subset.duration_in_weeks != None:
       course.duration_in_weeks = course_subset.duration_in_weeks
     #course.save()
     if course_subset.university != None:
       university_name = course_subset.university
       try:
         institution = Institution.objects.get(name=university_name)
       except Institution.DoesNotExist:
         institution = Institution()
         institution.name = university_name
         #institution.courseracourse_id = course.cid
         institution.save()
         print 'institution id', institution.id
         #CourseraCourse.objects.create(name=university_name)
       except AttributeError, e:
         print 'university_name', university_name
         print e
         #sys.exit(0)
         pass
       #course.in
       #course.institutions.add(institution.id)
     course.save()