Table works

This commit is contained in:
2024-10-09 15:13:40 +02:00
parent a4d0803d20
commit 4199b1c347
7 changed files with 183 additions and 47 deletions

View File

@ -16,6 +16,8 @@ from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from jinja2.runtime import Undefined as JinjaUndefined
from ums.management.interface import Interface
from ums.management.db import DB
@ -23,6 +25,8 @@ from ums.utils import AgentMessage, RiddleData, RiddleDataType, RiddleSolution,
class WebMain():
_TIME_FORMAT = "%H:%M:%S %d.%m.%Y"
def __init__(self):
self._init_app()
self._init_templates()
@ -47,8 +51,17 @@ class WebMain():
directory=TEMPLATE_PATH,
auto_reload=True
)
self.template.env.globals["timestamp2date"] = lambda t: \
datetime.fromtimestamp(t).strftime("%H:%M:%S %d.%m.%Y")
def timestamp2date(t:int|JinjaUndefined) -> str:
return "" if isinstance(t, JinjaUndefined) \
else datetime.fromtimestamp(t).strftime(self._TIME_FORMAT)
self.template.env.globals["timestamp2date"] = timestamp2date
def date2timestamp(d:str|JinjaUndefined) -> int|str:
return "" if isinstance(d, JinjaUndefined) \
else int(datetime.strptime(d, self._TIME_FORMAT).timestamp())
self.template.env.globals["date2timestamp"] = date2timestamp
def _add_routers(self):
interface_router = Interface(self.template, self.db)