06/08 Fix inspection photo issues
This commit is contained in:
+25
-1
@@ -34,6 +34,27 @@ logger = logging.getLogger(__name__)
|
|||||||
bp = Blueprint('api_inspections', __name__)
|
bp = Blueprint('api_inspections', __name__)
|
||||||
|
|
||||||
_ALLOWED_ROLES = {'admin', 'director', 'inspector', 'project_manager'}
|
_ALLOWED_ROLES = {'admin', 'director', 'inspector', 'project_manager'}
|
||||||
|
|
||||||
|
|
||||||
|
def _merge_form_data(existing: dict, incoming: dict) -> dict:
|
||||||
|
"""Merge incoming form_data into existing, preserving file paths.
|
||||||
|
|
||||||
|
New non-empty values always win. The one exception: an empty string
|
||||||
|
coming from the client will NOT overwrite an existing server-side upload
|
||||||
|
path (any value that starts with 'uploads/'). This protects photo paths
|
||||||
|
stored during an earlier POST from being silently blanked when the iOS
|
||||||
|
sends a final PATCH whose form_data was rebuilt without re-including the
|
||||||
|
already-uploaded paths.
|
||||||
|
"""
|
||||||
|
merged = dict(existing)
|
||||||
|
for k, v in incoming.items():
|
||||||
|
existing_v = merged.get(k)
|
||||||
|
if (not v
|
||||||
|
and isinstance(existing_v, str)
|
||||||
|
and existing_v.startswith('uploads/')):
|
||||||
|
continue # keep the saved photo path
|
||||||
|
merged[k] = v
|
||||||
|
return merged
|
||||||
_UUID_RE = re.compile(
|
_UUID_RE = re.compile(
|
||||||
r'^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$',
|
r'^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$',
|
||||||
re.IGNORECASE,
|
re.IGNORECASE,
|
||||||
@@ -424,7 +445,10 @@ def update_inspection(inspection_id):
|
|||||||
except (json.JSONDecodeError, TypeError):
|
except (json.JSONDecodeError, TypeError):
|
||||||
existing_notes = {}
|
existing_notes = {}
|
||||||
if 'form_data' in data:
|
if 'form_data' in data:
|
||||||
existing_notes['_form_data'] = data['form_data']
|
existing_notes['_form_data'] = _merge_form_data(
|
||||||
|
existing_notes.get('_form_data') or {},
|
||||||
|
data['form_data'] or {},
|
||||||
|
)
|
||||||
if 'notes' in data:
|
if 'notes' in data:
|
||||||
existing_notes['_inspector_notes'] = data['notes']
|
existing_notes['_inspector_notes'] = data['notes']
|
||||||
inspection.notes = json.dumps(existing_notes)
|
inspection.notes = json.dumps(existing_notes)
|
||||||
|
|||||||
Reference in New Issue
Block a user