fix callbacks
This commit is contained in:
parent
6d3b82ece2
commit
86b80f87f8
@ -11,8 +11,8 @@ def category_lookup(category):
|
||||
return category.id
|
||||
|
||||
|
||||
def get_task(task_id: int) -> Task:
|
||||
return Task.get_by_id(task_id)
|
||||
def get_task(item_id: int) -> Task:
|
||||
return Task.get_by_id(item_id)
|
||||
|
||||
|
||||
def add_task(
|
||||
@ -35,15 +35,15 @@ def add_task(
|
||||
|
||||
|
||||
def update_task(
|
||||
task_id: int,
|
||||
item_id: int,
|
||||
**kwargs,
|
||||
) -> Task:
|
||||
with db.atomic():
|
||||
if category := kwargs.pop("category", None):
|
||||
kwargs["category_id"] = category_lookup(category)
|
||||
query = Task.update(kwargs).where(Task.id == task_id)
|
||||
query = Task.update(kwargs).where(Task.id == item_id)
|
||||
query.execute()
|
||||
task = Task.get_by_id(task_id)
|
||||
task = Task.get_by_id(item_id)
|
||||
return task
|
||||
|
||||
|
||||
|
@ -113,7 +113,7 @@ class TableEditor(App):
|
||||
def __init__(self, default_view="default"):
|
||||
super().__init__()
|
||||
self.filters = {}
|
||||
self.sort_string = "due,status"
|
||||
self.sort_string = "" # TODO: default sort
|
||||
self._load_view(default_view)
|
||||
self.search_query = ""
|
||||
self.saved_cursor_pos = (1, 0)
|
||||
@ -192,20 +192,23 @@ class TableEditor(App):
|
||||
if self.table.cursor_column == 0:
|
||||
cur_row = self.table.cursor_row
|
||||
item_id = int(self.table.get_cell_at((cur_row, 0)))
|
||||
# TODO: deletable items need a delete
|
||||
self.update_item_callback(item_id, deleted=True)
|
||||
self._save_cursor()
|
||||
self.refresh_data()
|
||||
|
||||
def action_add_item(self):
|
||||
# if filtering on type, status, or category
|
||||
# the new item should use the selected value
|
||||
|
||||
# the new item should use the selected value if filtered
|
||||
# prepopulate with either the field default or the current filter
|
||||
prepopulated = {
|
||||
field.name: self.filters.get(field.name, field.default)
|
||||
for field in self.TABLE_CONFIG
|
||||
}
|
||||
# TODO: need to split type_ and status
|
||||
prepopulated = {}
|
||||
for fc in self.TABLE_CONFIG:
|
||||
val = self.filters.get(fc.field, fc.default)
|
||||
if val is not None:
|
||||
# enums use comma separated filters
|
||||
if fc.enum:
|
||||
prepopulated[fc.field] = val.split(",")[0]
|
||||
else:
|
||||
prepopulated[fc.field] = val
|
||||
|
||||
new_item = self.add_item_callback(**prepopulated)
|
||||
self.refresh_data(restore_cursor=False)
|
||||
@ -232,6 +235,7 @@ class TableEditor(App):
|
||||
# trigger item_id to be saved on the next cursor move
|
||||
# this avoids filtered columns disappearing right away
|
||||
# and tons of DB writes
|
||||
# TODO: status hard coded here
|
||||
self._register_save_on_move(item_id, status=next_val)
|
||||
|
||||
def _register_save_on_move(self, item_id, **kwargs):
|
||||
@ -245,7 +249,6 @@ class TableEditor(App):
|
||||
self.update_item_callback(**self.save_on_move)
|
||||
self._save_cursor()
|
||||
self.refresh_data()
|
||||
# reset status
|
||||
self.save_on_move = None
|
||||
|
||||
def move_cursor_to_item(self, item_id):
|
||||
@ -356,6 +359,7 @@ class TableEditor(App):
|
||||
# preprocess/validate the field being saved
|
||||
try:
|
||||
update_data[field] = cconf.preprocessor(new_value)
|
||||
# raise Exception(update_data)
|
||||
self.update_item_callback(item_id, **update_data)
|
||||
self.refresh_data()
|
||||
except NotifyValidationError as e:
|
||||
|
@ -55,9 +55,6 @@ class TT(TableEditor):
|
||||
TableColumnConfig("due", "Due", default="", preprocessor=due_preprocessor),
|
||||
TableColumnConfig("category", "Category", default="main"),
|
||||
)
|
||||
update_item_callback = update_task
|
||||
update_item_callback = add_task
|
||||
get_item_callback = get_task
|
||||
|
||||
BINDINGS = [
|
||||
# saved views
|
||||
@ -68,6 +65,9 @@ class TT(TableEditor):
|
||||
def __init__(self, default_view="default"):
|
||||
super().__init__()
|
||||
self._load_view(default_view)
|
||||
self.update_item_callback = update_task
|
||||
self.add_item_callback = add_task
|
||||
self.get_item_callback = get_task
|
||||
|
||||
def _load_view(self, name):
|
||||
try:
|
||||
@ -122,7 +122,6 @@ class TT(TableEditor):
|
||||
|
||||
|
||||
def run(default_view):
|
||||
initialize_db()
|
||||
app = TT(default_view)
|
||||
app.run()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user