miror_update
This commit is contained in:
Binary file not shown.
@@ -30,6 +30,24 @@ def add_charset(response):
|
||||
response.headers["Content-Type"] = "text/html; charset=utf-8"
|
||||
return response
|
||||
|
||||
|
||||
def fix_mojibake_text(value):
|
||||
if not isinstance(value, str) or not value:
|
||||
return value
|
||||
if not re.search(r"Р[А-яЁё]|С[А-яЁё]|вЂ|в„|Р |Ѓ|Љ|Њ|Ћ|Џ|™|ў|ќ|№", value):
|
||||
return value
|
||||
try:
|
||||
fixed = value.encode("cp1251").decode("utf-8")
|
||||
except (UnicodeEncodeError, UnicodeDecodeError):
|
||||
return value
|
||||
before = len(re.findall(r"Р[А-яЁё]|С[А-яЁё]|вЂ|в„|Р |Ѓ|Љ|Њ|Ћ|Џ|™|ў|ќ|№", value))
|
||||
after = len(re.findall(r"Р[А-яЁё]|С[А-яЁё]|вЂ|в„|Р |Ѓ|Љ|Њ|Ћ|Џ|™|ў|ќ|№", fixed))
|
||||
return fixed if after + 1 < before else value
|
||||
|
||||
|
||||
def fix_mojibake_row(items):
|
||||
return [fix_mojibake_text(item) for item in items]
|
||||
|
||||
USERS = {
|
||||
"admin": {"password": "admin", "role": "admin"},
|
||||
"user": {"password": "user", "role": "user"},
|
||||
@@ -1399,7 +1417,7 @@ def computers_update_cabinet():
|
||||
cid = request.form.get("id", "").strip()
|
||||
cabinet_id = request.form.get("cabinet_id", "").strip()
|
||||
if not cid.isdigit():
|
||||
flash("Некорректный компьютер")
|
||||
flash("Некорректный компьютер")
|
||||
return redirect(request.referrer or url_for("index"))
|
||||
cab_id = int(cabinet_id) if cabinet_id.isdigit() else None
|
||||
conn = get_conn()
|
||||
@@ -1411,7 +1429,7 @@ def computers_update_cabinet():
|
||||
cur.execute("UPDATE computers SET cabinet_id=%s WHERE id=%s", (cab_id, int(cid)))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
flash("Расположение обновлено")
|
||||
flash("Расположение обновлено")
|
||||
return redirect(request.referrer or url_for("index"))
|
||||
|
||||
@app.route("/devices/update_cabinet", methods=["POST"])
|
||||
@@ -1939,10 +1957,10 @@ def computers_add():
|
||||
date_in_operation = request.form.get("date_in_operation", "").strip()
|
||||
|
||||
if not inventory_number:
|
||||
flash("Укажите инвентарный номер")
|
||||
flash("Укажите инвентарный номер")
|
||||
return redirect(url_for("computers"))
|
||||
if ctype not in ("pc", "laptop"):
|
||||
flash("Укажите тип (ПК/ноутбук)")
|
||||
flash("Укажите тип (ПК/ноутбук)")
|
||||
return redirect(url_for("computers"))
|
||||
|
||||
cab_id = int(cabinet_id) if cabinet_id.isdigit() else None
|
||||
@@ -2825,7 +2843,7 @@ def report_orders_xlsx():
|
||||
ws.title = "Orders"
|
||||
ws.append(["Дата", "Штрихкод", "Модель", "Количество"])
|
||||
for dt, barcode, model, qty in rows:
|
||||
ws.append([dt, barcode, model, qty])
|
||||
ws.append(fix_mojibake_row([dt, barcode, model, qty]))
|
||||
|
||||
bio = BytesIO()
|
||||
wb.save(bio)
|
||||
@@ -2857,7 +2875,7 @@ def report_cartridges_xlsx():
|
||||
ws.title = "Cartridges"
|
||||
ws.append(["Штрихкод", "Модель", "Остаток", "Минимум"])
|
||||
for barcode, model, qty, minq in rows:
|
||||
ws.append([barcode, model, qty, minq])
|
||||
ws.append(fix_mojibake_row([barcode, model, qty, minq]))
|
||||
|
||||
bio = BytesIO()
|
||||
wb.save(bio)
|
||||
@@ -2913,7 +2931,7 @@ def report_devices_xlsx():
|
||||
ws.title = "Devices"
|
||||
ws.append(["Инв. №", "Бренд", "Модель", "Серийный №", "Тип", "Картридж", "Кабинет", "Примечание", "Дата ввода в эксплуатацию", "Добавлено"])
|
||||
for inv, brand, model, sn, dtype, cartridge, cab_name, note, date_in_operation, date_added in rows:
|
||||
ws.append([inv, brand, model, sn, dtype, cartridge, cab_name, note, date_in_operation, date_added])
|
||||
ws.append(fix_mojibake_row([inv, brand, model, sn, dtype, cartridge, cab_name, note, date_in_operation, date_added]))
|
||||
|
||||
bio = BytesIO()
|
||||
wb.save(bio)
|
||||
@@ -2939,7 +2957,7 @@ def report_cabinets_xlsx():
|
||||
ws.title = "Cabinets"
|
||||
ws.append(["ID", "Название"])
|
||||
for cid, name in rows:
|
||||
ws.append([cid, name])
|
||||
ws.append(fix_mojibake_row([cid, name]))
|
||||
|
||||
bio = BytesIO()
|
||||
wb.save(bio)
|
||||
@@ -2972,7 +2990,7 @@ def report_consumables_xlsx():
|
||||
ws.title = "Consumables"
|
||||
ws.append(["Штрихкод", "Модель", "Тип", "Количество"])
|
||||
for barcode, model, ctype, qty in rows:
|
||||
ws.append([barcode, model, ctype, qty])
|
||||
ws.append(fix_mojibake_row([barcode, model, ctype, qty]))
|
||||
|
||||
bio = BytesIO()
|
||||
wb.save(bio)
|
||||
|
||||
Reference in New Issue
Block a user