@@ -36,34 +36,6 @@ def get_tags_for_stream_id(stream_id):
3636 else :
3737 return []
3838
39- # This, and several other utilities here, assume that there is only one active ballot for a document at any point in time.
40- # If that assumption is violated, they will only expose the most recently created ballot
41- def active_ballot (doc ):
42- """Returns the most recently created ballot if it isn't closed."""
43- ballot = doc .latest_event (BallotDocEvent , type = "created_ballot" )
44- open = ballot_open (doc ,ballot .ballot_type .slug ) if ballot else False
45- return ballot if open else None
46-
47-
48- def active_ballot_positions (doc , ballot = None ):
49- """Return dict mapping each active AD to a current ballot position (or None if they haven't voted)."""
50- active_ads = list (Person .objects .filter (role__name = "ad" , role__group__state = "active" ))
51- res = {}
52-
53- if not ballot :
54- ballot = doc .latest_event (BallotDocEvent , type = "created_ballot" )
55- positions = BallotPositionDocEvent .objects .filter (doc = doc , type = "changed_ballot_position" , ad__in = active_ads , ballot = ballot ).select_related ('ad' , 'pos' ).order_by ("-time" , "-id" )
56-
57- for pos in positions :
58- if pos .ad not in res :
59- res [pos .ad ] = pos
60-
61- for ad in active_ads :
62- if ad not in res :
63- res [ad ] = None
64-
65- return res
66-
6739def needed_ballot_positions (doc , active_positions ):
6840 '''Returns text answering the question "what does this document
6941 need to pass?". The return value is only useful if the document
@@ -102,20 +74,16 @@ def needed_ballot_positions(doc, active_positions):
10274
10375 return " " .join (answer )
10476
105- def ballot_open (doc , ballot_type_slug ):
106- e = doc .latest_event (BallotDocEvent , ballot_type__slug = ballot_type_slug )
107- return e and not e .type == "closed_ballot"
108-
10977def create_ballot_if_not_open (doc , by , ballot_type_slug ):
110- if not ballot_open (doc , ballot_type_slug ):
78+ if not doc . ballot_open (ballot_type_slug ):
11179 e = BallotDocEvent (type = "created_ballot" , by = by , doc = doc )
11280 e .ballot_type = BallotType .objects .get (doc_type = doc .type , slug = ballot_type_slug )
11381 e .desc = u'Created "%s" ballot' % e .ballot_type .name
11482 e .save ()
11583
11684def close_open_ballots (doc , by ):
11785 for t in BallotType .objects .filter (doc_type = doc .type_id ):
118- if ballot_open (doc , t .slug ):
86+ if doc . ballot_open (t .slug ):
11987 e = BallotDocEvent (type = "closed_ballot" , doc = doc , by = by )
12088 e .ballot_type = t
12189 e .desc = 'Closed "%s" ballot' % t .name
0 commit comments