mostly working templating for landing page
This commit is contained in:
49
templating.py
Normal file
49
templating.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from flask import url_for, Flask
|
||||
from jinja2 import FileSystemLoader
|
||||
|
||||
import tomllib
|
||||
from os import sep
|
||||
from collections import namedtuple
|
||||
|
||||
def static_test_load():
|
||||
with open("static_text.toml", "rb") as f:
|
||||
return tomllib.load(f)
|
||||
|
||||
UserInfo = namedtuple('UserInfo',['id', 'name'])
|
||||
RoomInfo = namedtuple('RoomInfo',['name', 'shortcode', 'roomdata'])
|
||||
# state is an int not in db
|
||||
# 0 - value valid
|
||||
# 1 - value late
|
||||
# 2 - value missing
|
||||
SensorInfo = namedtuple('SensorInfo',['state','type','timestamp','reading'])
|
||||
|
||||
# base class for inheriting other more specific pages
|
||||
class BasePage():
|
||||
def __init__(
|
||||
self,
|
||||
jijna_env,
|
||||
target_path = "base.html.jinja" ,
|
||||
statictext = None,
|
||||
) -> None:
|
||||
self.env = jijna_env
|
||||
self.target = target_path
|
||||
self.rendervars = static_test_load() if statictext is None else statictext
|
||||
|
||||
def render(self):
|
||||
url_for('static', filename="styles.css")
|
||||
url_for('static', filename="scripts.css")
|
||||
template = self.env.get_template(self.target)
|
||||
return template.render(self.rendervars)
|
||||
|
||||
class LandingPage(BasePage):
|
||||
def __init__(
|
||||
self,
|
||||
jinja_env,
|
||||
userinfo,
|
||||
roominfo,
|
||||
target_path="landing.html.jinja",
|
||||
statictext=None,
|
||||
) -> None:
|
||||
super().__init__(jinja_env, target_path, statictext)
|
||||
self.rendervars["userinfo"] = userinfo
|
||||
self.rendervars["roominfo"] = roominfo
|
||||
Reference in New Issue
Block a user