Context:
I have a web application in Django. This application is a dashboard where the users can verify and validate the recognition made by an AI of each part of an invoice (prices, taxes...).
The user can manually review this recognition and consequently validate if everything is correct.
Situation:
When a user clicks on the verify button, it will redirect the user to another view. This new view is a Django template with an iframe. This Django view executes a function which updates the status of the item to '31.Verificando usuario' in the DB.
urls.py:
path('verification/<int:id>/', views.VerificationPage, name="fci-verification" )
views.py:
def VerificationPage (request, id):
invoice= Invoice.objects.get(id=id)
url= invoice.verification_url
invoice_id = invoice.id
status = '31.Verificando usuario'
message = _('Invoice in web verification')
try:
change_invoice_status(invoice_id, status, message)
except Exception as e:
capture_exception(e)
return render(request, "fci_verification.html", {'verification_url':
url,'invoice_id': id})
When this user clicks on "verified" into iframe, I catch this event with window.addEventListener("message", receiveMessage, false);
and update to new status.
Problem:
If the user closes the tab or browser, the item status stays as "31.Verificando usuario" and another user cannot review this invoice.
How can I capture a "close windows or tab" event and change the status to the previous status?
RESUME:
- I have a dashboard to verify invoices.
- When the user clicks on the verify button, the invoice status is updated to "31.Verificando usuario" .
- If user close browser without verify the invoice, this invoice stays with wrong status.
- I need capture this "close tab/browser" and update to the previous status.