Skip to content
Snippets Groups Projects

Change how users delete entries from the database

Merged Kien Le requested to merge feature-new_way_to_delete_database_entry into master
@@ -524,12 +524,15 @@ class UiDBInfoDialog(OneWindowAtATimeDialog):
@QtCore.Slot()
def delete_table_row(self, row_delete_button: QtWidgets.QPushButton):
"""
Remove all data edit widgets from a row and notify the user that they
deleted a row from the data table. Also convert the delete button into
an undo button.
Delete a row from the table.
On the backend, format a SQL statement to delete the row from the
database and queue it to be run when saving changes.
If the row contains data that is not in the database (i.e. rows added
by the user), remove it completely.
Otherwise, remove all data edit widgets from a row and notify the user
that they deleted the row. Also convert the delete button into an undo
button. On the backend, format a SQL statement to delete the row from
the database and queue it to be run when saving changes.
:param row_delete_button: the delete button assigned to the row to be
deleted
@@ -543,8 +546,11 @@ class UiDBInfoDialog(OneWindowAtATimeDialog):
row_idx = self.data_table_widget.rowAt(delete_button_y)
if row_idx >= len(self.data_list):
# If the deleted row is one that the user added, we can simply
# delete it.
# Deleting a row that is not in the database. Because no rows that
# are in the database are removed, and the user can only add rows
# at the end of the data table, it suffices to check that the index
# of the removed row is greater than the length of the data
# retrieved from the database.
self.remove_row(row_idx)
else:
primary_key = self.data_list[row_idx][0]
@@ -559,8 +565,6 @@ class UiDBInfoDialog(OneWindowAtATimeDialog):
row_idx, self.total_col - 1, undo_button
)
# Format the SQL statement that will delete the chosen row from the
# database and queue it for execution.
delete_sql = (f"DELETE FROM {self.table_name} "
f"WHERE {self.col_name}='{primary_key}'")
delete_sql += self.delete_sql_supplement
@@ -655,7 +659,7 @@ class UiDBInfoDialog(OneWindowAtATimeDialog):
# del self.changes_by_rowid[widget_idx]
# except KeyError:
# pass
if self.has_changes() and need_confirmation:
if self.has_changes() and not need_confirmation:
save_prompt = ('Do you want to save the changes you made? This '
'action cannot be undone.')
choice = QMessageBox.question(self, 'Saving changes', save_prompt,
Loading