From e00156c2774f9b89e609f16234c06ef165f27d69 Mon Sep 17 00:00:00 2001 From: Hamza Munir Date: Mon, 2 Jul 2018 22:16:05 +0500 Subject: [PATCH] Learners cannot process there Credit requests even though they are in the Credit mode. adding "credit mode" in change_enrollment management command to move the user to credit mode by running this command. LEARNER-5502 --- .../management/commands/change_enrollment.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/common/djangoapps/student/management/commands/change_enrollment.py b/common/djangoapps/student/management/commands/change_enrollment.py index e0f86e99b9..45ad35440f 100644 --- a/common/djangoapps/student/management/commands/change_enrollment.py +++ b/common/djangoapps/student/management/commands/change_enrollment.py @@ -10,6 +10,8 @@ from six import text_type from student.models import CourseEnrollment, User +from student.models import CourseEnrollmentAttribute + logger = logging.getLogger(__name__) # pylint: disable=invalid-name @@ -96,7 +98,7 @@ class Command(BaseCommand): self.report(error_users, success_users) - def update_enrollments(self, identifier, enrollment_args, options, error_users, success_users): + def update_enrollments(self, identifier, enrollment_args, options, error_users, success_users, enrollment_attrs=None): """ Update enrollments for a specific user identifier (email or username). """ users = options[identifier].split(",") @@ -111,10 +113,19 @@ class Command(BaseCommand): enrollment_args['user'] = User.objects.get(**user_args) enrollments = CourseEnrollment.objects.filter(**enrollment_args) + enrollment_attrs = [] with transaction.atomic(): for enrollment in enrollments: enrollment.update_enrollment(mode=options['to_mode']) enrollment.save() + if options['to_mode'] == 'credit': + enrollment_attrs.append({ + 'namespace': 'credit', + 'name': 'provider_id', + 'value': enrollment_args['course_id'].org, + }) + CourseEnrollmentAttribute.add_enrollment_attr(enrollment=enrollment, + data_list=enrollment_attrs) if options['noop']: raise RollbackException('Forced rollback.')