fix deletion again

This commit is contained in:
jpt 2025-05-04 21:32:15 -05:00
parent a72c6fbaab
commit 2624bfc3ee
2 changed files with 13 additions and 3 deletions

View File

@ -23,12 +23,18 @@ def add_thing(
def update_thing(
item_id: int,
deleted: bool | None = None,
type: str | None = None,
**kwargs,
) -> Thing:
with db.atomic():
thing = Thing.get_by_id(item_id)
new_data = thing.data | kwargs
query = Thing.update(data=new_data).where(Thing.id == item_id)
updates = {"data": thing.data | kwargs}
if deleted is not None:
updates["deleted"] = deleted
if type is not None:
updates["type"] = type
query = Thing.update(**updates).where(Thing.id == item_id)
query.execute()
thing = Thing.get_by_id(item_id)
return thing

View File

@ -37,7 +37,7 @@ class TableEditor(App):
width: 10;
content-align: left middle;
}
#input_widget {
width: 100%;
margin: 0;
@ -230,6 +230,8 @@ class TableEditor(App):
ConfirmModal(f"delete [green]{current_value}[/]?"),
self._delete_item_callback,
)
else:
raise Exception("FIXME")
def _delete_item_callback(self, confirm):
if confirm and self.table.cursor_column == 0:
@ -239,6 +241,8 @@ class TableEditor(App):
self.update_item_callback(item_id, deleted=True)
self._save_cursor()
self.refresh_data()
else:
raise Exception(f"{confirm=} {self.table.cursor_column=}")
def action_add_item(self):
# the new item should use the selected value if filtered