I can display datagrid content

This commit is contained in:
2026-01-08 15:19:16 +01:00
parent 70abf21c14
commit 797883dac8
8 changed files with 665 additions and 18 deletions

View File

@@ -4,6 +4,10 @@ DEFAULT_COLUMN_WIDTH = 100
ROUTE_ROOT = "/myfasthtml"
# Datagrid
ROW_INDEX_ID = "__row_index__"
DATAGRID_PAGE_SIZE = 1000
FILTER_INPUT_CID = "__filter_input__"
class Routes:
Commands = "/commands"

View File

@@ -37,10 +37,11 @@ class DbObject:
_initializing = False
_forbidden_attrs = {"_initializing", "_db_manager", "_name", "_owner", "_forbidden_attrs"}
def __init__(self, owner: BaseInstance, name=None, db_manager=None):
def __init__(self, owner: BaseInstance, name=None, db_manager=None, save_state=True):
self._owner = owner
self._name = name or owner.get_full_id()
self._db_manager = db_manager or DbManager(self._owner)
self._save_state = save_state
self._finalize_initialization()
@@ -75,6 +76,9 @@ class DbObject:
self._save_self()
def _save_self(self):
if not self._save_state:
return
props = {k: getattr(self, k) for k, v in self._get_properties().items() if
not k.startswith("_") and not k.startswith("ns")}
if props:

View File

@@ -284,6 +284,39 @@ def flatten(*args):
res.append(arg)
return res
def make_html_id(s: str | None) -> str | None:
"""
Creates a valid html id
:param s:
:return:
"""
if s is None:
return None
s = str(s).strip()
# Replace spaces and special characters with hyphens or remove them
s = re.sub(r'[^a-zA-Z0-9_-]', '-', s)
# Ensure the ID starts with a letter or underscore
if not re.match(r'^[a-zA-Z_]', s):
s = 'id_' + s # Add a prefix if it doesn't
# Collapse multiple consecutive hyphens into one
s = re.sub(r'-+', '-', s)
# Replace trailing hyphens with underscores
s = re.sub(r'-+$', '_', s)
return s
def make_safe_id(s: str | None):
if s is None:
return None
res = re.sub('-', '_', make_html_id(s)) # replace '-' by '_'
return res.lower() # no uppercase
@utils_rt(Routes.Commands)
def post(session, c_id: str, client_response: dict = None):
"""