Skip to content
Snippets Groups Projects
Unverified Commit b9e5f35b authored by hamzamunir7300's avatar hamzamunir7300 Committed by GitHub
Browse files

Merge pull request #18527 from edx/LEARNER-5502

Learner 5502
parents 49a73b7f e00156c2
No related branches found
No related tags found
No related merge requests found
......@@ -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.')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment