@@ -1271,63 +1271,70 @@ def settings_handler(request, course_key_string): # lint-amnesty, pylint: disab
12711271 )
12721272 # For every other possible method type submitted by the caller...
12731273 else :
1274- # if pre-requisite course feature is enabled set pre-requisite course
1275- if is_prerequisite_courses_enabled ():
1276- prerequisite_course_keys = request .json .get ('pre_requisite_courses' , [])
1277- if prerequisite_course_keys :
1278- if not all (is_valid_course_key (course_key ) for course_key in prerequisite_course_keys ):
1279- return JsonResponseBadRequest ({"error" : _ ("Invalid prerequisite course key" )})
1280- set_prerequisite_courses (course_key , prerequisite_course_keys )
1281- else :
1282- # None is chosen, so remove the course prerequisites
1283- course_milestones = milestones_api .get_course_milestones (
1284- course_key = course_key ,
1285- relationship = "requires" ,
1286- )
1287- for milestone in course_milestones :
1288- entrance_exam_namespace = generate_milestone_namespace (
1289- get_namespace_choices ().get ('ENTRANCE_EXAM' ),
1290- course_key
1291- )
1292- if milestone ["namespace" ] != entrance_exam_namespace :
1293- remove_prerequisite_course (course_key , milestone )
1294-
1295- # If the entrance exams feature has been enabled, we'll need to check for some
1296- # feature-specific settings and handle them accordingly
1297- # We have to be careful that we're only executing the following logic if we actually
1298- # need to create or delete an entrance exam from the specified course
1299- if core_toggles .ENTRANCE_EXAMS .is_enabled ():
1300- course_entrance_exam_present = course_block .entrance_exam_enabled
1301- entrance_exam_enabled = request .json .get ('entrance_exam_enabled' , '' ) == 'true'
1302- ee_min_score_pct = request .json .get ('entrance_exam_minimum_score_pct' , None )
1303- # If the entrance exam box on the settings screen has been checked...
1304- if entrance_exam_enabled :
1305- # Load the default minimum score threshold from settings, then try to override it
1306- entrance_exam_minimum_score_pct = float (settings .ENTRANCE_EXAM_MIN_SCORE_PCT )
1307- if ee_min_score_pct :
1308- entrance_exam_minimum_score_pct = float (ee_min_score_pct )
1309- if entrance_exam_minimum_score_pct .is_integer ():
1310- entrance_exam_minimum_score_pct = entrance_exam_minimum_score_pct / 100
1311- # If there's already an entrance exam defined, we'll update the existing one
1312- if course_entrance_exam_present :
1313- exam_data = {
1314- 'entrance_exam_minimum_score_pct' : entrance_exam_minimum_score_pct
1315- }
1316- update_entrance_exam (request , course_key , exam_data )
1317- # If there's no entrance exam defined, we'll create a new one
1318- else :
1319- create_entrance_exam (request , course_key , entrance_exam_minimum_score_pct )
1320-
1321- # If the entrance exam box on the settings screen has been unchecked,
1322- # and the course has an entrance exam attached...
1323- elif not entrance_exam_enabled and course_entrance_exam_present :
1324- delete_entrance_exam (request , course_key )
1325-
1326- # Perform the normal update workflow for the CourseDetails model
1327- return JsonResponse (
1328- CourseDetails .update_from_json (course_key , request .json , request .user ),
1329- encoder = CourseSettingsEncoder
1274+ return update_course_details_settings (course_key , course_block , request )
1275+
1276+
1277+ def update_course_details_settings (course_key , course_block : CourseBlock , request ):
1278+ """
1279+ Helper function to update course details settings from API data
1280+ """
1281+ # if pre-requisite course feature is enabled set pre-requisite course
1282+ if is_prerequisite_courses_enabled ():
1283+ prerequisite_course_keys = request .json .get ('pre_requisite_courses' , [])
1284+ if prerequisite_course_keys :
1285+ if not all (is_valid_course_key (course_key ) for course_key in prerequisite_course_keys ):
1286+ return JsonResponseBadRequest ({"error" : _ ("Invalid prerequisite course key" )})
1287+ set_prerequisite_courses (course_key , prerequisite_course_keys )
1288+ else :
1289+ # None is chosen, so remove the course prerequisites
1290+ course_milestones = milestones_api .get_course_milestones (
1291+ course_key = course_key ,
1292+ relationship = "requires" ,
1293+ )
1294+ for milestone in course_milestones :
1295+ entrance_exam_namespace = generate_milestone_namespace (
1296+ get_namespace_choices ().get ('ENTRANCE_EXAM' ),
1297+ course_key
13301298 )
1299+ if milestone ["namespace" ] != entrance_exam_namespace :
1300+ remove_prerequisite_course (course_key , milestone )
1301+
1302+ # If the entrance exams feature has been enabled, we'll need to check for some
1303+ # feature-specific settings and handle them accordingly
1304+ # We have to be careful that we're only executing the following logic if we actually
1305+ # need to create or delete an entrance exam from the specified course
1306+ if core_toggles .ENTRANCE_EXAMS .is_enabled ():
1307+ course_entrance_exam_present = course_block .entrance_exam_enabled
1308+ entrance_exam_enabled = request .json .get ('entrance_exam_enabled' , '' ) == 'true'
1309+ ee_min_score_pct = request .json .get ('entrance_exam_minimum_score_pct' , None )
1310+ # If the entrance exam box on the settings screen has been checked...
1311+ if entrance_exam_enabled :
1312+ # Load the default minimum score threshold from settings, then try to override it
1313+ entrance_exam_minimum_score_pct = float (settings .ENTRANCE_EXAM_MIN_SCORE_PCT )
1314+ if ee_min_score_pct :
1315+ entrance_exam_minimum_score_pct = float (ee_min_score_pct )
1316+ if entrance_exam_minimum_score_pct .is_integer ():
1317+ entrance_exam_minimum_score_pct = entrance_exam_minimum_score_pct / 100
1318+ # If there's already an entrance exam defined, we'll update the existing one
1319+ if course_entrance_exam_present :
1320+ exam_data = {
1321+ 'entrance_exam_minimum_score_pct' : entrance_exam_minimum_score_pct
1322+ }
1323+ update_entrance_exam (request , course_key , exam_data )
1324+ # If there's no entrance exam defined, we'll create a new one
1325+ else :
1326+ create_entrance_exam (request , course_key , entrance_exam_minimum_score_pct )
1327+
1328+ # If the entrance exam box on the settings screen has been unchecked,
1329+ # and the course has an entrance exam attached...
1330+ elif not entrance_exam_enabled and course_entrance_exam_present :
1331+ delete_entrance_exam (request , course_key )
1332+
1333+ # Perform the normal update workflow for the CourseDetails model
1334+ return JsonResponse (
1335+ CourseDetails .update_from_json (course_key , request .json , request .user ),
1336+ encoder = CourseSettingsEncoder
1337+ )
13311338
13321339
13331340@login_required
0 commit comments