Commit 1be33651 by Feanil Patel

CertificateItems should be updated for all course students.

Not just students that are currently active.  Students may have enrolled with verified certs, paid, gotten
a refund, and un-enrolled from the original course.  This function should now capture that.
parent 7d9b6a55
...@@ -34,18 +34,21 @@ class Command(BaseCommand): ...@@ -34,18 +34,21 @@ class Command(BaseCommand):
dest = options['dest_course'] dest = options['dest_course']
source_students = User.objects.filter( source_students = User.objects.filter(
courseenrollment__course_id=source, courseenrollment__course_id=source)
courseenrollment__is_active=True)
for user in source_students: for user in source_students:
print("Moving {}.".format(user.username)) print("Moving {}.".format(user.username))
# Find the old enrollment. # Find the old enrollment.
enrollment = CourseEnrollment.objects.get(user=user, enrollment = CourseEnrollment.objects.get(user=user,
course_id=source) course_id=source)
# Move the Student between the classes. # Move the Student between the classes.
mode = enrollment.mode mode = enrollment.mode
CourseEnrollment.unenroll(user,source) CourseEnrollment.unenroll(user,source)
CourseEnrollment.enroll(user, dest, mode=mode) new_enrollment = CourseEnrollment.enroll(user, dest, mode=mode)
if not enrollment.is_active:
CourseEnrollment.unenroll(user,dest)
if mode == 'verified': if mode == 'verified':
try: try:
...@@ -56,9 +59,6 @@ class Command(BaseCommand): ...@@ -56,9 +59,6 @@ class Command(BaseCommand):
print("No certificate for {}".format(user)) print("No certificate for {}".format(user))
continue continue
new_enrollment = CourseEnrollment.objects.get(user=user,
course_id=dest)
certificate_item.course_id = dest certificate_item.course_id = dest
certificate_item.course_enrollment = new_enrollment certificate_item.course_enrollment = new_enrollment
certificate_item.save() certificate_item.save()
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