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

68 lines
3.1 KiB
Python

import sys
with open('core/templates/core/yard_sign_voters.html', 'r') as f:
lines = f.readlines()
new_lines = []
skip_next_th = False
skip_next_td = False
# Remove duplicated TH
for i, line in enumerate(lines):
if '<th class="py-3 text-uppercase small ls-1">Voters Wanting Sign</th><th class="py-3 text-uppercase small ls-1">Sign Type</th>' in line:
new_lines.append(line)
skip_next_th = True
continue
if skip_next_th and '<th class="py-3 text-uppercase small ls-1">Sign Type</th>' in line:
skip_next_th = False
continue
# Remove duplicated TD
if '<td>' in line and i + 3 < len(lines) and 'household.sign_types_display' in lines[i+1] and 'bg-warning' in lines[i+1] and '</span>' in lines[i+2] and '</td>' in lines[i+3]:
if skip_next_td:
# This is the second one, skip it
skip_next_td = False
# We need to skip 4 lines
# I'll just not append them and increment a counter or something
# Actually, let's just use a more robust approach.
pass
else:
# This is the first one, keep it but mark that we should skip the next one
new_lines.append(line)
skip_next_td = True
continue
# This logic is a bit flawed for multi-line. Let's try something else.
new_lines.append(line)
# Let's try a simpler approach: replace the exact block if it's there.
content = "".join(lines)
# Fix duplicated TH
old_th = '<th class="py-3 text-uppercase small ls-1">Voters Wanting Sign</th><th class="py-3 text-uppercase small ls-1">Sign Type</th>\n <th class="py-3 text-uppercase small ls-1">Sign Type</th>'
new_th = '<th class="py-3 text-uppercase small ls-1">Voters Wanting Sign</th>\n <th class="py-3 text-uppercase small ls-1">Sign Type</th>'
content = content.replace(old_th, new_th)
# Fix duplicated TD
# Note: I already fixed the { % if so both are same now
old_td = """ <td>
<span class="badge { % if \"Large Sign\" in household.sign_types_display %}bg-warning text-dark{% else %}bg-danger{% endif %} rounded-pill px-3">
{{ household.sign_types_display }}
</span>
</td>
<td>
<span class="badge { % if \"Large Sign\" in household.sign_types_display %}bg-warning text-dark{% else %}bg-danger{% endif %} rounded-pill px-3">
{{ household.sign_types_display }}
</span>
</td>"""
new_td = """ <td>
<span class="badge { % if \"Large Sign\" in household.sign_types_display %}bg-warning text-dark{% else %}bg-danger{% endif %} rounded-pill px-3">
{{ household.sign_types_display }}
</span>
</td>"""
content = content.replace(old_td, new_td)
with open('core/templates/core/yard_sign_voters.html', 'w') as f:
f.write(content)