Skip to content

Commit c44363b

Browse files
VirginiaDooleyVirginia Dooley
authored andcommitted
Mark any remaining uncontested candidates as elected
1 parent 42a7d1c commit c44363b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from django.db import migrations
2+
3+
4+
def mark_uncontested_winners(apps, schema_editor):
5+
"""
6+
If the election is uncontested mark all candidates as elected
7+
"""
8+
Ballot = apps.get_model("candidates", "Ballot")
9+
locked_ballots = Ballot.objects.filter(candidates_locked=True)
10+
uncontested_ballots = []
11+
for ballot in locked_ballots:
12+
if ballot.winner_count >= ballot.membership_set.count():
13+
uncontested_ballots.append(ballot)
14+
ballot.membership_set.update(elected=True)
15+
16+
17+
class Migration(migrations.Migration):
18+
dependencies = [
19+
("people", "0044_populate_biography_timestamp"),
20+
]
21+
22+
operations = [
23+
migrations.RunPython(
24+
code=mark_uncontested_winners,
25+
reverse_code=migrations.RunPython.noop,
26+
)
27+
]

0 commit comments

Comments
 (0)