From 752e5600964cad9f206149ab949cbf73c0d2413e Mon Sep 17 00:00:00 2001 From: Christian Heller 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; }
{% for dat_line in dat_lines %} - {% if (not raw) and dat_line.is_intro and loop.index > 1 %} - - {% endif %} {% if dat_line.is_intro %} @@ -57,14 +54,18 @@ table.ledger tr > td:first-child { background-color: white; } {% if dat_line.is_intro %} {{dat_line.booking.target}} - {% elif not dat_line.error %} + + {% elif dat_line.error %} + + + {% elif dat_line.booking_line %} + {% else %} - + {% endif %} - {% endif %} {% if dat_line.error and not raw %} -- 2.30.2
 
[#]{{dat_line.booking.date}} {{dat_line.comment}}{{dat_line.code}}{{dat_line.comment}}{{dat_line.booking_line.amount_short}} {{dat_line.booking_line.currency|truncate(4,true,"…")}} {{dat_line.booking_line.account}}{{dat_line.comment}}{{dat_line.code}}{{dat_line.comment}} {{dat_line.comment}}