76 lines
4.1 KiB
Python
76 lines
4.1 KiB
Python
from pathlib import Path
|
|
|
|
p = Path("app/templates/agreements/detail.html")
|
|
t = p.read_text(encoding="utf-8")
|
|
|
|
old_badge = (
|
|
"{% if agreement.status == 'approved' %}"
|
|
'<span class="badge text-bg-success align-self-center">\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u043e</span>'
|
|
"{% else %}"
|
|
'<span class="badge text-bg-secondary align-self-center">\u0427\u0435\u0440\u043d\u043e\u0432\u0438\u043a</span>'
|
|
)
|
|
new_badge = (
|
|
"{% if agreement.status == 'approved' %}"
|
|
'<span class="badge text-bg-success align-self-center">\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u043e</span>'
|
|
'<button type="button" class="btn btn-outline-warning" data-bs-toggle="modal" '
|
|
'data-bs-target="#cancelAgreementModal">\u041e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u0414\u0421</button>'
|
|
"{% elif agreement.status == 'cancelled' %}"
|
|
'<span class="badge text-bg-danger align-self-center">\u041e\u0422\u041c\u0415\u041d\u0415\u041d\u041e</span>'
|
|
"{% else %}"
|
|
'<span class="badge text-bg-secondary align-self-center">\u0427\u0435\u0440\u043d\u043e\u0432\u0438\u043a</span>'
|
|
)
|
|
|
|
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' %}"
|
|
'<span class="badge text-bg-success align-self-center">\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u043e</span>'
|
|
'<button type="button" class="btn btn-outline-warning" data-bs-toggle="modal" '
|
|
'data-bs-target="#cancelAgreementModal">\u041e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u0414\u0421</button>'
|
|
"{% elif agreement.status == 'cancelled' %}"
|
|
'<span class="badge text-bg-danger align-self-center">\u041e\u0422\u041c\u0415\u041d\u0415\u041d\u041e</span>'
|
|
"{% else %}"
|
|
'<span class="badge text-bg-secondary align-self-center">\u0427\u0435\u0440\u043d\u043e\u0432\u0438\u043a</span>'
|
|
'<button type="button" class="btn btn-outline-danger" data-bs-toggle="modal" '
|
|
'data-bs-target="#deleteAgreementModal">\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0414\u0421</button>'
|
|
"{% endif %}"
|
|
)
|
|
t = t.replace(old_block, new_block)
|
|
print("badge block replaced")
|
|
|
|
old_modal = "\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0414\u0421</button></form></div></div></div></div>"
|
|
cancel_modal = (
|
|
'<div class="modal fade" id="cancelAgreementModal" tabindex="-1">'
|
|
'<div class="modal-dialog"><div class="modal-content">'
|
|
'<div class="modal-header"><h2 class="modal-title fs-5">\u041e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u0414\u0421</h2>'
|
|
'<button type="button" class="btn-close" data-bs-dismiss="modal"></button></div>'
|
|
'<div class="modal-body"><p>\u041f\u043e\u0441\u043b\u0435 \u043e\u0442\u043c\u0435\u043d\u044b \u0414\u0421 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0435\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043f\u043b\u0430\u043d\u0435. \u0418\u0441\u0442\u043e\u0440\u0438\u044f \u0414\u0421 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f.</p></div>'
|
|
'<div class="modal-footer"><button class="btn btn-outline-secondary" data-bs-dismiss="modal">\u041d\u0430\u0437\u0430\u0434</button>'
|
|
'<form method="post" action="/projects/{{ project.id }}/agreements/{{ agreement.id }}/cancel">'
|
|
'<button class="btn btn-warning">\u041e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u0414\u0421</button></form></div>'
|
|
"</div></div></div>" + 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")
|