Commit 912db991 by Brandon DeRosier

Fix CCX 0002 migration

(cherry picked from commit 558b93fdeaaf72d02e050808698b2015e123a01c)
parent 34526ddf
...@@ -3,6 +3,7 @@ from south.utils import datetime_utils as datetime ...@@ -3,6 +3,7 @@ from south.utils import datetime_utils as datetime
from south.db import db from south.db import db
from south.v2 import DataMigration from south.v2 import DataMigration
from django.db import models from django.db import models
from opaque_keys import InvalidKeyError
class Migration(DataMigration): class Migration(DataMigration):
...@@ -12,11 +13,14 @@ class Migration(DataMigration): ...@@ -12,11 +13,14 @@ class Migration(DataMigration):
memberships = orm['ccx.CcxMembership'].objects.select_related('ccx', 'student').all() memberships = orm['ccx.CcxMembership'].objects.select_related('ccx', 'student').all()
for membership in memberships: for membership in memberships:
ccx = membership.ccx ccx = membership.ccx
course_key = CCXLocator.from_course_locator(ccx.course_id, ccx.id) try:
enrollment, created = orm['student.CourseEnrollment'].objects.get_or_create( course_key = CCXLocator.from_course_locator(ccx.course_id, ccx.id)
enrollment, created = orm['student.CourseEnrollment'].objects.get_or_create(
user=membership.student, user=membership.student,
course_id=course_key, course_id=course_key,
) )
except InvalidKeyError:
membership.delete()
def backwards(self, orm): def backwards(self, orm):
......
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