From 1be33651b08ac4fc20cad3ea962c5ca3468c4b53 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Fri, 10 Jan 2014 13:18:39 -0500 Subject: [PATCH] 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. --- .../student/management/commands/transfer_students.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/common/djangoapps/student/management/commands/transfer_students.py b/common/djangoapps/student/management/commands/transfer_students.py index e986e7d192..38585961aa 100644 --- a/common/djangoapps/student/management/commands/transfer_students.py +++ b/common/djangoapps/student/management/commands/transfer_students.py @@ -34,18 +34,21 @@ class Command(BaseCommand): dest = options['dest_course'] source_students = User.objects.filter( - courseenrollment__course_id=source, - courseenrollment__is_active=True) + courseenrollment__course_id=source) for user in source_students: print("Moving {}.".format(user.username)) # Find the old enrollment. enrollment = CourseEnrollment.objects.get(user=user, course_id=source) + # Move the Student between the classes. mode = enrollment.mode 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': try: @@ -56,9 +59,6 @@ class Command(BaseCommand): print("No certificate for {}".format(user)) continue - new_enrollment = CourseEnrollment.objects.get(user=user, - course_id=dest) - certificate_item.course_id = dest certificate_item.course_enrollment = new_enrollment certificate_item.save()