awacke1 commited on
Commit
3c2371e
Β·
verified Β·
1 Parent(s): 54d0e82

Update backup9clonesavenameatlast.app.py

Browse files
Files changed (1) hide show
  1. backup9clonesavenameatlast.app.py +19 -7
backup9clonesavenameatlast.app.py CHANGED
@@ -683,27 +683,35 @@ def main():
683
  st.error("Failed to clone document. Please try again.")
684
 
685
  elif selected_view == 'Clone Document':
686
- # 🧬 Clone Document per record
687
- st.markdown("#### Clone a document:")
688
  for idx, doc in enumerate(documents_to_display):
689
  st.markdown(f"##### Document ID: {doc.get('id', '')}")
690
  if st.button("πŸ“„ Clone Document", key=f'clone_button_{idx}'):
691
  cloned_doc = doc.copy()
692
- # Generate a unique ID
693
- cloned_doc['id'] = generate_unique_id()
 
 
 
694
  st.session_state.cloned_doc = cloned_doc
695
  st.session_state.cloned_doc_str = json.dumps(cloned_doc, indent=2)
696
  st.session_state.clone_mode = True
697
  st.rerun()
 
698
  if st.session_state.get('clone_mode', False):
699
- st.markdown("#### Edit Cloned Document and Name Your Clone:")
700
- cloned_doc_str = st.text_area("Cloned Document Content (in JSON format) - Update name please to make it unique before saving!", value=st.session_state.cloned_doc_str, height=300)
 
 
 
 
 
701
  if st.button("πŸ’Ύ Save Cloned Document"):
702
  try:
703
  new_doc = json.loads(cloned_doc_str)
704
  success, message = insert_record(container, new_doc)
705
  if success:
706
- st.success(f"Cloned document saved with id: {new_doc['id']} πŸŽ‰")
707
  st.session_state.selected_document_id = new_doc['id']
708
  st.session_state.clone_mode = False
709
  st.session_state.cloned_doc = None
@@ -713,6 +721,10 @@ def main():
713
  st.error(message)
714
  except json.JSONDecodeError as e:
715
  st.error(f"Invalid JSON: {str(e)} 🚫")
 
 
 
 
716
 
717
  elif selected_view == 'New Record':
718
  # πŸ†• New Record
 
683
  st.error("Failed to clone document. Please try again.")
684
 
685
  elif selected_view == 'Clone Document':
686
+ st.markdown("#### Clone Document:")
 
687
  for idx, doc in enumerate(documents_to_display):
688
  st.markdown(f"##### Document ID: {doc.get('id', '')}")
689
  if st.button("πŸ“„ Clone Document", key=f'clone_button_{idx}'):
690
  cloned_doc = doc.copy()
691
+ # Generate new unique IDs
692
+ new_id = str(uuid.uuid4())
693
+ cloned_doc['id'] = new_id
694
+ if 'name' in cloned_doc:
695
+ cloned_doc['name'] = f"{cloned_doc['name']}_clone_{new_id[:8]}"
696
  st.session_state.cloned_doc = cloned_doc
697
  st.session_state.cloned_doc_str = json.dumps(cloned_doc, indent=2)
698
  st.session_state.clone_mode = True
699
  st.rerun()
700
+
701
  if st.session_state.get('clone_mode', False):
702
+ st.markdown("#### Edit Cloned Document:")
703
+ cloned_doc_str = st.text_area(
704
+ "Edit JSON content below:",
705
+ value=st.session_state.cloned_doc_str,
706
+ height=300
707
+ )
708
+
709
  if st.button("πŸ’Ύ Save Cloned Document"):
710
  try:
711
  new_doc = json.loads(cloned_doc_str)
712
  success, message = insert_record(container, new_doc)
713
  if success:
714
+ st.success(f"Cloned document saved successfully! πŸŽ‰")
715
  st.session_state.selected_document_id = new_doc['id']
716
  st.session_state.clone_mode = False
717
  st.session_state.cloned_doc = None
 
721
  st.error(message)
722
  except json.JSONDecodeError as e:
723
  st.error(f"Invalid JSON: {str(e)} 🚫")
724
+
725
+
726
+
727
+
728
 
729
  elif selected_view == 'New Record':
730
  # πŸ†• New Record