Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -174,38 +174,14 @@ def update_record(container, updated_record):
|
|
174 |
return False, f"An unexpected error occurred: {traceback.format_exc()} π±"
|
175 |
|
176 |
# ποΈ Delete record - Saying goodbye to data (it's not you, it's me)
|
177 |
-
def delete_record(container,
|
178 |
try:
|
179 |
-
|
180 |
-
|
181 |
-
params = [{"name": "@id", "value": id}]
|
182 |
-
|
183 |
-
# Execute query with cross partition enabled
|
184 |
-
items = list(container.query_items(
|
185 |
-
query=query,
|
186 |
-
parameters=params,
|
187 |
-
enable_cross_partition_query=True
|
188 |
-
))
|
189 |
-
|
190 |
-
if not items:
|
191 |
-
return False, f"Record with id {id} not found. π΅οΈββοΈ"
|
192 |
-
|
193 |
-
# Get partition key value from the query result
|
194 |
-
partition_key = items[0]['id']
|
195 |
-
|
196 |
-
# Create partition key instance
|
197 |
-
pk = PartitionKey(partition_key)
|
198 |
-
|
199 |
-
# Delete the document using correct partition key
|
200 |
-
container.delete_item(item=id, partition_key=pk)
|
201 |
-
return True, f"Successfully deleted record with id: {id} ποΈ"
|
202 |
-
|
203 |
-
except exceptions.CosmosResourceNotFoundError:
|
204 |
-
return False, f"Record with id {id} not found. π΅οΈββοΈ"
|
205 |
except exceptions.CosmosHttpResponseError as e:
|
206 |
return False, f"HTTP error occurred: {str(e)} π¨"
|
207 |
except Exception as e:
|
208 |
-
return False, f"An unexpected error occurred: {
|
209 |
|
210 |
|
211 |
# πΎ Save to Cosmos DB - Preserving data for future generations (or just until the next update)
|
@@ -737,7 +713,7 @@ def main():
|
|
737 |
st.rerun()
|
738 |
|
739 |
elif selected_view == 'Show as Code Editor':
|
740 |
-
Label = '# π» Code editor view
|
741 |
st.markdown(Label)
|
742 |
total_docs = len(documents)
|
743 |
doc = documents[st.session_state.current_index]
|
@@ -747,7 +723,6 @@ def main():
|
|
747 |
height=300,
|
748 |
key=f'code_editor_{st.session_state.current_index}')
|
749 |
|
750 |
-
# β¬
οΈβ‘οΈ Navigation controls
|
751 |
col_prev, col_next = st.columns([1, 1])
|
752 |
with col_prev:
|
753 |
if st.button("β¬
οΈ Previous", key='prev_code'):
|
@@ -760,7 +735,6 @@ def main():
|
|
760 |
st.session_state.current_index += 1
|
761 |
st.rerun()
|
762 |
|
763 |
-
# πΎ ποΈ Save and Delete controls
|
764 |
col_save, col_delete = st.columns([1, 1])
|
765 |
with col_save:
|
766 |
if st.button("πΎ Save Changes", key=f'save_button_{st.session_state.current_index}'):
|
@@ -780,17 +754,16 @@ def main():
|
|
780 |
if st.button("ποΈ Delete", key=f'delete_button_{st.session_state.current_index}'):
|
781 |
try:
|
782 |
current_doc = json.loads(doc_str)
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
)
|
787 |
-
if response:
|
788 |
-
st.success(f"Document {current_doc['id']} deleted successfully.")
|
789 |
if st.session_state.current_index > 0:
|
790 |
st.session_state.current_index -= 1
|
791 |
st.rerun()
|
792 |
-
|
793 |
-
|
|
|
|
|
794 |
|
795 |
|
796 |
|
@@ -847,14 +820,24 @@ def main():
|
|
847 |
search_glossary(json.dumps(editable_doc, indent=2))
|
848 |
|
849 |
with col_delete:
|
850 |
-
if st.button("ποΈ Delete Record", key=f'delete_button_{idx}'):
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
858 |
|
859 |
elif selected_view == 'Clone Document':
|
860 |
st.markdown("#### Clone a document:")
|
|
|
174 |
return False, f"An unexpected error occurred: {traceback.format_exc()} π±"
|
175 |
|
176 |
# ποΈ Delete record - Saying goodbye to data (it's not you, it's me)
|
177 |
+
def delete_record(container, record):
|
178 |
try:
|
179 |
+
container.delete_item(item=record['id'], partition_key=record['id'])
|
180 |
+
return True, f"Record with id {record['id']} successfully deleted. ποΈ"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
except exceptions.CosmosHttpResponseError as e:
|
182 |
return False, f"HTTP error occurred: {str(e)} π¨"
|
183 |
except Exception as e:
|
184 |
+
return False, f"An unexpected error occurred: {traceback.format_exc()} π±"
|
185 |
|
186 |
|
187 |
# πΎ Save to Cosmos DB - Preserving data for future generations (or just until the next update)
|
|
|
713 |
st.rerun()
|
714 |
|
715 |
elif selected_view == 'Show as Code Editor':
|
716 |
+
Label = '# π» Code editor view'
|
717 |
st.markdown(Label)
|
718 |
total_docs = len(documents)
|
719 |
doc = documents[st.session_state.current_index]
|
|
|
723 |
height=300,
|
724 |
key=f'code_editor_{st.session_state.current_index}')
|
725 |
|
|
|
726 |
col_prev, col_next = st.columns([1, 1])
|
727 |
with col_prev:
|
728 |
if st.button("β¬
οΈ Previous", key='prev_code'):
|
|
|
735 |
st.session_state.current_index += 1
|
736 |
st.rerun()
|
737 |
|
|
|
738 |
col_save, col_delete = st.columns([1, 1])
|
739 |
with col_save:
|
740 |
if st.button("πΎ Save Changes", key=f'save_button_{st.session_state.current_index}'):
|
|
|
754 |
if st.button("ποΈ Delete", key=f'delete_button_{st.session_state.current_index}'):
|
755 |
try:
|
756 |
current_doc = json.loads(doc_str)
|
757 |
+
success, message = delete_record(container, current_doc)
|
758 |
+
if success:
|
759 |
+
st.success(message)
|
|
|
|
|
|
|
760 |
if st.session_state.current_index > 0:
|
761 |
st.session_state.current_index -= 1
|
762 |
st.rerun()
|
763 |
+
else:
|
764 |
+
st.error(message)
|
765 |
+
except json.JSONDecodeError as e:
|
766 |
+
st.error(f"Invalid JSON: {str(e)} π«")
|
767 |
|
768 |
|
769 |
|
|
|
820 |
search_glossary(json.dumps(editable_doc, indent=2))
|
821 |
|
822 |
with col_delete:
|
823 |
+
#if st.button("ποΈ Delete Record", key=f'delete_button_{idx}'):
|
824 |
+
|
825 |
+
|
826 |
+
if st.button("ποΈ Delete", key=f'delete_button_{st.session_state.current_index}'):
|
827 |
+
try:
|
828 |
+
current_doc = json.loads(doc_str)
|
829 |
+
success, message = delete_record(container, current_doc)
|
830 |
+
if success:
|
831 |
+
st.success(message)
|
832 |
+
if st.session_state.current_index > 0:
|
833 |
+
st.session_state.current_index -= 1
|
834 |
+
st.rerun()
|
835 |
+
else:
|
836 |
+
st.error(message)
|
837 |
+
except json.JSONDecodeError as e:
|
838 |
+
st.error(f"Invalid JSON: {str(e)} π«")
|
839 |
+
|
840 |
+
|
841 |
|
842 |
elif selected_view == 'Clone Document':
|
843 |
st.markdown("#### Clone a document:")
|