37769-vm/fix_voted_voters.py
2026-05-30 08:01:02 +00:00

25 lines
1.1 KiB
Python

from core.models import Voter, ScheduledCall
import django
def fix_voter_stats():
# Fix 1: Voted = True -> Target Door Visit = False
voters_to_fix = Voter.objects.filter(voted=True, target_door_visit=True)
count1 = voters_to_fix.count()
voters_to_fix.update(target_door_visit=False)
print(f"Fixed {count1} voters: voted=True, but had target_door_visit=True")
# Fix 2: Voted = True -> Call Queue Status = no_call_required
voters_to_fix_calls = Voter.objects.filter(voted=True).exclude(call_queue_status='no_call_required')
count2 = voters_to_fix_calls.count()
voters_to_fix_calls.update(call_queue_status='no_call_required')
print(f"Fixed {count2} voters: voted=True, but had call_queue_status != 'no_call_required'")
# Fix 3: Cancel pending calls for those who voted
pending_calls = ScheduledCall.objects.filter(voter__voted=True, status='pending')
count3 = pending_calls.count()
pending_calls.update(status='cancelled')
print(f"Cancelled {count3} pending calls for voters who have already voted.")
if __name__ == "__main__":
fix_voter_stats()