use EventDays in GET admin/config_model

This commit is contained in:
Jörn-Michael Miehe 2023-09-14 23:40:06 +00:00
parent a4a0893e7d
commit c93ec06925
4 changed files with 36 additions and 16 deletions

View file

@ -1,3 +1,4 @@
from datetime import date
from io import BytesIO from io import BytesIO
from typing import cast from typing import cast
@ -7,7 +8,7 @@ from PIL import Image, ImageFont
from .advent_image import _XY, AdventImage from .advent_image import _XY, AdventImage
from .calendar_config import CalendarConfig, get_calendar_config from .calendar_config import CalendarConfig, get_calendar_config
from .config import Config, get_config from .config import Config, get_config
from .helpers import Random, list_images_auto, load_image, set_len from .helpers import EventDays, Random, list_images_auto, load_image, set_len
from .webdav import WebDAV from .webdav import WebDAV
@ -21,6 +22,22 @@ async def get_all_days(
return sorted(set(door.day for door in cal_cfg.doors)) return sorted(set(door.day for door in cal_cfg.doors))
async def get_all_event_days(
days: list[int] = Depends(get_all_days),
) -> EventDays:
"""
Aktuelles EventDays Objekt
"""
return EventDays.get(
today=date.today(),
begin_month=12,
begin_day=1,
events_after=[day - 1 for day in days],
closing_after=90,
)
async def get_all_parts( async def get_all_parts(
cfg: Config = Depends(get_config), cfg: Config = Depends(get_config),
days: list[int] = Depends(get_all_days), days: list[int] = Depends(get_all_days),

View file

@ -3,9 +3,11 @@ from datetime import date
from fastapi import APIRouter, Depends from fastapi import APIRouter, Depends
from pydantic import BaseModel from pydantic import BaseModel
from advent22_api.core.helpers import EventDays
from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config
from ..core.config import Config, get_config from ..core.config import Config, get_config
from ..core.depends import get_all_image_names, get_all_parts from ..core.depends import get_all_event_days, get_all_image_names, get_all_parts
from ..core.settings import SETTINGS from ..core.settings import SETTINGS
from ._security import require_admin, user_is_admin from ._security import require_admin, user_is_admin
@ -22,9 +24,9 @@ async def is_admin(
class ConfigModel(BaseModel): class ConfigModel(BaseModel):
class __Puzzle(BaseModel): class __Puzzle(BaseModel):
solution: str solution: str
begin: date first: date
last: date
end: date end: date
closing: date
seed: str seed: str
class __Calendar(BaseModel): class __Calendar(BaseModel):
@ -56,6 +58,7 @@ async def get_config_model(
_: None = Depends(require_admin), _: None = Depends(require_admin),
cfg: Config = Depends(get_config), cfg: Config = Depends(get_config),
cal_cfg: CalendarConfig = Depends(get_calendar_config), cal_cfg: CalendarConfig = Depends(get_calendar_config),
event_days: EventDays = Depends(get_all_event_days),
) -> ConfigModel: ) -> ConfigModel:
""" """
Kombiniert aus privaten `settings`, `config` und `calendar_config` Kombiniert aus privaten `settings`, `config` und `calendar_config`
@ -65,9 +68,9 @@ async def get_config_model(
{ {
"puzzle": { "puzzle": {
"solution": cfg.puzzle.solution, "solution": cfg.puzzle.solution,
"begin": date.today(), # TODO "first": event_days.first,
"end": date.today(), # TODO "last": event_days.last,
"closing": date.today(), # TODO "end": event_days.end,
"seed": cfg.puzzle.random_seed, "seed": cfg.puzzle.random_seed,
}, },
"calendar": { "calendar": {

View file

@ -21,13 +21,13 @@
<dd>dd-hh-mm-ss</dd> <dd>dd-hh-mm-ss</dd>
<dt>Erstes Türchen</dt> <dt>Erstes Türchen</dt>
<dd>{{ config_model.puzzle.begin }}</dd> <dd>{{ config_model.puzzle.first }}</dd>
<dt>Letztes Türchen</dt> <dt>Letztes Türchen</dt>
<dd>{{ config_model.puzzle.end }}</dd> <dd>{{ config_model.puzzle.last }}</dd>
<dt>Rätsel schließt</dt> <dt>Rätsel schließt nach</dt>
<dd>{{ config_model.puzzle.closing }}</dd> <dd>{{ config_model.puzzle.end }}</dd>
<dt>Zufalls-Seed</dt> <dt>Zufalls-Seed</dt>
<dd class="is-family-monospace"> <dd class="is-family-monospace">
@ -142,9 +142,9 @@ export default class extends Vue {
public config_model: ConfigModel = { public config_model: ConfigModel = {
puzzle: { puzzle: {
solution: "ABCDEFGHIJKLMNOPQRSTUVWX", solution: "ABCDEFGHIJKLMNOPQRSTUVWX",
begin: "01.12.2023", first: "01.12.2023",
end: "24.12.2023", last: "24.12.2023",
closing: "01.04.2024", end: "01.04.2024",
seed: "", seed: "",
}, },
calendar: { calendar: {

View file

@ -1,9 +1,9 @@
export interface ConfigModel { export interface ConfigModel {
puzzle: { puzzle: {
solution: string; solution: string;
begin: string; first: string;
last: string;
end: string; end: string;
closing: string;
seed: string; seed: string;
}; };
calendar: { calendar: {