use THing.type field
This commit is contained in:
parent
2bf3d126e9
commit
fe5be1115b
@ -43,8 +43,8 @@ def get_view(name):
|
|||||||
raise ValueError(f"no such view! {name}")
|
raise ValueError(f"no such view! {name}")
|
||||||
|
|
||||||
def get_column(name):
|
def get_column(name):
|
||||||
if name == "id":
|
if name in ("id", "type"):
|
||||||
return {"field_name": "id", "display_name": "ID", "read_only": True}
|
return {"field_name": name, "display_name": name, "read_only": True}
|
||||||
|
|
||||||
for col in _load_config().get("columns", []):
|
for col in _load_config().get("columns", []):
|
||||||
if col["field_name"] == name:
|
if col["field_name"] == name:
|
||||||
|
@ -87,6 +87,10 @@ def get_things(
|
|||||||
# no _in query for JSON fields, so use OR
|
# no _in query for JSON fields, so use OR
|
||||||
condition = False
|
condition = False
|
||||||
for cond in val:
|
for cond in val:
|
||||||
|
# handle type filtering the same way
|
||||||
|
if param == "type":
|
||||||
|
condition |= Thing.type == cond
|
||||||
|
else:
|
||||||
condition |= Thing.data[param] == cond
|
condition |= Thing.data[param] == cond
|
||||||
query = query.where(condition)
|
query = query.where(condition)
|
||||||
|
|
||||||
|
@ -105,13 +105,13 @@ class TableEditor(App):
|
|||||||
- sort_string
|
- sort_string
|
||||||
"""
|
"""
|
||||||
self.table_config = []
|
self.table_config = []
|
||||||
view = config.get_view(name)
|
self.view = config.get_view(name)
|
||||||
|
|
||||||
# FIXME: special case during things conversion
|
# FIXME: special case during things conversion
|
||||||
# if recurring, different column definition
|
# if recurring, different column definition
|
||||||
|
|
||||||
# set up columns
|
# set up columns
|
||||||
for col_name in view["columns"]:
|
for col_name in self.view["columns"]:
|
||||||
col = config.get_column(col_name)
|
col = config.get_column(col_name)
|
||||||
field_type = col.get("field_type", "text")
|
field_type = col.get("field_type", "text")
|
||||||
field_cls = get_col_cls(field_type)
|
field_cls = get_col_cls(field_type)
|
||||||
@ -129,8 +129,9 @@ class TableEditor(App):
|
|||||||
self.table_config.append(cc)
|
self.table_config.append(cc)
|
||||||
|
|
||||||
# load default filters
|
# load default filters
|
||||||
self.filters = view["filters"]
|
self.filters = self.view["filters"]
|
||||||
self.sort_string = view["sort"]
|
self.sort_string = self.view["sort"]
|
||||||
|
self.defaults = self.view["defaults"]
|
||||||
|
|
||||||
def _db_item_to_row(self, item):
|
def _db_item_to_row(self, item):
|
||||||
"""
|
"""
|
||||||
@ -139,7 +140,8 @@ class TableEditor(App):
|
|||||||
row = []
|
row = []
|
||||||
|
|
||||||
for col in self.table_config:
|
for col in self.table_config:
|
||||||
# TODO: decide how this should work once things is done
|
# look up properties first (ID, type, etc.)
|
||||||
|
# & fall back to data JSON if not found
|
||||||
try:
|
try:
|
||||||
val = getattr(item, col.field)
|
val = getattr(item, col.field)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@ -241,12 +243,20 @@ class TableEditor(App):
|
|||||||
for fc in self.table_config:
|
for fc in self.table_config:
|
||||||
if fc.read_only:
|
if fc.read_only:
|
||||||
continue
|
continue
|
||||||
val = self.filters.get(fc.field, fc.default)
|
val = self.defaults.get(fc.field, fc.default)
|
||||||
if val is not None:
|
if val is not None:
|
||||||
if "," in val:
|
if "," in val:
|
||||||
val = val.split(",")[0] # TODO: fix hack for enums
|
val = val.split(",")[0] # TODO: fix hack for enums
|
||||||
prepopulated[fc.field] = val
|
prepopulated[fc.field] = val
|
||||||
|
|
||||||
|
# required fields
|
||||||
|
for required in ["type"]:
|
||||||
|
if required not in prepopulated:
|
||||||
|
try:
|
||||||
|
prepopulated[required] = self.defaults[required]
|
||||||
|
except KeyError:
|
||||||
|
raise Exception(f"must set a default for {required}")
|
||||||
|
|
||||||
new_item = self.add_item_callback(**prepopulated)
|
new_item = self.add_item_callback(**prepopulated)
|
||||||
self.refresh_data(restore_cursor=False)
|
self.refresh_data(restore_cursor=False)
|
||||||
self.move_cursor_to_item(new_item.id) # TODO: check success here
|
self.move_cursor_to_item(new_item.id) # TODO: check success here
|
||||||
|
Loading…
Reference in New Issue
Block a user