From 752e5600964cad9f206149ab949cbf73c0d2413e Mon Sep 17 00:00:00 2001 From: Christian Heller <c.heller@plomlompom.de> Date: Fri, 7 Feb 2025 00:26:31 +0100 Subject: [PATCH] Simplify handling of empty and comment-only lines in structured ledger. --- ledger.py | 13 +++---------- templates/_macros.tmpl | 13 +++++++------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/ledger.py b/ledger.py index f8f92c0..96520b6 100755 --- 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 , 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) diff --git a/templates/_macros.tmpl b/templates/_macros.tmpl index db7a325..aef28ae 100644 --- a/templates/_macros.tmpl +++ b/templates/_macros.tmpl @@ -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> </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}} </td> {% endif %} - <td>{{dat_line.comment}}</td> {% endif %} </tr> {% if dat_line.error and not raw %} -- 2.30.2