home · contact · privacy
Simplify handling of empty and comment-only lines in structured ledger. master
authorChristian Heller <c.heller@plomlompom.de>
Thu, 6 Feb 2025 23:26:31 +0000 (00:26 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 6 Feb 2025 23:26:31 +0000 (00:26 +0100)
ledger.py
templates/_macros.tmpl

index f8f92c0d1db8a8ba4f7c64681e75d2e51a3d09f1..96520b627f00a5484aa978047ec8c60be670c9a4 100755 (executable)
--- a/ledger.py
+++ b/ledger.py
@@ -178,11 +178,6 @@ class DatLine(Dictable):
         return (self.booking_line.booking.is_questionable if self.booking_line
                 else False)
 
-    @property
-    def is_empty(self) -> bool:
-        """Return if both .code and .comment are empty."""
-        return not bool(self.code or self.comment)
-
     @property
     def raw_nbsp(self) -> str:
         """Return .raw but ensure whitespace as &nbsp;, and at least one."""
@@ -427,9 +422,8 @@ class Handler(PlomHttpHandler):
         if action == 'move':
             id_ = self.server.move_booking(id_, dir_ == 'up')
             return Path(self.path).joinpath(f'#{id_}')
-        elif action == 'copy':
-            id_ = self.server.copy_booking(id_, dir_ == 'to_end')
-            return Path(EDIT_STRUCT).joinpath(f'{id_}')
+        id_ = self.server.copy_booking(id_, dir_ == 'to_end')
+        return Path(EDIT_STRUCT).joinpath(f'{id_}')
 
     def do_GET(self) -> None:
         """"Route GET requests to respective handlers."""
@@ -512,8 +506,7 @@ class Handler(PlomHttpHandler):
 
     def get_ledger(self, ctx: dict[str, Any], raw: bool) -> None:
         """Display ledger of all Bookings."""
-        ctx['dat_lines'] = [dl for dl in self.server.dat_lines
-                            if raw or not dl.is_empty]
+        ctx['dat_lines'] = self.server.dat_lines
         self._send_rendered(LEDGER_RAW if raw else LEDGER_STRUCT, ctx)
 
 
index db7a3255f9eddcc8d328bd64f3d98abbc2264678..aef28ae1f61365a2bb73003a6d89e91ee1119930 100644 (file)
@@ -32,9 +32,6 @@ table.ledger tr > td:first-child { background-color: white; }
 <form action="/ledger_{% if raw %}raw{% else %}structured{% endif %}" method="POST">
 <table class="ledger">
 {% for dat_line in dat_lines %}
-  {% if (not raw) and dat_line.is_intro and loop.index > 1 %}
-    <tr class="alternating"><td><td colspan=4>&nbsp;</td></tr>
-  {% endif %}
   <tr class="alternating{% if dat_line.is_questionable %} warning{% endif %}">
   {% if dat_line.is_intro %}
     <td id="{{dat_line.booking_id}}"><a href="#{{dat_line.booking_id}}">[#]</a><input type="submit" name="ledger_move_{{dat_line.booking_id}}_up" value="^"{% if not dat_line.booking.can_move(1) %} disabled{% endif %}/></td>
@@ -57,14 +54,18 @@ table.ledger tr > td:first-child { background-color: white; }
     {% if dat_line.is_intro %}
       <td class="date {% if dat_line.error %} invalid{% endif %}" colspan=2><a href="/bookings/{{dat_line.booking_id}}">{{dat_line.booking.date}}</a></td>
       <td{% if dat_line.error %} class="invalid"{% endif %}>{{dat_line.booking.target}}</td>
-    {% elif not dat_line.error %}
+      <td>{{dat_line.comment}}</td>
+    {% elif dat_line.error %}
+      <td class="invalid" colspan=3>{{dat_line.code}}</td>
+      <td>{{dat_line.comment}}</td>
+    {% elif dat_line.booking_line %}
       <td class="amt">{{dat_line.booking_line.amount_short}}</td>
       <td class="curr">{{dat_line.booking_line.currency|truncate(4,true,"…")}}</td>
       <td>{{dat_line.booking_line.account}}</td>
+      <td>{{dat_line.comment}}</td>
     {% else %}
-      <td class="invalid" colspan=3>{{dat_line.code}}</td>
+      <td colspan=2></td><td colspan=2>{{dat_line.comment}}&nbsp;</td>
     {% endif %}
-    <td>{{dat_line.comment}}</td>
   {% endif %}
   </tr>
   {% if dat_line.error and not raw %}