from pathlib import Path p = Path("app/templates/agreements/detail.html") t = p.read_text(encoding="utf-8") old_badge = ( "{% if agreement.status == 'approved' %}" '\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u043e' "{% else %}" '\u0427\u0435\u0440\u043d\u043e\u0432\u0438\u043a' ) new_badge = ( "{% if agreement.status == 'approved' %}" '\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u043e' '' "{% elif agreement.status == 'cancelled' %}" '\u041e\u0422\u041c\u0415\u041d\u0415\u041d\u041e' "{% else %}" '\u0427\u0435\u0440\u043d\u043e\u0432\u0438\u043a' ) if old_badge in t: t = t.replace(old_badge, new_badge) print("badge replaced") else: print("badge NOT found") # The file uses HTML entities for Russian text - find and replace using entity form # Look for the actual bytes in file old_ent = "{% if agreement.status == 'approved' %}" idx = t.find(old_ent) if idx >= 0: # Find the closing {% endif %} after this end = t.find("{% endif %}", idx) end += len("{% endif %}") old_block = t[idx:end] print("OLD BLOCK:", repr(old_block[:200])) new_block = ( "{% if agreement.status == 'approved' %}" '\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u043e' '' "{% elif agreement.status == 'cancelled' %}" '\u041e\u0422\u041c\u0415\u041d\u0415\u041d\u041e' "{% else %}" '\u0427\u0435\u0440\u043d\u043e\u0432\u0438\u043a' '' "{% endif %}" ) t = t.replace(old_block, new_block) print("badge block replaced") old_modal = "\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0414\u0421" cancel_modal = ( '" + old_modal ) if old_modal in t: t = t.replace(old_modal, cancel_modal) print("modal replaced") else: print("modal NOT found") p.write_text(t, encoding="utf-8") print("done")