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)
|
||||
|
||||
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 = (
|
||||
# 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 ''
|
||||
)
|
||||
responses[fid] = existing_path
|
||||
|
||||
elif ftype == 'table':
|
||||
cols = field.get('col_headers') or ['Column 1']
|
||||
|
||||
@@ -420,7 +420,9 @@
|
||||
<input type="file" name="field_{{ fid }}" id="field_{{ fid }}" accept="image/*"
|
||||
onchange="uploadPhotoField(this)"
|
||||
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">
|
||||
<i class="bi bi-cloud-upload" id="icon_{{ fid }}"></i>
|
||||
<span class="upload-prompt" id="prompt_{{ fid }}">Tap to take / choose photo</span>
|
||||
|
||||
Reference in New Issue
Block a user