Verified Commit 2095f1bf authored by Jakob Moser's avatar Jakob Moser
Browse files

Show card ids in admin interface

Closes #16
parent 3f8c3776
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
import re

from babel.numbers import format_currency
from rich.text import Text
from textual.widgets import DataTable
@@ -5,6 +7,12 @@ from textual.widgets import DataTable
from poolpay.model.Person import Person


def to_chunked_hex(i: int) -> str:
    i_hex = hex(i).removeprefix("0x")
    chunks = re.findall(r"..", i_hex)
    return ":".join(chunks)


def to_row(p: Person) -> tuple[str, str, Text, str]:
    balance = format_currency(p.balance_cents / 100, "EUR", locale="de_DE")
    style = "green" if p.balance_cents > 0 else "red" if p.balance_cents < 0 else ""
@@ -13,13 +21,13 @@ def to_row(p: Person) -> tuple[str, str, Text, str]:
        p.name,
        p.cl_account_name,
        Text(balance, style=style),
        "N/A",
        ", ".join(to_chunked_hex(card.id) for card in p.cards),
    )


class PersonsTable(DataTable):
    def on_mount(self) -> None:
        self.add_columns("Name", "CL-Account", "Kontostand", "Karten-IDs")
        self.add_columns("Name", "CL-Account", "Kontostand", "Karten-ID")
        self.add_all_persons()

    def add_all_persons(self) -> None:
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ class Card(Retrievable):

    id: Mapped[int] = mapped_column(primary_key=True)
    owner_uuid: Mapped[UUID] = mapped_column(ForeignKey("person.uuid"))
    owner: Mapped[Person] = relationship()
    owner: Mapped[Person] = relationship(back_populates="cards")

    @property
    def primary_key(self) -> int:
+9 −1
Original line number Diff line number Diff line
from __future__ import annotations

from typing import TYPE_CHECKING

from babel.numbers import format_currency
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.orm import Mapped, mapped_column, relationship

from poolpay.model.Base import Base

if TYPE_CHECKING:
    from poolpay.model.Card import Card
from poolpay.model.IntLike import IntLike


@@ -25,6 +32,7 @@ class Person(Base):
    name: Mapped[str]
    cl_account_name: Mapped[str] = mapped_column(unique=True)
    balance_cents: Mapped[int] = mapped_column(default=0)
    cards: Mapped[list[Card]] = relationship(back_populates="owner")

    @property
    def balance_str(self) -> str: