Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
823 |
-
'id':
|
824 |
-
'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(
|
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 |
-
|
840 |
-
|
841 |
-
|
|
|
842 |
st.rerun()
|
843 |
else:
|
844 |
-
st.error(
|
845 |
-
except
|
846 |
-
st.error(f"
|
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
|