diff --git a/app/routes/inspections.py b/app/routes/inspections.py index c14eb3b..d6284f3 100644 --- a/app/routes/inspections.py +++ b/app/routes/inspections.py @@ -94,17 +94,26 @@ def _collect_form_responses(form_fields, existing_responses=None): responses[fid] = request.form.getlist(key) elif ftype == 'image': + # Priority 1: a new file was selected and submitted with the form photo_file = request.files.get(key) path = _save_photo(photo_file, subfolder='inspection_photos') if path: responses[fid] = path else: - existing_path = ( - existing_responses.get(str(fid)) - or existing_responses.get(fid) - or '' - ) - responses[fid] = existing_path + # Priority 2: the named hidden input carries the AJAX-uploaded + # server path directly in the POST body — covers the case where + # the photo was uploaded via AJAX but no draft save captured it + # (e.g., uploaded after the last flag-issue page reload). + submitted_path = request.form.get(f'{key}_server_path', '').strip() + if submitted_path: + responses[fid] = submitted_path + else: + # Priority 3: fall back to the most recent draft in the DB + responses[fid] = ( + existing_responses.get(str(fid)) + or existing_responses.get(fid) + or '' + ) elif ftype == 'table': cols = field.get('col_headers') or ['Column 1'] diff --git a/app/templates/inspections/execute.html b/app/templates/inspections/execute.html index 1762d7b..8d85a85 100644 --- a/app/templates/inspections/execute.html +++ b/app/templates/inspections/execute.html @@ -420,7 +420,9 @@ - +