Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -831,32 +831,33 @@ def main():
|
|
831 |
# Button to initiate cloning of the document
|
832 |
if st.button("📄 Clone Document", key=f'clone_button_{idx}'):
|
833 |
with st.spinner("Cloning document..."):
|
834 |
-
try:
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
|
|
854 |
))
|
855 |
|
856 |
-
except exceptions.CosmosHttpResponseError as e:
|
857 |
-
|
858 |
-
except Exception as e:
|
859 |
-
|
860 |
|
861 |
# If clone mode is activated, allow user to edit the cloned document
|
862 |
if st.session_state.get('clone_mode', False):
|
|
|
831 |
# Button to initiate cloning of the document
|
832 |
if st.button("📄 Clone Document", key=f'clone_button_{idx}'):
|
833 |
with st.spinner("Cloning document..."):
|
834 |
+
#try:
|
835 |
+
# Copy the document and reset system-managed fields
|
836 |
+
cloned_doc = doc.copy()
|
837 |
+
cloned_doc['id'] = generate_unique_id() # Generate new unique ID
|
838 |
+
cloned_doc['name'] = generate_unique_id() # Generate new unique ID
|
839 |
+
cloned_doc['createdAt'] = datetime.utcnow().isoformat() # Set new creation time
|
840 |
+
cloned_doc['_rid'] = None # Clear system-managed fields
|
841 |
+
cloned_doc['_self'] = None
|
842 |
+
cloned_doc['_etag'] = None
|
843 |
+
cloned_doc['_attachments'] = None
|
844 |
+
cloned_doc['_ts'] = None
|
845 |
+
|
846 |
+
# Save the cloned document
|
847 |
+
|
848 |
+
response = container.create_item(body=cloned_doc)
|
849 |
+
st.success(f"Cloned document saved successfully with ID: {cloned_doc['id']} 🎉")
|
850 |
+
|
851 |
+
# Refresh session state documents to show the new cloned document
|
852 |
+
st.session_state.documents = list(container.query_items(
|
853 |
+
query="SELECT * FROM c ORDER BY c._ts DESC",
|
854 |
+
enable_cross_partition_query=True
|
855 |
))
|
856 |
|
857 |
+
#except exceptions.CosmosHttpResponseError as e:
|
858 |
+
# st.error(f"HTTP error occurred: {str(e)} 🚨")
|
859 |
+
#except Exception as e:
|
860 |
+
# st.error(f"An unexpected error occurred: {str(e)} 😱")
|
861 |
|
862 |
# If clone mode is activated, allow user to edit the cloned document
|
863 |
if st.session_state.get('clone_mode', False):
|