@@ -740,9 +740,27 @@ def retrieve(self, request, *args, **kwargs):
740740 allocation_count = 1 # Dref Application is always the first allocation
741741 public = code not in self .get_nonsuperusers_excluded_codes ()
742742 a = ["First" , "Second" , "Third" , "Fourth" , "Fifth" , "Sixth" , "Seventh" , "Eighth" , "Ninth" , "Tenth" ]
743- for instance in instances :
743+
744+ # is_latest_stage: the last APPROVED-status instance and next instance either absent or not APPROVED
745+ latest_index = None
746+ for i , inst in enumerate (instances ):
747+ if getattr (inst , "status" , None ) == Dref .Status .APPROVED :
748+ next_inst = instances [i + 1 ] if i + 1 < len (instances ) else None
749+ if next_inst is None or getattr (next_inst , "status" , None ) != Dref .Status .APPROVED :
750+ latest_index = i
751+ # Build serialized rows with flag
752+ for i , instance in enumerate (instances ):
753+ is_latest_stage = i == latest_index
744754 if isinstance (instance , Dref ):
745- serializer = Dref3Serializer (instance , context = {"stage" : "Application" , "allocation" : a [0 ], "public" : public })
755+ serializer = Dref3Serializer (
756+ instance ,
757+ context = {
758+ "stage" : "Application" ,
759+ "allocation" : a [0 ],
760+ "public" : public ,
761+ "is_latest_stage" : is_latest_stage ,
762+ },
763+ )
746764 elif isinstance (instance , DrefOperationalUpdate ):
747765 ops_update_count += 1
748766 if instance .additional_allocation and len (a ) > allocation_count :
@@ -753,15 +771,21 @@ def retrieve(self, request, *args, **kwargs):
753771 serializer = DrefOperationalUpdate3Serializer (
754772 instance ,
755773 context = {
756- "stage" : "Operational Update " + str ( ops_update_count ) ,
774+ "stage" : f "Operational Update { ops_update_count } " ,
757775 "allocation" : allocation ,
758776 "public" : public ,
777+ "is_latest_stage" : is_latest_stage ,
759778 },
760779 )
761780 elif isinstance (instance , DrefFinalReport ):
762781 serializer = DrefFinalReport3Serializer (
763782 instance ,
764- context = {"stage" : "Final Report" , "allocation" : "No allocation" , "public" : public },
783+ context = {
784+ "stage" : "Final Report" ,
785+ "allocation" : "No allocation" ,
786+ "public" : public ,
787+ "is_latest_stage" : is_latest_stage ,
788+ },
765789 )
766790 else :
767791 continue
0 commit comments