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

47 lines
1.6 KiB
Python

import sys
with open('core/models.py', 'r') as f:
content = f.read()
# Update update_target_door_visit_logic
# Add voted to relevant fields
content = content.replace(
"relevant = {'candidate_support', 'is_targeted', 'door_visit', 'address_street', 'city', 'state', 'zip_code'}",
"relevant = {'candidate_support', 'is_targeted', 'door_visit', 'address_street', 'city', 'state', 'zip_code', 'voted'}"
)
# Add voted check at the start of the logic
target_door_logic_start = """ # 1. If this voter was just updated to Supporting or Not Supporting, """
content = content.replace(
target_door_logic_start,
""" # 0. If this voter has voted, they are no longer a target for door visits.
if instance.voted:
if instance.target_door_visit:
Voter.objects.filter(pk=instance.pk).update(target_door_visit=False)
""" + target_door_logic_start
)
# Update update_voter_call_queue_status_on_voter_save
# Add voted to relevant fields
content = content.replace(
"relevant = {'is_targeted', 'candidate_support'}",
"relevant = {'is_targeted', 'candidate_support', 'voted'}"
)
# Add voted check to priorities
call_priority_logic = """ # PRIORITY 2: If support is 'supporting', then 'no_call_required'"""
content = content.replace(
call_priority_logic,
""" # PRIORITY 1.5: If they voted, no call required
if instance.voted:
if instance.call_queue_status != 'no_call_required':
Voter.objects.filter(pk=instance.pk).update(call_queue_status='no_call_required')
return
""" + call_priority_logic
)
with open('core/models.py', 'w') as f:
f.write(content)