I can resize Datagrid columns
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
from contextlib import contextmanager
|
||||
from types import SimpleNamespace
|
||||
|
||||
@@ -6,6 +7,8 @@ from dbengine.dbengine import DbEngine
|
||||
from myfasthtml.core.instances import SingleInstance, BaseInstance
|
||||
from myfasthtml.core.utils import retrieve_user_info
|
||||
|
||||
logger = logging.getLogger("DbManager")
|
||||
|
||||
|
||||
class DbManager(SingleInstance):
|
||||
def __init__(self, parent, root=".myFastHtmlDb", auto_register: bool = True):
|
||||
@@ -52,8 +55,8 @@ class DbObject:
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
self._finalize_initialization()
|
||||
self._initializing = old_state
|
||||
self._finalize_initialization()
|
||||
|
||||
def __setattr__(self, name: str, value: str):
|
||||
if name.startswith("_") or name.startswith("ns_") or getattr(self, "_initializing", False):
|
||||
@@ -69,11 +72,24 @@ class DbObject:
|
||||
self._save_self()
|
||||
|
||||
def _finalize_initialization(self):
|
||||
if getattr(self, "_initializing", False):
|
||||
return # still under initialization
|
||||
|
||||
if self._reload_self():
|
||||
logger.debug(f"finalize_initialization ({self._name}) : Loaded existing content.")
|
||||
return
|
||||
else:
|
||||
logger.debug(
|
||||
f"finalize_initialization ({self._name}) : No existing content found, creating new entry {self._save_state=}.")
|
||||
self._save_self()
|
||||
|
||||
def _reload_self(self):
|
||||
if self._db_manager.exists_entry(self._name):
|
||||
props = self._db_manager.load(self._name)
|
||||
self.update(props)
|
||||
else:
|
||||
self._save_self()
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def _save_self(self):
|
||||
if not self._save_state:
|
||||
@@ -125,3 +141,15 @@ class DbObject:
|
||||
as_dict = self._get_properties().copy()
|
||||
as_dict = {k: v for k, v in as_dict.items() if k not in DbObject._forbidden_attrs}
|
||||
return SimpleNamespace(**as_dict)
|
||||
|
||||
def save(self):
|
||||
self._save_self()
|
||||
|
||||
def reload(self):
|
||||
self._reload_self()
|
||||
|
||||
def exists(self):
|
||||
return self._db_manager.exists_entry(self._name)
|
||||
|
||||
def get_id(self):
|
||||
return self._name
|
||||
|
||||
Reference in New Issue
Block a user