Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -711,8 +711,8 @@ def main():
|
|
711 |
if st.session_state.current_index < total_docs - 1:
|
712 |
st.session_state.current_index += 1
|
713 |
st.rerun()
|
714 |
-
|
715 |
-
|
716 |
elif selected_view == 'Show as Code Editor':
|
717 |
Label = '# 💻 Code editor view'
|
718 |
st.markdown(Label)
|
@@ -753,72 +753,23 @@ def main():
|
|
753 |
if st.button("🗑️ Delete", key=f'delete_button_{st.session_state.current_index}'):
|
754 |
try:
|
755 |
current_doc = json.loads(doc_str)
|
756 |
-
|
757 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
758 |
if response:
|
759 |
-
st.success(f"Document {
|
760 |
if st.session_state.current_index > 0:
|
761 |
st.session_state.current_index -= 1
|
762 |
st.rerun()
|
763 |
except Exception as e:
|
764 |
st.error(f"Error deleting document: {str(e)}")
|
765 |
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
elif selected_view == 'Show as Code Editor 3':
|
770 |
-
Label = '# 💻 Code editor view'
|
771 |
-
st.markdown(Label)
|
772 |
-
total_docs = len(documents)
|
773 |
-
doc = documents[st.session_state.current_index]
|
774 |
-
st.markdown(f"#### Document ID: {doc.get('id', '')}")
|
775 |
-
doc_str = st.text_area("Edit Document",
|
776 |
-
value=json.dumps(doc, indent=2),
|
777 |
-
height=300,
|
778 |
-
key=f'code_editor_{st.session_state.current_index}')
|
779 |
-
|
780 |
-
col_prev, col_next = st.columns([1, 1])
|
781 |
-
with col_prev:
|
782 |
-
if st.button("⬅️ Previous", key='prev_code'):
|
783 |
-
if st.session_state.current_index > 0:
|
784 |
-
st.session_state.current_index -= 1
|
785 |
-
st.rerun()
|
786 |
-
with col_next:
|
787 |
-
if st.button("➡️ Next", key='next_code'):
|
788 |
-
if st.session_state.current_index < total_docs - 1:
|
789 |
-
st.session_state.current_index += 1
|
790 |
-
st.rerun()
|
791 |
-
|
792 |
-
col_save, col_delete = st.columns([1, 1])
|
793 |
-
with col_save:
|
794 |
-
if st.button("💾 Save Changes", key=f'save_button_{st.session_state.current_index}'):
|
795 |
-
try:
|
796 |
-
updated_doc = json.loads(doc_str)
|
797 |
-
success, message = update_record(container, updated_doc)
|
798 |
-
if success:
|
799 |
-
st.success(f"Document {updated_doc['id']} saved successfully.")
|
800 |
-
st.session_state.selected_document_id = updated_doc['id']
|
801 |
-
st.rerun()
|
802 |
-
else:
|
803 |
-
st.error(message)
|
804 |
-
except json.JSONDecodeError as e:
|
805 |
-
st.error(f"Invalid JSON: {str(e)} 🚫")
|
806 |
-
|
807 |
-
with col_delete:
|
808 |
-
if st.button("🗑️ Delete", key=f'delete_button_{st.session_state.current_index}'):
|
809 |
-
try:
|
810 |
-
current_doc = json.loads(doc_str)
|
811 |
-
success, message = delete_record(container, current_doc)
|
812 |
-
if success:
|
813 |
-
st.success(message)
|
814 |
-
if st.session_state.current_index > 0:
|
815 |
-
st.session_state.current_index -= 1
|
816 |
-
st.rerun()
|
817 |
-
else:
|
818 |
-
st.error(message)
|
819 |
-
except json.JSONDecodeError as e:
|
820 |
-
st.error(f"Invalid JSON: {str(e)} 🚫")
|
821 |
-
|
822 |
|
823 |
|
824 |
|
|
|
711 |
if st.session_state.current_index < total_docs - 1:
|
712 |
st.session_state.current_index += 1
|
713 |
st.rerun()
|
714 |
+
|
715 |
+
|
716 |
elif selected_view == 'Show as Code Editor':
|
717 |
Label = '# 💻 Code editor view'
|
718 |
st.markdown(Label)
|
|
|
753 |
if st.button("🗑️ Delete", key=f'delete_button_{st.session_state.current_index}'):
|
754 |
try:
|
755 |
current_doc = json.loads(doc_str)
|
756 |
+
options = {
|
757 |
+
'enableCrossPartitionQuery': True,
|
758 |
+
'partitionKey': '/id'
|
759 |
+
}
|
760 |
+
response = container.delete_item(
|
761 |
+
item=current_doc['id'],
|
762 |
+
partition_key=current_doc['id'],
|
763 |
+
enable_cross_partition_query=True
|
764 |
+
)
|
765 |
if response:
|
766 |
+
st.success(f"Document {current_doc['id']} deleted successfully.")
|
767 |
if st.session_state.current_index > 0:
|
768 |
st.session_state.current_index -= 1
|
769 |
st.rerun()
|
770 |
except Exception as e:
|
771 |
st.error(f"Error deleting document: {str(e)}")
|
772 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
773 |
|
774 |
|
775 |
|