import sys file_path = 'core/views.py' with open(file_path, 'r') as f: content = f.read() # Replace: # wants_yard_sign = form.cleaned_data["wants_yard_sign"] # ... # # 2) If "Wants a Yard Sign" checkbox is selected # if wants_yard_sign: # voter.yard_sign = "wants" old_part = " wants_yard_sign = form.cleaned_data[\"wants_yard_sign\"]" new_part = " yard_sign_status = form.cleaned_data[\"yard_sign_status\"]" content = content.replace(old_part, new_part) old_loop_part = " # 2) If \"Wants a Yard Sign\" checkbox is selected\n if wants_yard_sign:\n voter.yard_sign = \"wants\"" new_loop_part = " # 2) Update Yard Sign status if not \"no_change\":\n if yard_sign_status != 'no_change':\n voter.yard_sign = yard_sign_status" content = content.replace(old_loop_part, new_loop_part) with open(file_path, 'w') as f: f.write(content)