From 179ec04e80c28a9bf66fd224f2d4159240d9bc6e Mon Sep 17 00:00:00 2001 From: Agnibho Mondal Date: Tue, 27 Feb 2024 02:54:51 +0530 Subject: [PATCH] Card ID race condition --- librevax.py | 13 ++++++++++++- templates/base.html | 4 ---- templates/patient-edit.html | 13 ++++++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/librevax.py b/librevax.py index 41c87d9..8e6363f 100644 --- a/librevax.py +++ b/librevax.py @@ -378,7 +378,18 @@ def patient_edit(pid=None): if(pid is None): (ok, data)=patient.create(cursor, request.form) if(not ok): - raise Exception(data) + if(isinstance(data, sqlite3.IntegrityError)): + data=request.form + (ok, center)=multicenter.list(cursor) + if(not ok): + raise exception(center) + (ok, last)=patient.last(cursor) + if(not ok): + raise Exception(last) + data.lastCid=last["cid"] + return render_template("patient-edit.html", data=data, center=center, action="uniq") + else: + raise Exception(data) pid=data else: (ok, data)=patient.update(cursor, pid, request.form) diff --git a/templates/base.html b/templates/base.html index 931794d..459e2f2 100644 --- a/templates/base.html +++ b/templates/base.html @@ -67,9 +67,5 @@ You should have received a copy of the GNU General Public License along with Lib - {% if data and data["lastCid"] %} - - - {% endif %} diff --git a/templates/patient-edit.html b/templates/patient-edit.html index 3a4b397..9fadb43 100644 --- a/templates/patient-edit.html +++ b/templates/patient-edit.html @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with Lib {% block content %}
-
+
@@ -91,6 +91,17 @@ You should have received a copy of the GNU General Public License along with Lib
+{% if data["lastCid"] %} + + +{% endif %} +{% if action=="uniq" %} + +{% endif %}