move db error handling from per-page to base page
This commit is contained in:
parent
140d1cb1db
commit
deae96d8fa
@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
from random import choice
|
from random import choice
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
@ -6,10 +7,13 @@ from rio import Component, Column, Text, Row, Rectangle, Button, TextStyle, Colo
|
|||||||
from src.ez_lan_manager import UserService
|
from src.ez_lan_manager import UserService
|
||||||
from src.ez_lan_manager.components.UserInfoBoxButton import UserInfoBoxButton
|
from src.ez_lan_manager.components.UserInfoBoxButton import UserInfoBoxButton
|
||||||
from src.ez_lan_manager.services.AccountingService import AccountingService
|
from src.ez_lan_manager.services.AccountingService import AccountingService
|
||||||
|
from src.ez_lan_manager.services.DatabaseService import NoDatabaseConnectionError, DatabaseService
|
||||||
from src.ez_lan_manager.services.TicketingService import TicketingService
|
from src.ez_lan_manager.services.TicketingService import TicketingService
|
||||||
from src.ez_lan_manager.services.SeatingService import SeatingService
|
from src.ez_lan_manager.services.SeatingService import SeatingService
|
||||||
from src.ez_lan_manager.types.SessionStorage import SessionStorage
|
from src.ez_lan_manager.types.SessionStorage import SessionStorage
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__.split(".")[-1])
|
||||||
|
|
||||||
class StatusButton(Component):
|
class StatusButton(Component):
|
||||||
STYLE = TextStyle(fill=Color.from_hex("121212"), font_size=0.5)
|
STYLE = TextStyle(fill=Color.from_hex("121212"), font_size=0.5)
|
||||||
label: str
|
label: str
|
||||||
@ -138,7 +142,7 @@ class UserInfoAndLoginBox(Component):
|
|||||||
else:
|
else:
|
||||||
user = self.session[UserService].get_user(self.session[SessionStorage].user_id)
|
user = self.session[UserService].get_user(self.session[SessionStorage].user_id)
|
||||||
if user is None:
|
if user is None:
|
||||||
print("ERROR")
|
logger.warning("User could not be found, this should not have happend.")
|
||||||
a_s = self.session[AccountingService]
|
a_s = self.session[AccountingService]
|
||||||
return Rectangle(
|
return Rectangle(
|
||||||
content=Column(
|
content=Column(
|
||||||
|
|||||||
@ -2,9 +2,9 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import * # type: ignore
|
from typing import * # type: ignore
|
||||||
|
|
||||||
from rio import Component, event, Spacer, Card, Container, Column, Row, Rectangle, TextStyle, Color, Text
|
from rio import Component, event, Spacer, Card, Container, Column, Row, TextStyle, Color, Text
|
||||||
|
|
||||||
from src.ez_lan_manager import ConfigurationService
|
from src.ez_lan_manager import ConfigurationService, DatabaseService
|
||||||
from src.ez_lan_manager.components.DesktopNavigation import DesktopNavigation
|
from src.ez_lan_manager.components.DesktopNavigation import DesktopNavigation
|
||||||
|
|
||||||
class BasePage(Component):
|
class BasePage(Component):
|
||||||
@ -14,6 +14,11 @@ class BasePage(Component):
|
|||||||
async def on_window_size_change(self):
|
async def on_window_size_change(self):
|
||||||
await self.force_refresh()
|
await self.force_refresh()
|
||||||
|
|
||||||
|
@event.on_populate
|
||||||
|
async def check_db_connection(self):
|
||||||
|
if not self.session[DatabaseService].is_connected:
|
||||||
|
self.session.navigate_to("./db-error")
|
||||||
|
|
||||||
def build(self) -> Component:
|
def build(self) -> Component:
|
||||||
if self.content is None:
|
if self.content is None:
|
||||||
content = Spacer()
|
content = Spacer()
|
||||||
@ -63,3 +68,4 @@ class BasePage(Component):
|
|||||||
align_y=0.5,
|
align_y=0.5,
|
||||||
style=TextStyle(fill=Color.from_hex("FFFFFF"), font_size=0.8)
|
style=TextStyle(fill=Color.from_hex("FFFFFF"), font_size=0.8)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@ from rio import Column, Component, event
|
|||||||
from src.ez_lan_manager import ConfigurationService, NewsService
|
from src.ez_lan_manager import ConfigurationService, NewsService
|
||||||
from src.ez_lan_manager.components.NewsPost import NewsPost
|
from src.ez_lan_manager.components.NewsPost import NewsPost
|
||||||
from src.ez_lan_manager.pages import BasePage
|
from src.ez_lan_manager.pages import BasePage
|
||||||
from src.ez_lan_manager.services.DatabaseService import NoDatabaseConnectionError
|
|
||||||
from src.ez_lan_manager.types.News import News
|
from src.ez_lan_manager.types.News import News
|
||||||
|
|
||||||
|
|
||||||
@ -13,10 +12,7 @@ class NewsPage(Component):
|
|||||||
@event.on_populate
|
@event.on_populate
|
||||||
async def on_populate(self) -> None:
|
async def on_populate(self) -> None:
|
||||||
await self.session.set_title(f"{self.session[ConfigurationService].get_lan_info().name} - Neuigkeiten")
|
await self.session.set_title(f"{self.session[ConfigurationService].get_lan_info().name} - Neuigkeiten")
|
||||||
try:
|
self.news_posts = self.session[NewsService].get_news()[:8]
|
||||||
self.news_posts = self.session[NewsService].get_news()[:8]
|
|
||||||
except NoDatabaseConnectionError:
|
|
||||||
self.session.navigate_to("db-error")
|
|
||||||
|
|
||||||
def build(self) -> Component:
|
def build(self) -> Component:
|
||||||
posts = [NewsPost(
|
posts = [NewsPost(
|
||||||
|
|||||||
@ -36,9 +36,12 @@ class DatabaseService:
|
|||||||
self._connection: Optional[mariadb.Connection] = None
|
self._connection: Optional[mariadb.Connection] = None
|
||||||
self._reestablishment_lock = False
|
self._reestablishment_lock = False
|
||||||
self.establish_new_connection()
|
self.establish_new_connection()
|
||||||
|
self.calls = 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_connected(self) -> bool:
|
def is_connected(self) -> bool:
|
||||||
|
self.calls += 1
|
||||||
|
print(f"{self.calls} Calls")
|
||||||
try:
|
try:
|
||||||
self._connection.ping()
|
self._connection.ping()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user