Updated Command to allow client_response. First implementation or UserProfile control

This commit is contained in:
2025-11-11 12:07:00 +01:00
parent c641f3fd63
commit cba4f2aab4
11 changed files with 166 additions and 26 deletions

View File

@@ -1,5 +1,11 @@
import uuid
from myfasthtml.controls.helpers import Ids
special_session = {
"user_info": {"id": "** SPECIAL SESSION **"}
}
class DuplicateInstanceError(Exception):
def __init__(self, instance):
@@ -34,6 +40,16 @@ class SingleInstance(BaseInstance):
self._instance = None
class UniqueInstance(BaseInstance):
"""
Base class for instances that can only have one instance at a time.
Does not throw exception if the instance already exists, it simply overwrites it.
"""
def __init__(self, session: dict, prefix: str, auto_register: bool = True):
super().__init__(session, prefix, auto_register)
self._instance = None
class MultipleInstance(BaseInstance):
"""
Base class for instances that can have multiple instances at a time.
@@ -79,7 +95,10 @@ class InstancesManager:
return InstancesManager.instances[key]
except KeyError:
return instance_type(session, *args, **kwargs) # it will be automatically registered
if instance_type:
return instance_type(session, *args, **kwargs) # it will be automatically registered
else:
raise
@staticmethod
def _get_session_id(session):
@@ -88,3 +107,7 @@ class InstancesManager:
if "user_info" not in session:
return "** UNKNOWN USER **"
return session["user_info"].get("id", "** INVALID SESSION **")
@staticmethod
def get_auth_proxy():
return InstancesManager.get(special_session, Ids.AuthProxy)