06/08 Fix inspection photo issues
This commit is contained in:
@@ -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
|
||||||
existing_responses.get(str(fid))
|
# server path directly in the POST body — covers the case where
|
||||||
or existing_responses.get(fid)
|
# the photo was uploaded via AJAX but no draft save captured it
|
||||||
or ''
|
# (e.g., uploaded after the last flag-issue page reload).
|
||||||
)
|
submitted_path = request.form.get(f'{key}_server_path', '').strip()
|
||||||
responses[fid] = existing_path
|
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':
|
elif ftype == 'table':
|
||||||
cols = field.get('col_headers') or ['Column 1']
|
cols = field.get('col_headers') or ['Column 1']
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user