06/08 Fix inspection photo issues

This commit is contained in:
2026-06-08 15:22:53 -04:00
parent 1f0bf2e586
commit 5dd0fe23b5
2 changed files with 18 additions and 7 deletions
+11 -2
View File
@@ -94,17 +94,26 @@ def _collect_form_responses(form_fields, existing_responses=None):
responses[fid] = request.form.getlist(key) responses[fid] = request.form.getlist(key)
elif ftype == 'image': elif ftype == 'image':
# Priority 1: a new file was selected and submitted with the form
photo_file = request.files.get(key) photo_file = request.files.get(key)
path = _save_photo(photo_file, subfolder='inspection_photos') path = _save_photo(photo_file, subfolder='inspection_photos')
if path: if path:
responses[fid] = path responses[fid] = path
else: else:
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)) existing_responses.get(str(fid))
or existing_responses.get(fid) or existing_responses.get(fid)
or '' or ''
) )
responses[fid] = existing_path
elif ftype == 'table': elif ftype == 'table':
cols = field.get('col_headers') or ['Column 1'] cols = field.get('col_headers') or ['Column 1']
+3 -1
View File
@@ -420,7 +420,9 @@
<input type="file" name="field_{{ fid }}" id="field_{{ fid }}" accept="image/*" <input type="file" name="field_{{ fid }}" id="field_{{ fid }}" accept="image/*"
onchange="uploadPhotoField(this)" onchange="uploadPhotoField(this)"
data-upload-url="{{ url_for('inspections.upload_photo_ajax', inspection_id=inspection.id) }}"> data-upload-url="{{ url_for('inspections.upload_photo_ajax', inspection_id=inspection.id) }}">
<input type="hidden" id="field_{{ fid }}_server_path" value="{{ saved or '' }}"> <input type="hidden" id="field_{{ fid }}_server_path"
name="field_{{ fid }}_server_path"
value="{{ saved or '' }}">
<div class="upload-main"> <div class="upload-main">
<i class="bi bi-cloud-upload" id="icon_{{ fid }}"></i> <i class="bi bi-cloud-upload" id="icon_{{ fid }}"></i>
<span class="upload-prompt" id="prompt_{{ fid }}">Tap to take / choose photo</span> <span class="upload-prompt" id="prompt_{{ fid }}">Tap to take / choose photo</span>