forked from s3lph/matemat
24 lines
926 B
Python
24 lines
926 B
Python
|
|
from typing import Any, Dict, Union
|
|
|
|
from matemat.webserver import pagelet, RequestArguments, PageletResponse, TemplateResponse
|
|
from matemat.db import MatematDatabase
|
|
|
|
|
|
@pagelet('/')
|
|
def main_page(method: str,
|
|
path: str,
|
|
args: RequestArguments,
|
|
session_vars: Dict[str, Any],
|
|
headers: Dict[str, str])\
|
|
-> Union[bytes, str, PageletResponse]:
|
|
with MatematDatabase('test.db') as db:
|
|
if 'authenticated_user' in session_vars:
|
|
uid: int = session_vars['authenticated_user']
|
|
authlevel: int = session_vars['authentication_level']
|
|
user = db.get_user(uid)
|
|
products = db.list_products()
|
|
return TemplateResponse('productlist.html', authuser=user, products=products, authlevel=authlevel)
|
|
else:
|
|
users = db.list_users()
|
|
return TemplateResponse('userlist.html', users=users)
|