forked from Hay1tsme/artemis
very basic diva frontend
This commit is contained in:
parent
5ba041b32b
commit
1b5b9d7f9a
@ -21,7 +21,7 @@ title:
|
||||
reboot_end_time: "05:00"
|
||||
|
||||
database:
|
||||
host: "localhost"
|
||||
host: "192.168.192.12"
|
||||
username: "aime"
|
||||
password: "aime"
|
||||
name: "aime"
|
||||
@ -33,7 +33,7 @@ database:
|
||||
memcached_host: "localhost"
|
||||
|
||||
frontend:
|
||||
enable: False
|
||||
enable: True
|
||||
port: 8080
|
||||
loglevel: "info"
|
||||
secret: ""
|
||||
@ -58,7 +58,7 @@ aimedb:
|
||||
listen_address: ""
|
||||
loglevel: "info"
|
||||
port: 22345
|
||||
key: ""
|
||||
key: "Copyright(C)SEGA"
|
||||
id_secret: ""
|
||||
id_lifetime_seconds: 86400
|
||||
|
||||
|
@ -2,8 +2,10 @@ from titles.diva.index import DivaServlet
|
||||
from titles.diva.const import DivaConstants
|
||||
from titles.diva.database import DivaData
|
||||
from titles.diva.read import DivaReader
|
||||
from .frontend import DivaFrontend
|
||||
|
||||
index = DivaServlet
|
||||
database = DivaData
|
||||
reader = DivaReader
|
||||
frontend = DivaFrontend
|
||||
game_codes = [DivaConstants.GAME_CODE]
|
||||
|
52
titles/diva/frontend.py
Normal file
52
titles/diva/frontend.py
Normal 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")
|
0
titles/diva/templates/css/diva_style.css
Normal file
0
titles/diva/templates/css/diva_style.css
Normal file
15
titles/diva/templates/diva_index.jinja
Normal file
15
titles/diva/templates/diva_index.jinja
Normal 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 %}
|
Loading…
Reference in New Issue
Block a user