Skip to content

Commit c3b6912

Browse files
authored
Fix specialisation enrolment to recover from single failure (#95)
* Fix specialisation enrolment to recover from single failure * Modify error message for clarity
1 parent f1c073d commit c3b6912

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lms/djangoapps/student_enrollment/enrollment.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,11 @@ def enroll(self):
220220
'crm_field': 'Specialisation_programme_id',
221221
'unexpected_value': student['Specialisation_programme_id'],
222222
'attempted_action': 'enroll specialisation',
223-
'message': ('Specialisation change field checked, but student'
224-
+ ' is already enrolled into the same specialisation')
223+
'message': ('Student is already enrolled into this specialisation')
225224
}
226225
)
227-
# return in order to prevent reenrollment
228-
return
226+
# continue in order to prevent reenrollment
227+
continue
229228

230229
# otherwise continue with enrollment
231230
try:
@@ -252,11 +251,13 @@ def enroll(self):
252251
#
253252
# If specialisation change, get the previous enrolled specialisation
254253
if specialization_change:
254+
error_flag = False
255255
for program in user.program_set.all():
256256
if program.specialization_for:
257257
# if already enrolled into same specialisation,
258258
# trigger exception email and stop further process
259259
if program == specialization:
260+
error_flag = True
260261
log.exception(
261262
"**Student %s already enrolled in this specialization: %s**",
262263
student['Email'], specialization_to_enroll
@@ -272,11 +273,13 @@ def enroll(self):
272273
+ ' is already enrolled into the same specialisation')
273274
}
274275
)
275-
# return in order to prevent reenrollment
276-
return
276+
break
277277
# otherwise, set current specialisation as current program (to unenroll)
278278
else:
279279
current_program = program.program_code
280+
# continue to prevent reenrollment
281+
if error_flag:
282+
continue
280283

281284
# Enroll the student in the (new) specialisation
282285
specialization_enrollment_status = specialization.enroll_student_in_program(

0 commit comments

Comments
 (0)