2021-05-20 00:38:00 +02:00
|
|
|
from flask import Blueprint, Response
|
2019-12-08 22:43:49 +01:00
|
|
|
from typing import Dict, Any
|
|
|
|
|
|
|
|
from bemani.data import News
|
|
|
|
from bemani.frontend.app import loginrequired, render_react
|
|
|
|
from bemani.frontend.templates import templates_location
|
|
|
|
from bemani.frontend.static import static_location
|
2021-05-20 00:38:00 +02:00
|
|
|
from bemani.frontend.types import g
|
|
|
|
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
home_pages = Blueprint(
|
2022-10-15 20:56:30 +02:00
|
|
|
"home_pages",
|
2019-12-08 22:43:49 +01:00
|
|
|
__name__,
|
|
|
|
template_folder=templates_location,
|
|
|
|
static_folder=static_location,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def format_news(news: News) -> Dict[str, Any]:
|
|
|
|
return {
|
2022-10-15 20:56:30 +02:00
|
|
|
"timestamp": news.timestamp,
|
|
|
|
"title": news.title,
|
|
|
|
"body": news.body,
|
2019-12-08 22:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-15 20:56:30 +02:00
|
|
|
@home_pages.route("/")
|
2019-12-08 22:43:49 +01:00
|
|
|
@loginrequired
|
|
|
|
def viewhome() -> Response:
|
|
|
|
return render_react(
|
2022-10-15 20:56:30 +02:00
|
|
|
g.config.get("name", "e-AMUSEMENT Network"),
|
|
|
|
"home.react.js",
|
2019-12-08 22:43:49 +01:00
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"news": [format_news(news) for news in g.data.local.network.get_all_news()],
|
|
|
|
},
|
2019-12-08 22:43:49 +01:00
|
|
|
)
|