awacke1 commited on
Commit
e30de17
ยท
verified ยท
1 Parent(s): 0d3a812

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -15
app.py CHANGED
@@ -814,21 +814,17 @@ def main():
814
  st.markdown(f"##### Original Document ID: {doc.get('id', '')}")
815
 
816
  if st.button("๐Ÿ“„ Clone Document", key=f'clone_button_{idx}'):
817
- # Generate new unique identifiers
818
- new_id = str(uuid.uuid4())
819
- new_name = f"Clone_{str(uuid.uuid4())[:8]}"
820
-
821
  # Create new document with unique ID and name
822
- cloned_doc = {
823
- 'id': new_id,
824
- 'name': new_name,
825
- **{k: v for k, v in doc.items() if k not in ['id', 'name']}
826
  }
827
 
828
  # Show editable preview
829
  edited_doc = st.text_area(
830
  "Edit cloned document:",
831
- value=json.dumps(cloned_doc, indent=2),
832
  height=300,
833
  key=f'edit_clone_{idx}'
834
  )
@@ -836,14 +832,15 @@ def main():
836
  if st.button("๐Ÿ’พ Save Clone", key=f'save_clone_{idx}'):
837
  try:
838
  final_doc = json.loads(edited_doc)
839
- success, message = insert_record(container, final_doc)
840
- if success:
841
- st.success(f"Cloned document saved with ID: {new_id}")
 
842
  st.rerun()
843
  else:
844
- st.error(message)
845
- except json.JSONDecodeError as e:
846
- st.error(f"Invalid JSON format: {str(e)}")
847
 
848
  elif selected_view == 'New Record':
849
  # ๐Ÿ†• New Record
 
814
  st.markdown(f"##### Original Document ID: {doc.get('id', '')}")
815
 
816
  if st.button("๐Ÿ“„ Clone Document", key=f'clone_button_{idx}'):
 
 
 
 
817
  # Create new document with unique ID and name
818
+ new_doc = {
819
+ 'id': str(uuid.uuid4()),
820
+ 'name': f"Clone_{str(uuid.uuid4())[:8]}",
821
+ **{k: v for k, v in doc.items() if k not in ['id', 'name', '_rid', '_self', '_etag', '_attachments', '_ts']}
822
  }
823
 
824
  # Show editable preview
825
  edited_doc = st.text_area(
826
  "Edit cloned document:",
827
+ value=json.dumps(new_doc, indent=2),
828
  height=300,
829
  key=f'edit_clone_{idx}'
830
  )
 
832
  if st.button("๐Ÿ’พ Save Clone", key=f'save_clone_{idx}'):
833
  try:
834
  final_doc = json.loads(edited_doc)
835
+ # Use container.create_item() instead of update_record()
836
+ response = container.create_item(body=final_doc)
837
+ if response:
838
+ st.success(f"New cloned document created with ID: {final_doc['id']}")
839
  st.rerun()
840
  else:
841
+ st.error("Failed to create new document")
842
+ except Exception as e:
843
+ st.error(f"Error creating document: {str(e)}")
844
 
845
  elif selected_view == 'New Record':
846
  # ๐Ÿ†• New Record