home · contact · privacy
Improve Booking-specific view.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 20 Jan 2025 11:51:51 +0000 (12:51 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 20 Jan 2025 11:51:51 +0000 (12:51 +0100)
ledger.py
templates/booking.tmpl [new file with mode: 0644]

index 8a50435fb30162e98157f13afdf58957b42ffe22..24e83119da101ef3c5af6bb8f3ec0e858e9d553c 100755 (executable)
--- 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 (file)
index 0000000..1bfea62
--- /dev/null
@@ -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 %}
+<table>
+{% for l in dat_lines %}
+  <tr class="{{l.type}}">
+  {% if l.type == "value" %}
+    <td class="amt">{{l.booking_line.amt}}</td><td class="curr">{{l.booking_line.curr|truncate(4,true,"…")}}</td><td>{{l.booking_line.acc}}</td>
+  {% elif l.type == "intro" %}
+    <td class="code" colspan=3><a href="/booking/{{l.booking_id}}">{{l.code}}</a></td>
+  {% else %}
+    <td colspan=3>{{l.code}}</td>
+  {% endif %}
+  <td>{{l.comment}}</td>
+  </tr>
+{% endfor %}
+</table>
+{% endblock %}
+