From 05c41e8c4aefdeecf60c864eceaf6655851f222b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Wed, 17 Jun 2026 18:58:43 +0400 Subject: [PATCH] =?UTF-8?q?upload:=20=D0=B2=D1=81=D0=B5=D0=B3=D0=B4=D0=B0?= =?UTF-8?q?=20=D0=BE=D0=B4=D0=BD=D0=BE=20=D1=81=D0=BE=D0=B5=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5,=20=D1=83=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=20if=20cid,=20v1.23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site/app.py | 36 +++++++++++++++++++++--------------- site/templates/upload.html | 2 +- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/site/app.py b/site/app.py index d8c5da6..fff6b97 100644 --- a/site/app.py +++ b/site/app.py @@ -152,25 +152,31 @@ class ContractsApp: mime = mimeutil.guess_mime(filename) or "application/octet-stream" cid = data.get("cid") - conn = None - if cid: - contract_id = cid - else: - conn, err = db.connect() - if err: - return jsonify({"error": f"БД: {err}"}), 500 + # Всегда одно соединение + conn, err = db.connect() + if err: + return jsonify({"error": f"БД: {err}"}), 500 + try: cur = conn.cursor() - cur.execute( - "INSERT INTO contracts (number, client) VALUES (%s, %s) RETURNING id", - ("б/н " + __import__("datetime").datetime.now().strftime("%Y%m%d-%H%M"), ""), - ) - contract_id = cur.fetchone()[0] - conn.commit() + if cid: + contract_id = cid + else: + cur.execute( + "INSERT INTO contracts (number, client) VALUES (%s, %s) RETURNING id", + ("б/н " + __import__("datetime").datetime.now().strftime("%Y%m%d-%H%M"), ""), + ) + contract_id = cur.fetchone()[0] - doc_id = _save_file_to_db(filename, file_bytes, mime, str(contract_id), conn=conn) - if conn: + doc_id = _save_file_to_db(filename, file_bytes, mime, str(contract_id), conn=conn) + conn.commit() cur.close() + except Exception as e: + try: conn.rollback() + except: pass + raise e + finally: db.put_conn(conn) + return jsonify({"contract_id": str(contract_id), "doc_id": str(doc_id) if doc_id else None}) # ── Чанковая загрузка ────────────────────────────────────── diff --git a/site/templates/upload.html b/site/templates/upload.html index b187027..4e92644 100644 --- a/site/templates/upload.html +++ b/site/templates/upload.html @@ -59,7 +59,7 @@
Nubes - Сверка договоров v1.22 + Сверка договоров v1.23