diff --git a/README.md b/README.md index 976e0fb..9fa5dc1 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ So developping a htag app which work the same on desktop and on the web, should * multiple ways to handle sessions (file, mem, etc ...) * compatible with **uvloop** !!! * compatible with multiple gunicorn/uvicorn/webworkers !!! - * compatible with **tag.update()** + * compatible with [tag.update()](https://manatlan.github.io/htag/tag_update/) * works on gnu/linux, ios or windows ! * real starlette session available (in tag.state, and starlette request.session) * compatible with oauth2 authent ( [authlib](https://pypi.org/project/Authlib/) ) diff --git a/examples/oauth_example.py b/examples/oauth_example.py index 453d627..804c02b 100644 --- a/examples/oauth_example.py +++ b/examples/oauth_example.py @@ -60,6 +60,7 @@ def user(self): # -> dict or empty dict return self._rootstate.get(OAUTH_SESSION_NAME,{}) def render(self): # dynamic rendering + self.clear() self+= self.title + self.btn if self.user: self.title.set(self.user['name']) @@ -83,6 +84,8 @@ def init(self): self.oa = TagOAuth(self.state) def render(self): # dynamic rendering + self.clear() + self += self.oa self += f"You are {self.oa.user.get('name') or 'unknown'}" diff --git a/htagweb/appserver.py b/htagweb/appserver.py index 0770cc4..9177415 100644 --- a/htagweb/appserver.py +++ b/htagweb/appserver.py @@ -154,14 +154,16 @@ async def send_wrapper(message: Message) -> None: await self.app(scope, receive, send_wrapper) -def fqn2hr(fqn:str,js:str,init,session): # fqn is a "full qualified name", full ! +def fqn2hr(fqn:str,js:str,init,session,fullerror=False): # fqn is a "full qualified name", full ! if ":" not in fqn: # replace last "." by ":" fqn="".join( reversed("".join(reversed(fqn)).replace(".",":",1))) klass=getClass(fqn) - return HRenderer( klass, js, init=init, session = session) + styles=Tag.style("body.htagoff * {cursor:not-allowed !important;}") + + return HRenderer( klass, js, init=init, session = session, fullerror=fullerror, statics=[styles,]) class HRSocket(WebSocketEndpoint): encoding = "text" @@ -197,7 +199,7 @@ async def on_connect(self, websocket): """ try: - hr=fqn2hr(fqn,js,commons.url2ak(str(websocket.url)),websocket.session) + hr=fqn2hr(fqn,js,commons.url2ak(str(websocket.url)),websocket.session,fullerror=websocket.app.debug) except Exception as e: await self._sendback( websocket, str(e) ) await websocket.close() @@ -262,22 +264,45 @@ async def serve(self, request, obj ) -> HTMLResponse: jsbootstrap=""" %(jsparano)s // instanciate the WEBSOCKET - var _WS_ = new WebSocket("%(protocol)s://"+location.host+"/_/%(fqn)s"+location.search); - _WS_.onmessage = async function(e) { - // when connected -> the full HTML page is returned, installed & start'ed !!! - - let html = await _read_(e.data); - html = html.replace(" the full HTML page is returned, installed & start'ed !!! + + let html = await _read_(e.data); + html = html.replace("