[models] move data loader to models module

This commit is contained in:
bronsen 2026-02-07 02:52:13 +01:00
parent d2b6e11fe4
commit 6a4334263a
2 changed files with 18 additions and 22 deletions

View file

@ -55,3 +55,14 @@ async def make_teilchen_input(text: str) -> TeilchenCreate | None:
tags=" ".join(natsorted(tags)), tags=" ".join(natsorted(tags)),
text=text, text=text,
) )
async def load_initial_data() -> list[TeilchenDatum]:
return [
(0, "Name0", "Description0", "9000", "#tag0 #tag00 #tag000"),
(1, "Name1", "Description1", "9001", "#tag1 #tag11 #tag111"),
(2, "Name2", "Description2", "9002", "#tag2 #tag22 #tag222"),
(3, "Name3", "Description3", "9003", "#tag3 #tag33 #tag333"),
(4, "Name4", "Description4", "9004", "#tag4 #tag44 #tag444"),
(5, "Name5", "Description5", "9005", "#tag5 #tag55 #tag555"),
]

View file

@ -4,6 +4,11 @@ from textual.screen import Screen
from textual.widget import Widget from textual.widget import Widget
from textual.widgets import DataTable, Footer, Header, Static, Input, Button from textual.widgets import DataTable, Footer, Header, Static, Input, Button
from .models import load_initial_data
FAKE_DATA_HEADER = "pk Name Description Number Tags"
class SearchBar(Static): class SearchBar(Static):
DEFAULT_CSS = """ DEFAULT_CSS = """
@ -36,34 +41,14 @@ class SearchBar(Static):
) )
TeilchenHeader = tuple[
Literal["pk"],
Literal["Name"],
Literal["Description"],
Literal["Number"],
Literal["Tags"],
]
FAKE_DATA: list[TeilchenHeader | TeilchenDatum] = [
("pk", "Name", "Description", "Number", "Tags"),
(0, "Name0", "Description0", "9000", "#tag0 #tag00 #tag000"),
(1, "Name1", "Description1", "9001", "#tag1 #tag11 #tag111"),
(2, "Name2", "Description2", "9002", "#tag2 #tag22 #tag222"),
(3, "Name3", "Description3", "9003", "#tag3 #tag33 #tag333"),
(4, "Name4", "Description4", "9004", "#tag4 #tag44 #tag444"),
(5, "Name5", "Description5", "9005", "#tag5 #tag55 #tag555"),
]
class SearchResults(Widget): class SearchResults(Widget):
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
yield DataTable(id="table-search-result", cursor_type="row", zebra_stripes=True) yield DataTable(id="table-search-result", cursor_type="row", zebra_stripes=True)
async def on_mount(self) -> None: async def on_mount(self) -> None:
table: DataTable[None] = self.query_one(DataTable[None]) table: DataTable[None] = self.query_one(DataTable[None])
_ = table.add_columns(*FAKE_DATA[0]) # pyright: ignore[reportArgumentType] _ = table.add_columns(FAKE_DATA_HEADER)
_ = table.add_rows(FAKE_DATA[1:]) # pyright: ignore[reportArgumentType] _ = table.add_rows(await load_initial_data()) # ty:ignore[invalid-argument-type]
class AddInventoryScreen(Screen[None]): class AddInventoryScreen(Screen[None]):