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}")
|
||||
|
||||
def get_column(name):
|
||||
if name == "id":
|
||||
return {"field_name": "id", "display_name": "ID", "read_only": True}
|
||||
if name in ("id", "type"):
|
||||
return {"field_name": name, "display_name": name, "read_only": True}
|
||||
|
||||
for col in _load_config().get("columns", []):
|
||||
if col["field_name"] == name:
|
||||
|
@ -87,7 +87,11 @@ def get_things(
|
||||
# no _in query for JSON fields, so use OR
|
||||
condition = False
|
||||
for cond in val:
|
||||
condition |= Thing.data[param] == cond
|
||||
# handle type filtering the same way
|
||||
if param == "type":
|
||||
condition |= Thing.type == cond
|
||||
else:
|
||||
condition |= Thing.data[param] == cond
|
||||
query = query.where(condition)
|
||||
|
||||
sort_expressions = _parse_sort_string(sort)
|
||||
|
@ -105,13 +105,13 @@ class TableEditor(App):
|
||||
- sort_string
|
||||
"""
|
||||
self.table_config = []
|
||||
view = config.get_view(name)
|
||||
self.view = config.get_view(name)
|
||||
|
||||
# FIXME: special case during things conversion
|
||||
# if recurring, different column definition
|
||||
|
||||
# set up columns
|
||||
for col_name in view["columns"]:
|
||||
for col_name in self.view["columns"]:
|
||||
col = config.get_column(col_name)
|
||||
field_type = col.get("field_type", "text")
|
||||
field_cls = get_col_cls(field_type)
|
||||
@ -129,8 +129,9 @@ class TableEditor(App):
|
||||
self.table_config.append(cc)
|
||||
|
||||
# load default filters
|
||||
self.filters = view["filters"]
|
||||
self.sort_string = view["sort"]
|
||||
self.filters = self.view["filters"]
|
||||
self.sort_string = self.view["sort"]
|
||||
self.defaults = self.view["defaults"]
|
||||
|
||||
def _db_item_to_row(self, item):
|
||||
"""
|
||||
@ -139,7 +140,8 @@ class TableEditor(App):
|
||||
row = []
|
||||
|
||||
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:
|
||||
val = getattr(item, col.field)
|
||||
except AttributeError:
|
||||
@ -241,12 +243,20 @@ class TableEditor(App):
|
||||
for fc in self.table_config:
|
||||
if fc.read_only:
|
||||
continue
|
||||
val = self.filters.get(fc.field, fc.default)
|
||||
val = self.defaults.get(fc.field, fc.default)
|
||||
if val is not None:
|
||||
if "," in val:
|
||||
val = val.split(",")[0] # TODO: fix hack for enums
|
||||
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)
|
||||
self.refresh_data(restore_cursor=False)
|
||||
self.move_cursor_to_item(new_item.id) # TODO: check success here
|
||||
|
Loading…
Reference in New Issue
Block a user