First Working version. I can add table
This commit is contained in:
226
src/main.py
226
src/main.py
@@ -1,16 +1,222 @@
|
||||
# This is a sample Python script.
|
||||
# global layout
|
||||
import logging.config
|
||||
|
||||
# Press Shift+F10 to execute it or replace it with your code.
|
||||
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
|
||||
import yaml
|
||||
from fasthtml.common import *
|
||||
|
||||
from assets.css import my_managing_tools_style
|
||||
from auth.auth_manager import AuthManager
|
||||
from components.DrawerLayoutOld import DrawerLayout as DrawerLayoutOld
|
||||
from components.DrawerLayoutOld import Page
|
||||
from components.addstuff.AddStuffApp import add_stuff_app
|
||||
from components.addstuff.constants import ROUTE_ROOT as ADD_STUFF_ROUTE_ROOT
|
||||
from components.datagrid.DataGrid import DATAGRID_PATH, datagrid_app
|
||||
from components.datagrid_new.DataGridApp import datagrid_new_app
|
||||
from components.datagrid_new.constants import ROUTE_ROOT as DATAGRID_NEW_ROUTE_ROOT
|
||||
from components.debugger.DebuggerApp import debugger_app
|
||||
from components.debugger.constants import ROUTE_ROOT as DEBUGGER_ROUTE_ROOT
|
||||
from components.drawerlayout.DrawerLayoutApp import drawer_layout_app
|
||||
from components.drawerlayout.components import DrawerLayout
|
||||
from components.drawerlayout.components.DrawerLayout import DrawerLayout
|
||||
from components.drawerlayout.constants import ROUTE_ROOT as DRAWER_LAYOUT_ROUTE_ROOT
|
||||
from components.form.FormApp import form_app
|
||||
from components.form.constants import ROUTE_ROOT as FORM_ROUTE_ROOT
|
||||
from components.login.LoginApp import login_app
|
||||
from components.login.components.Login import Login
|
||||
from components.login.constants import ROUTE_ROOT as LOGIN_ROUTE_ROOT
|
||||
from components.login.constants import Routes as LoginRoutes
|
||||
from components.page_layout_new import page_layout_new, page_layout_lite
|
||||
from components.register.RegisterApp import register_app
|
||||
from components.register.components.Register import Register
|
||||
from components.register.constants import ROUTE_ROOT as REGISTER_ROUTE_ROOT
|
||||
from components.register.constants import Routes as RegisterRoutes
|
||||
from components.tabs.TabsApp import tabs_app
|
||||
from components.tabs.constants import ROUTE_ROOT as TABS_ROUTE_ROOT
|
||||
from components.themecontroller.ThemeControllerApp import theme_controller_app
|
||||
from components.themecontroller.constants import ROUTE_ROOT as THEME_CONTROLLER_ROUTE_ROOT
|
||||
from constants import Routes
|
||||
from core.dbengine import DbException
|
||||
from core.instance_manager import NO_SESSION, NOT_LOGGED, InstanceManager
|
||||
from core.settings_management import SettingsManager
|
||||
from pages.admin_import_settings import AdminImportSettings, IMPORT_SETTINGS_PATH, import_settings_app
|
||||
from pages.another_grid import get_datagrid2
|
||||
from pages.basic_test import BASIC_TEST_PATH, basic_test_app, get_basic_test
|
||||
from pages.testing_datagrid import get_datagrid
|
||||
from pages.testing_restore_state import testing_restore_state
|
||||
|
||||
# logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||
# Load the YAML logging configuration
|
||||
with open('logging.yaml', 'r') as f:
|
||||
config = yaml.safe_load(f)
|
||||
|
||||
# At the top of your script or module
|
||||
logging.config.dictConfig(config)
|
||||
|
||||
# daisy_ui_links_v4 = (
|
||||
# Link(href="https://cdn.jsdelivr.net/npm/daisyui@latest/dist/full.min.css", rel="stylesheet", type="text/css"),
|
||||
# Script(src="https://cdn.tailwindcss.com"),
|
||||
# )
|
||||
|
||||
daisy_ui_links_v4 = (
|
||||
Link(href="./assets/daisyui-4.12.10-full-min.css", rel="stylesheet", type="text/css"),
|
||||
Script(src="./assets/tailwindcss.js"),
|
||||
)
|
||||
|
||||
daisy_ui_links = (
|
||||
Link(href="https://cdn.jsdelivr.net/npm/daisyui@5", rel="stylesheet", type="text/css"),
|
||||
Link(href="https://cdn.jsdelivr.net/npm/daisyui@5/themes.css", rel="stylesheet", type="text/css"),
|
||||
Script(src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"),
|
||||
)
|
||||
|
||||
main_links = (Script(src="./assets/main.js"),
|
||||
Link(rel="stylesheet", href="./assets/main.css", type="text/css"),)
|
||||
|
||||
drawer_layout = (Script(src="./components/drawerlayout/assets/DrawerLayout.js"),
|
||||
Link(rel="stylesheet", href="./components/drawerlayout/assets/DrawerLayout.css"),)
|
||||
|
||||
datagridOld = (Script(src="./components/datagrid/DataGrid.js"),
|
||||
Link(rel="stylesheet", href="./components/datagrid/DataGrid.css"))
|
||||
|
||||
drw_layout_old = (Script(src="./assets/DrawerLayout.js", defer=True),
|
||||
Link(rel="stylesheet", href="./assets/DrawerLayout.css"))
|
||||
|
||||
datagrid = (Script(src="./components/datagrid_new/assets/Datagrid.js"),
|
||||
Link(rel="stylesheet", href="./components/datagrid_new/assets/Datagrid.css"))
|
||||
|
||||
addstuff = (Script(src="./components/addstuff/assets/addstuff.js"),)
|
||||
|
||||
tabs = (Script(src="./components/tabs/assets/tabs.js"),
|
||||
Link(rel="stylesheet", href="./components/tabs/assets/tabs.css"),)
|
||||
|
||||
debugger = (Script(type="module", src="./components/debugger/assets/Debugger.js"),)
|
||||
|
||||
routes = (
|
||||
Mount(LOGIN_ROUTE_ROOT, login_app, name="login"),
|
||||
Mount(REGISTER_ROUTE_ROOT, register_app, name="register"),
|
||||
Mount(THEME_CONTROLLER_ROUTE_ROOT, theme_controller_app, name="theme_controller"),
|
||||
Mount(DRAWER_LAYOUT_ROUTE_ROOT, drawer_layout_app, name="main"),
|
||||
Mount(ADD_STUFF_ROUTE_ROOT, add_stuff_app, name="add_stuff"),
|
||||
Mount(TABS_ROUTE_ROOT, tabs_app, name="tabs"),
|
||||
Mount(FORM_ROUTE_ROOT, form_app, name="form"),
|
||||
Mount(DATAGRID_NEW_ROUTE_ROOT, datagrid_new_app, name="datagrid_new"),
|
||||
Mount(DEBUGGER_ROUTE_ROOT, debugger_app, name="debugger"),
|
||||
|
||||
Mount(f"/{BASIC_TEST_PATH}", basic_test_app, name="basic test"),
|
||||
Mount(f"/{DATAGRID_PATH}", datagrid_app, name="datagrid"),
|
||||
Mount(f"/{IMPORT_SETTINGS_PATH}", import_settings_app, name="import_settings"),
|
||||
|
||||
)
|
||||
|
||||
|
||||
def print_hi(name):
|
||||
# Use a breakpoint in the code line below to debug your script.
|
||||
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
|
||||
# The `before` function is a *Beforeware* function. These are functions that run before a route handler is called.
|
||||
def before(request, session):
|
||||
# This sets the `auth` attribute in the request scope, and gets it from the session.
|
||||
# The session is a Starlette session, which is a dict-like object which is cryptographically signed,
|
||||
# so it can't be tampered with.
|
||||
# The `auth` key in the scope is automatically provided to any handler which requests it, and can not
|
||||
# be injected by the user using query params, cookies, etc, so it should be secure to use.
|
||||
|
||||
# auth = request.scope['auth'] = sess.session('auth', None)
|
||||
if not AuthManager.is_authenticated(session):
|
||||
return RedirectResponse(LOGIN_ROUTE_ROOT + LoginRoutes.Login, status_code=303)
|
||||
|
||||
|
||||
# Press the green button in the gutter to run the script.
|
||||
if __name__ == '__main__':
|
||||
print_hi('PyCharm')
|
||||
# To create a Beforeware object, we pass the function itself, and optionally a list of regexes to skip.
|
||||
bware = Beforeware(before, skip=[r'/favicon\.ico',
|
||||
r'/static/.*',
|
||||
r'.*\.css',
|
||||
LOGIN_ROUTE_ROOT + LoginRoutes.Login,
|
||||
LOGIN_ROUTE_ROOT + LoginRoutes.Logout,
|
||||
LOGIN_ROUTE_ROOT + LoginRoutes.LoginByEmail,
|
||||
REGISTER_ROUTE_ROOT + RegisterRoutes.Register,
|
||||
REGISTER_ROUTE_ROOT + RegisterRoutes.RegisterByEmail, ])
|
||||
|
||||
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
|
||||
app, rt = fast_app(
|
||||
before=bware,
|
||||
hdrs=(daisy_ui_links,
|
||||
main_links, my_managing_tools_style,
|
||||
drawer_layout, addstuff,
|
||||
tabs, debugger, datagrid),
|
||||
live=True,
|
||||
routes=routes,
|
||||
debug=True,
|
||||
pico=False,
|
||||
)
|
||||
|
||||
settings_manager = SettingsManager()
|
||||
settings_manager.init_user(NO_SESSION, NOT_LOGGED)
|
||||
|
||||
import_settings = AdminImportSettings(settings_manager, None)
|
||||
pages = [
|
||||
Page("My table", get_datagrid, id="my_table"),
|
||||
Page("new settings", import_settings, id="import_settings"),
|
||||
Page("Basic test", get_basic_test, id="basic_test"),
|
||||
Page("Restore state", testing_restore_state, id="testing_states"),
|
||||
Page("Another Table", get_datagrid2, id="another_table"),
|
||||
]
|
||||
|
||||
login = Login(settings_manager)
|
||||
register = Register(settings_manager)
|
||||
InstanceManager.register_many(login, register)
|
||||
|
||||
|
||||
@rt(Routes.Root)
|
||||
def get(session):
|
||||
try:
|
||||
main = InstanceManager.get(session,
|
||||
DrawerLayout.create_component_id(session),
|
||||
DrawerLayout,
|
||||
settings_manager=settings_manager)
|
||||
return page_layout_lite(session, settings_manager, main)
|
||||
except DbException:
|
||||
return RedirectResponse(LOGIN_ROUTE_ROOT + LoginRoutes.Logout, status_code=303)
|
||||
|
||||
|
||||
@rt(Routes.Logout)
|
||||
def get(session):
|
||||
AuthManager.logout_user(session)
|
||||
return RedirectResponse('/', status_code=303)
|
||||
|
||||
|
||||
@rt("/test")
|
||||
def get(session):
|
||||
return (Title("Another Project Management"),
|
||||
datagridOld, drw_layout_old, daisy_ui_links_v4,
|
||||
Input(type='checkbox', value='light', cls='toggle theme-controller'),
|
||||
DrawerLayoutOld(pages),)
|
||||
|
||||
|
||||
# Error Handling
|
||||
@app.get("/{path:path}")
|
||||
def not_found(path: str, session=None):
|
||||
"""Handler for 404 Not Found errors."""
|
||||
error_content = Div(
|
||||
H1("404 - Page Not Found", cls="text-3xl font-bold text-gray-800 mb-4"),
|
||||
P(f"Sorry, the page '/{path}' does not exist.", cls="mb-4"),
|
||||
A("Return Home", href="/",
|
||||
cls="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"),
|
||||
cls="max-w-2xl mx-auto bg-white p-6 rounded-lg shadow-md text-center"
|
||||
)
|
||||
|
||||
return page_layout_new(
|
||||
session=session,
|
||||
settings_manager=settings_manager,
|
||||
content=error_content
|
||||
)
|
||||
|
||||
|
||||
setup_toasts(app)
|
||||
|
||||
|
||||
@rt('/toasting')
|
||||
def get(session):
|
||||
# Normally one toast is enough, this allows us to see
|
||||
# different toast types in action.
|
||||
add_toast(session, f"Toast is being cooked", "info")
|
||||
add_toast(session, f"Toast is ready", "success")
|
||||
add_toast(session, f"Toast is getting a bit crispy", "warning")
|
||||
add_toast(session, f"Toast is burning!", "error")
|
||||
return Titled("I like toast")
|
||||
|
||||
|
||||
serve(port=5001)
|
||||
|
||||
Reference in New Issue
Block a user