Ali2206 commited on
Commit
3d48b7c
·
1 Parent(s): 0ee46b5

Fix user name display in history - Ensure metadata.userName is properly saved and displayed

Browse files
Files changed (1) hide show
  1. app.py +11 -0
app.py CHANGED
@@ -587,6 +587,17 @@ async def save_checklist(user_id: str, checklist_data: dict):
587
  session_id = f"{user_id}-{datetime.utcnow().strftime('%Y%m%d-%H%M%S')}"
588
  checklist_dict['sessionId'] = session_id
589
 
 
 
 
 
 
 
 
 
 
 
 
590
  # Remove _id if it exists to let MongoDB generate a new one
591
  if '_id' in checklist_dict:
592
  del checklist_dict['_id']
 
587
  session_id = f"{user_id}-{datetime.utcnow().strftime('%Y%m%d-%H%M%S')}"
588
  checklist_dict['sessionId'] = session_id
589
 
590
+ # Ensure metadata exists and contains user information
591
+ if 'metadata' not in checklist_dict:
592
+ checklist_dict['metadata'] = {}
593
+
594
+ # Add user name from metadata if available, or use a default
595
+ user_name = checklist_dict['metadata'].get('userName', 'Unknown User')
596
+ checklist_dict['metadata']['userName'] = user_name
597
+ checklist_dict['metadata']['userId'] = user_id
598
+ checklist_dict['metadata']['savedAt'] = datetime.utcnow().isoformat()
599
+ checklist_dict['metadata']['savedAtFormatted'] = datetime.utcnow().strftime('%d/%m/%Y, %H:%M:%S')
600
+
601
  # Remove _id if it exists to let MongoDB generate a new one
602
  if '_id' in checklist_dict:
603
  del checklist_dict['_id']