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(
|
|
|
|
'home_pages',
|
|
|
|
__name__,
|
|
|
|
template_folder=templates_location,
|
|
|
|
static_folder=static_location,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def format_news(news: News) -> Dict[str, Any]:
|
|
|
|
return {
|
|
|
|
'timestamp': news.timestamp,
|
|
|
|
'title': news.title,
|
|
|
|
'body': news.body,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@home_pages.route('/')
|
|
|
|
@loginrequired
|
|
|
|
def viewhome() -> Response:
|
|
|
|
return render_react(
|
|
|
|
g.config.get('name', 'e-AMUSEMENT Network'),
|
|
|
|
'home.react.js',
|
|
|
|
{
|
|
|
|
'news': [format_news(news) for news in g.data.local.network.get_all_news()],
|
|
|
|
}
|
|
|
|
)
|