home · contact · privacy
Hide ;def comments in /ledger_structured. master
authorChristian Heller <c.heller@plomlompom.de>
Mon, 24 Feb 2025 12:38:46 +0000 (13:38 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 24 Feb 2025 12:38:46 +0000 (13:38 +0100)
src/run.py
src/templates/_macros.tmpl

index db54b7704acccfb31519b19bd210f8f84985956f..8c26685451256b12f5fd9808804410c3c279b36b 100755 (executable)
@@ -138,6 +138,12 @@ class DatLine(Dictable):
         self.comment = halves[1] if len(halves) > 1 else ''
         self.code = halves[0]
         self.booking_line: Optional[BookingLine] = None
         self.comment = halves[1] if len(halves) > 1 else ''
         self.code = halves[0]
         self.booking_line: Optional[BookingLine] = None
+        self.hide_comment_in_ledger = False
+
+    @property
+    def comment_in_ledger(self) -> str:
+        """What to show in structured ledger view (as per .hide_comment…)."""
+        return '' if self.hide_comment_in_ledger else self.comment
 
     @property
     def is_intro(self) -> bool:
 
     @property
     def is_intro(self) -> bool:
@@ -548,15 +554,16 @@ class Server(PlomHttpServer):
                     booked_lines.clear()
                 gap_lines += [dat_line]
         self.paths_to_descs = {}
                     booked_lines.clear()
                 gap_lines += [dat_line]
         self.paths_to_descs = {}
-        for comment in [dl.comment for dl in self.dat_lines if dl.comment]:
-            if comment.startswith(PREFIX_DEF):
-                parts = [part.strip() for part
-                         in comment[len(PREFIX_DEF):].split(';')]
-                first_part_parts = parts[0].split(maxsplit=1)
-                account_name = first_part_parts[0]
-                desc = first_part_parts[1] if len(first_part_parts) > 1 else ''
-                if desc:
-                    self.paths_to_descs[account_name] = desc
+        for dat_line in [dl for dl in self.dat_lines
+                         if dl.comment.startswith(PREFIX_DEF)]:
+            parts = [part.strip() for part
+                     in dat_line.comment[len(PREFIX_DEF):].split(';')]
+            first_part_parts = parts[0].split(maxsplit=1)
+            account_name = first_part_parts[0]
+            desc = first_part_parts[1] if len(first_part_parts) > 1 else ''
+            if desc:
+                self.paths_to_descs[account_name] = desc
+            dat_line.hide_comment_in_ledger = True
         for booking in self.bookings:
             booking.recalc_prev_next(self.bookings)
         if booking:
         for booking in self.bookings:
             booking.recalc_prev_next(self.bookings)
         if booking:
@@ -604,8 +611,10 @@ class Server(PlomHttpServer):
         for line in self.dat_lines:
             line.prev_line_empty = False
             if prev_line:
         for line in self.dat_lines:
             line.prev_line_empty = False
             if prev_line:
-                line.prev_line_empty = not prev_line.code + prev_line.comment
-            prev_line = line
+                line.prev_line_empty = not (prev_line.code
+                                            + prev_line.comment_in_ledger)
+            if prev_line or line.code + line.comment_in_ledger:  # jump over
+                prev_line = line                                 # empty start
 
     def _recalc_dat_lines(self) -> None:
         self.dat_lines = self.initial_gap_lines[:]
 
     def _recalc_dat_lines(self) -> None:
         self.dat_lines = self.initial_gap_lines[:]
index 614a7fa39693a958f02d9f77f2185d07af27bc28..a3187c9b62709c41f62320c7c244e6c0ac9aed9d 100644 (file)
@@ -32,7 +32,7 @@ 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 %}
 <form action="/ledger_{% if raw %}raw{% else %}structured{% endif %}" method="POST">
 <table class="ledger">
 {% for dat_line in dat_lines %}
-  {% if raw or dat_line.code or dat_line.comment %}
+  {% if raw or dat_line.code or dat_line.comment_in_ledger %}
 
     {% if (not raw) and dat_line.prev_line_empty %}
       <tr ><td>&nbsp;</td></tr>
 
     {% if (not raw) and dat_line.prev_line_empty %}
       <tr ><td>&nbsp;</td></tr>
@@ -66,18 +66,18 @@ table.ledger tr > td:first-child { background-color: white; }
         <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>
         <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>
-        <td>{{dat_line.comment}}</td>
+        <td>{{dat_line.comment_in_ledger}}</td>
       {% elif dat_line.error %}
         <td class="invalid" colspan=3>{{dat_line.code}}</td>
       {% elif dat_line.error %}
         <td class="invalid" colspan=3>{{dat_line.code}}</td>
-        <td>{{dat_line.comment}}</td>
+        <td>{{dat_line.comment_in_ledger}}</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>
       {% 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>
+        <td>{{dat_line.comment_in_ledger}}</td>
       {% else %}
         <td colspan=2></td>
       {% else %}
         <td colspan=2></td>
-        <td colspan=2>{{dat_line.comment}}&nbsp;</td>
+        <td colspan=2>{{dat_line.comment_in_ledger}}&nbsp;</td>
       {% endif %}
     {% endif %}
     </tr>
       {% endif %}
     {% endif %}
     </tr>