From 05d0535ef9f976f788bb5fe7abb3a9b98b04b67d Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Mon, 20 Jan 2025 12:51:51 +0100 Subject: [PATCH] Improve Booking-specific view. --- ledger.py | 25 ++++++++++--------------- templates/booking.tmpl | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 templates/booking.tmpl diff --git a/ledger.py b/ledger.py index 8a50435..24e8311 100755 --- a/ledger.py +++ b/ledger.py @@ -75,12 +75,10 @@ class Booking: """Represents lines of individual booking.""" # pylint: disable=too-few-public-methods - def __init__(self, id_: int, idx_start: int, dat_lines: list[DatLine] - ) -> None: + def __init__(self, id_: int, dat_lines: list[DatLine]) -> None: self.id_ = id_ - self.idx_start = idx_start - self.idx_end = self.idx_start + len(dat_lines) - for dat_line in dat_lines: + self.dat_lines = dat_lines + for dat_line in self.dat_lines: dat_line.booking_line = BookingLine(self.id_, dat_line.code) @@ -95,9 +93,10 @@ class Handler(PlomHttpHandler): def do_GET(self) -> None: # pylint: disable=invalid-name,missing-function-docstring if self.pagename == 'booking': - b = self.server.bookings[int(self.path_toks[2])] - dat_lines = self.server.dat_lines[b.idx_start:b.idx_end] - self.send_rendered(Path('index.tmpl'), {'dat_lines': dat_lines}) + self.send_rendered( + Path('booking.tmpl'), + {'dat_lines': + self.server.bookings[int(self.path_toks[2])].dat_lines}) elif self.pagename == 'raw': self.send_rendered(Path('raw.tmpl'), {'dat_lines': self.server.dat_lines}) @@ -115,17 +114,13 @@ class Server(PlomHttpServer): DatLine(line) for line in path_dat.read_text(encoding='utf8').splitlines()] self.bookings: list[Booking] = [] - last_booking_start = -1 booking_lines: list[DatLine] = [] - for idx, dat_line in enumerate(self.dat_lines + [DatLine('')]): + for dat_line in self.dat_lines + [DatLine('')]: if dat_line.code: - if not booking_lines: - last_booking_start = idx booking_lines += [dat_line] elif booking_lines: - self.bookings += [Booking(len(self.bookings), - last_booking_start, booking_lines)] - booking_lines.clear() + self.bookings += [Booking(len(self.bookings), booking_lines)] + booking_lines = [] @property def dat_lines_sans_empty(self) -> list[DatLine]: diff --git a/templates/booking.tmpl b/templates/booking.tmpl new file mode 100644 index 0000000..1bfea62 --- /dev/null +++ b/templates/booking.tmpl @@ -0,0 +1,25 @@ +{% extends '_base.tmpl' %} + +{% block css %} +td.amt { text-align: right } +td.amt, td.curr { font-family: monospace; font-size: 1.3em; } +td.curr { text-align: center; } +{% endblock %} + +{% block content %} + +{% for l in dat_lines %} + + {% if l.type == "value" %} + + {% elif l.type == "intro" %} + + {% else %} + + {% endif %} + + +{% endfor %} +
{{l.booking_line.amt}}{{l.booking_line.curr|truncate(4,true,"…")}}{{l.booking_line.acc}}{{l.code}}{{l.code}}{{l.comment}}
+{% endblock %} + -- 2.30.2