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

30 lines
1013 B
Python

import sys
def r(c, f, n):
s = f"def {f}("
i = c.find(s)
if i == -1: return c
ls = c[:i].splitlines()
if ls and ls[-1].strip().startswith("@"):
i = c.rfind("@", 0, i)
nx = c.find("\ndef ", i + 1)
if nx == -1: nx = c.find("\nclass ", i + 1)
if nx == -1: nx = len(c)
return c[:i] + n.strip() + "\n\n" + c[nx:]
v = "core/views.py"
with open(v, "r") as f: c = f.read()
with open("core/filter_helper.py", "r") as f: h = f.read()
if "get_filtered_voter_queryset" not in c:
t = "def voter_advanced_search"
c = c.replace(t, h.strip() + "\n\n" + t, 1)
with open("core/views_new.py", "r") as f: v_n = f.read()
with open("core/bulk_sms_new.py", "r") as f: s_n = f.read()
with open("core/bulk_email_new.py", "r") as f: e_n = f.read()
with open("core/export_new.py", "r") as f: x_n = f.read()
c = r(c, "voter_advanced_search", v_n)
c = r(c, "bulk_send_sms", s_n)
c = r(c, "voter_bulk_send_email", e_n)
c = r(c, "export_voters_csv", x_n)
with open(v, "w") as f: f.write(c)