Source code for bacommon.docui.routes.classicleaguepresidency
# Released under the MIT License. See LICENSE for details.
#
"""Routes for the classic league-presidency doc-ui domain."""
from __future__ import annotations # Docs-generation hack.
from dataclasses import dataclass
from typing import Annotated, override
from efro.dataclassio import ioprepped, IOAttrs
import bacommon.docui.v2 as dui2
from bacommon.docui.routes import (
DocUIRoute,
DocUILocalActionBase,
DocUIState,
family_members,
)
[docs]
class LeaguePresidencyRoute(DocUIRoute):
"""Family class for classic league-presidency routes."""
[docs]
@override
@classmethod
def get_route_types(cls) -> tuple[type[DocUIRoute], ...]:
return family_members(AnyLeaguePresidencyRoute)
[docs]
@override
@classmethod
def get_window_layout(cls) -> dui2.WindowLayout:
# The page is one fixed-size block (it doesn't stretch to fill
# a window), sized for a phone screen; wide keeps that block
# the same at every ui-scale with a snug window around it.
return dui2.WindowLayout.WIDE
[docs]
@ioprepped
@dataclass
class BidState(DocUIState, state_id='classic.league_presidency.bid'):
"""The presidency page's state: the bid being composed.
Clients that speak page state carry this; older ones carry the
same value as the ``bid`` arg on the routes.
"""
bid: int = 0
[docs]
@ioprepped
@dataclass
class Root(LeaguePresidencyRoute, path='/'):
"""The presidency page for the account's current league."""
#: The bid being composed (the page's +/- buttons adjust this).
#: Only meaningful for clients without page state; others carry
#: it in :class:`BidState`.
bid: int = 0
#: Draw bounds and other debug bits.
debug: bool = False
#: Season the client was looking at when it opened us. Not
#: currently used (the page always shows the current season).
season: str | None = None
[docs]
@ioprepped
@dataclass
class SubmitBid(
LeaguePresidencyRoute, path='/', method=dui2.RequestMethod.POST
):
"""Submit a bid."""
#: See :attr:`Root.bid`.
bid: int = 0
debug: bool = False
# All routes in the family.
AnyLeaguePresidencyRoute = Root | SubmitBid
[docs]
class LeaguePresidencyLocalAction(DocUILocalActionBase):
"""Family class for classic league-presidency local-actions."""
[docs]
@override
@classmethod
def get_action_types(cls) -> tuple[type[DocUILocalActionBase], ...]:
return family_members(AnyLeaguePresidencyLocalAction)
[docs]
@ioprepped
@dataclass
class GetTokens(LeaguePresidencyLocalAction, name='get_tokens'):
"""Show the get-tokens window."""
# All local-actions in the family (just the one for now).
AnyLeaguePresidencyLocalAction = GetTokens
# Docs-generation hack; import some stuff that we likely only forward-declared
# in our actual source code so that docs tools can find it.
from typing import (Coroutine, Any, Literal, Callable,
Generator, Awaitable, Sequence, Self, TypeIs)
import asyncio
from concurrent.futures import Future
from pathlib import Path
from enum import Enum