very basic diva frontend

This commit is contained in:
= 2024-06-11 01:06:24 +02:00
parent 5ba041b32b
commit 1b5b9d7f9a
5 changed files with 72 additions and 3 deletions

View File

@ -21,7 +21,7 @@ title:
reboot_end_time: "05:00" reboot_end_time: "05:00"
database: database:
host: "localhost" host: "192.168.192.12"
username: "aime" username: "aime"
password: "aime" password: "aime"
name: "aime" name: "aime"
@ -33,7 +33,7 @@ database:
memcached_host: "localhost" memcached_host: "localhost"
frontend: frontend:
enable: False enable: True
port: 8080 port: 8080
loglevel: "info" loglevel: "info"
secret: "" secret: ""
@ -58,7 +58,7 @@ aimedb:
listen_address: "" listen_address: ""
loglevel: "info" loglevel: "info"
port: 22345 port: 22345
key: "" key: "Copyright(C)SEGA"
id_secret: "" id_secret: ""
id_lifetime_seconds: 86400 id_lifetime_seconds: 86400

View File

@ -2,8 +2,10 @@ from titles.diva.index import DivaServlet
from titles.diva.const import DivaConstants from titles.diva.const import DivaConstants
from titles.diva.database import DivaData from titles.diva.database import DivaData
from titles.diva.read import DivaReader from titles.diva.read import DivaReader
from .frontend import DivaFrontend
index = DivaServlet index = DivaServlet
database = DivaData database = DivaData
reader = DivaReader reader = DivaReader
frontend = DivaFrontend
game_codes = [DivaConstants.GAME_CODE] game_codes = [DivaConstants.GAME_CODE]

52
titles/diva/frontend.py Normal file
View File

@ -0,0 +1,52 @@
from typing import List
from starlette.routing import Route, Mount
from starlette.requests import Request
from starlette.responses import Response, RedirectResponse
from os import path
import yaml
import jinja2
from core.frontend import FE_Base, UserSession
from core.config import CoreConfig
from .database import DivaData
from .config import DivaConfig
from .const import DivaConstants
class DivaFrontend(FE_Base):
def __init__(
self, cfg: CoreConfig, environment: jinja2.Environment, cfg_dir: str
) -> None:
super().__init__(cfg, environment)
self.data = DivaData(cfg)
self.game_cfg = DivaConfig()
if path.exists(f"{cfg_dir}/{DivaConstants.CONFIG_NAME}"):
self.game_cfg.update(
yaml.safe_load(open(f"{cfg_dir}/{DivaConstants.CONFIG_NAME}"))
)
self.nav_name = "diva"
def get_routes(self) -> List[Route]:
return [
Route("/", self.render_GET, methods=['GET'])
]
async def render_GET(self, request: Request) -> bytes:
template = self.environment.get_template(
"titles/diva/templates/diva_index.jinja"
)
usr_sesh = self.validate_session(request)
if not usr_sesh:
usr_sesh = UserSession()
if usr_sesh.user_id > 0:
profile = self.data.profile
resp = Response(template.render(
title=f"{self.core_config.server.name} | {self.nav_name}",
game_list=self.environment.globals["game_list"],
sesh=vars(usr_sesh),
profile=profile
))
return resp
else:
return RedirectResponse("/login")

View File

View File

@ -0,0 +1,15 @@
{% extends "core/templates/index.jinja" %}
{% block content %}
<style>
{% include 'titles/diva/templates/css/diva_style.css' %}
</style>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1>{{ title }}</h1>
<p>{{ description }}</p>
</div>
</div>
</div>
{% endblock %}