@@ -122,7 +122,7 @@ def get_state(self, state_type=None):
122122
123123 if not hasattr (self , "state_cache" ) or self .state_cache == None :
124124 self .state_cache = {}
125- for s in self .states .all ().select_related ():
125+ for s in self .states .all ().select_related ("type" ):
126126 self .state_cache [s .type_id ] = s
127127
128128 return self .state_cache .get (state_type , None )
@@ -149,8 +149,8 @@ def ballot_open(self, ballot_type_slug):
149149
150150 def active_ballot (self ):
151151 """Returns the most recently created ballot if it isn't closed."""
152- ballot = self .latest_event (BallotDocEvent , type = "created_ballot" )
153- if ballot and self . ballot_open ( ballot .ballot_type . slug ) :
152+ ballot = self .latest_event (BallotDocEvent , type__in = ( "created_ballot" , "closed_ballot" ) )
153+ if ballot and ballot .type == "created_ballot" :
154154 return ballot
155155 else :
156156 return None
@@ -616,17 +616,15 @@ def active_ad_positions(self):
616616 active_ads = list (Person .objects .filter (role__name = "ad" , role__group__state = "active" ))
617617 res = {}
618618
619- if self .doc .latest_event (BallotDocEvent , type = "created_ballot" ) == self :
620-
621- positions = BallotPositionDocEvent .objects .filter (type = "changed_ballot_position" ,ad__in = active_ads , ballot = self ).select_related ('ad' , 'pos' ).order_by ("-time" , "-id" )
622-
623- for pos in positions :
624- if pos .ad not in res :
625- res [pos .ad ] = pos
626-
627- for ad in active_ads :
628- if ad not in res :
629- res [ad ] = None
619+ positions = BallotPositionDocEvent .objects .filter (type = "changed_ballot_position" ,ad__in = active_ads , ballot = self ).select_related ('ad' , 'pos' ).order_by ("-time" , "-id" )
620+
621+ for pos in positions :
622+ if pos .ad not in res :
623+ res [pos .ad ] = pos
624+
625+ for ad in active_ads :
626+ if ad not in res :
627+ res [ad ] = None
630628 return res
631629
632630 def all_positions (self ):
0 commit comments