@@ -382,85 +382,64 @@ def _grade(student, request, course, keep_raw_scores, field_data_cache, scores_c
382
382
# TODO This block is causing extra savepoints to be fired that are empty because no queries are executed
383
383
# during the loop. When refactoring this code please keep this outer_atomic call in mind and ensure we
384
384
# are not making unnecessary database queries.
385
- should_grade_section = any (
386
- descriptor .always_recalculate_grades for descriptor in section ['xmoduledescriptors' ]
387
- )
388
385
389
- # If there are no problems that always have to be regraded, check to
390
- # see if any of our locations are in the scores from the submissions
391
- # API. If scores exist, we have to calculate grades for this section.
392
- if not should_grade_section :
393
- should_grade_section = any (
394
- descriptor .location .to_deprecated_string () in submissions_scores
395
- for descriptor in section ['xmoduledescriptors' ]
386
+ # If we haven't seen a single problem in the section, we don't have
387
+ # to grade it at all! We can assume 0%
388
+ scores = []
389
+
390
+ def create_module (descriptor ):
391
+ """creates an XModule instance given a descriptor"""
392
+ # TODO: We need the request to pass into here. If we could forego that, our arguments
393
+ # would be simpler
394
+ return get_module_for_descriptor (
395
+ student , request , descriptor , field_data_cache , course .id , course = course
396
396
)
397
397
398
- if not should_grade_section :
399
- should_grade_section = any (
400
- descriptor . location in scores_client
401
- for descriptor in section [ 'xmoduledescriptors' ]
398
+ descendants = yield_dynamic_descriptor_descendants ( section_descriptor , student . id , create_module )
399
+ for module_descriptor in descendants :
400
+ user_access = has_access (
401
+ student , 'load' , module_descriptor , module_descriptor . location . course_key
402
402
)
403
+ if not user_access :
404
+ continue
403
405
404
- # If we haven't seen a single problem in the section, we don't have
405
- # to grade it at all! We can assume 0%
406
- if should_grade_section :
407
- scores = []
408
-
409
- def create_module (descriptor ):
410
- '''creates an XModule instance given a descriptor'''
411
- # TODO: We need the request to pass into here. If we could forego that, our arguments
412
- # would be simpler
413
- return get_module_for_descriptor (
414
- student , request , descriptor , field_data_cache , course .id , course = course
415
- )
406
+ (correct , total ) = get_score (
407
+ student ,
408
+ module_descriptor ,
409
+ create_module ,
410
+ scores_client ,
411
+ submissions_scores ,
412
+ max_scores_cache ,
413
+ )
414
+ if correct is None and total is None :
415
+ continue
416
416
417
- descendants = yield_dynamic_descriptor_descendants (section_descriptor , student .id , create_module )
418
- for module_descriptor in descendants :
419
- user_access = has_access (
420
- student , 'load' , module_descriptor , module_descriptor .location .course_key
421
- )
422
- if not user_access :
423
- continue
424
-
425
- (correct , total ) = get_score (
426
- student ,
427
- module_descriptor ,
428
- create_module ,
429
- scores_client ,
430
- submissions_scores ,
431
- max_scores_cache ,
432
- )
433
- if correct is None and total is None :
434
- continue
435
-
436
- if settings .GENERATE_PROFILE_SCORES : # for debugging!
437
- if total > 1 :
438
- correct = random .randrange (max (total - 2 , 1 ), total + 1 )
439
- else :
440
- correct = total
441
-
442
- graded = module_descriptor .graded
443
- if not total > 0 :
444
- # We simply cannot grade a problem that is 12/0, because we might need it as a percentage
445
- graded = False
446
-
447
- scores .append (
448
- Score (
449
- correct ,
450
- total ,
451
- graded ,
452
- module_descriptor .display_name_with_default ,
453
- module_descriptor .location
454
- )
417
+ if settings .GENERATE_PROFILE_SCORES : # for debugging!
418
+ if total > 1 :
419
+ correct = random .randrange (max (total - 2 , 1 ), total + 1 )
420
+ else :
421
+ correct = total
422
+
423
+ graded = module_descriptor .graded
424
+ if not total > 0 :
425
+ # We simply cannot grade a problem that is 12/0, because we might need it as a percentage
426
+ graded = False
427
+
428
+ scores .append (
429
+ Score (
430
+ correct ,
431
+ total ,
432
+ graded ,
433
+ module_descriptor .display_name_with_default ,
434
+ module_descriptor .location
455
435
)
436
+ )
456
437
457
- __ , graded_total = graders .aggregate_scores (scores , section_name )
458
- if keep_raw_scores :
459
- raw_scores += scores
460
- else :
461
- graded_total = Score (0.0 , 1.0 , True , section_name , None )
438
+ __ , graded_total = graders .aggregate_scores (scores , section_name )
439
+ if keep_raw_scores :
440
+ raw_scores += scores
462
441
463
- #Add the graded total to totaled_scores
442
+ # Add the graded total to totaled_scores
464
443
if graded_total .possible > 0 :
465
444
format_scores .append (graded_total )
466
445
else :
0 commit comments