@@ -518,50 +518,13 @@ def is_editable(self, user):
518
518
return True
519
519
return False
520
520
521
- @property
522
- def combined_check_state (self ):
523
- """Return the combined state for all checks.
524
-
525
- Generate the combined check's state for this patch. This check
526
- is one of the following, based on the value of each unique
527
- check:
528
-
529
- * failure, if any context's latest check reports as failure
530
- * warning, if any context's latest check reports as warning
531
- * pending, if there are no checks, or a context's latest
532
- Check reports as pending
533
- * success, if latest checks for all contexts reports as
534
- success
535
- """
536
- state_names = dict (Check .STATE_CHOICES )
537
- states = [check .state for check in self .checks ]
538
-
539
- if not states :
540
- return state_names [Check .STATE_PENDING ]
541
-
542
- for state in [Check .STATE_FAIL , Check .STATE_WARNING ,
543
- Check .STATE_PENDING ]: # order sensitive
544
- if state in states :
545
- return state_names [state ]
546
-
547
- return state_names [Check .STATE_SUCCESS ]
548
-
549
- @property
550
- def checks (self ):
551
- """Return the list of unique checks.
552
-
553
- Generate a list of checks associated with this patch for each
554
- type of Check. Only "unique" checks are considered,
555
- identified by their 'context' field. This means, given n
556
- checks with the same 'context', the newest check is the only
557
- one counted regardless of its value. The end result will be a
558
- association of types to number of unique checks for said
559
- type.
560
- """
521
+ @staticmethod
522
+ def filter_unique_checks (checks ):
523
+ """Filter the provided checks to generate the unique list."""
561
524
unique = {}
562
525
duplicates = []
563
526
564
- for check in self . check_set . all () :
527
+ for check in checks :
565
528
ctx = check .context
566
529
user = check .user_id
567
530
@@ -588,7 +551,50 @@ def checks(self):
588
551
# prefetch_related.) So, do it 'by hand' in Python. We can
589
552
# also be confident that this won't be worse, seeing as we've
590
553
# just iterated over self.check_set.all() *anyway*.
591
- return [c for c in self .check_set .all () if c .id not in duplicates ]
554
+ return [c for c in checks if c .id not in duplicates ]
555
+
556
+ @property
557
+ def checks (self ):
558
+ """Return the list of unique checks.
559
+
560
+ Generate a list of checks associated with this patch for each
561
+ type of Check. Only "unique" checks are considered,
562
+ identified by their 'context' field. This means, given n
563
+ checks with the same 'context', the newest check is the only
564
+ one counted regardless of its value. The end result will be a
565
+ association of types to number of unique checks for said
566
+ type.
567
+ """
568
+ return self .filter_unique_checks (self .check_set .all ())
569
+
570
+ @property
571
+ def combined_check_state (self ):
572
+ """Return the combined state for all checks.
573
+
574
+ Generate the combined check's state for this patch. This check
575
+ is one of the following, based on the value of each unique
576
+ check:
577
+
578
+ * failure, if any context's latest check reports as failure
579
+ * warning, if any context's latest check reports as warning
580
+ * pending, if there are no checks, or a context's latest check reports
581
+ as pending
582
+ * success, if latest checks for all contexts reports as success
583
+ """
584
+ state_names = dict (Check .STATE_CHOICES )
585
+ states = [check .state for check in self .checks ]
586
+
587
+ if not states :
588
+ return state_names [Check .STATE_PENDING ]
589
+
590
+ # order sensitive
591
+ for state in (
592
+ Check .STATE_FAIL , Check .STATE_WARNING , Check .STATE_PENDING ,
593
+ ):
594
+ if state in states :
595
+ return state_names [state ]
596
+
597
+ return state_names [Check .STATE_SUCCESS ]
592
598
593
599
@property
594
600
def check_count (self ):
0 commit comments