home · contact · privacy
Avoid writing of empty comments.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 2 Feb 2026 03:45:27 +0000 (04:45 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 2 Feb 2026 03:45:27 +0000 (04:45 +0100)
src/ledgplom/http.py
src/ledgplom/ledger.py

index 0c8d437f1a94844842d89f9f0395fd695d28cd03..480ff511b71f6713053b6f1c6dafb58664a848b3 100644 (file)
@@ -5,7 +5,7 @@ from typing import Any
 # plomlib
 from plomlib.web import PlomHttpHandler, PlomHttpServer, PlomQueryMap
 # ourselves
-from ledgplom.ledger import Ledger
+from ledgplom.ledger import Ledger, SEP_COMMENTS, SPACE
 
 
 _PATH_TEMPLATES = Path('templates')
@@ -72,12 +72,15 @@ class _Handler(PlomHttpHandler):
                 inputs = {key: self.postvars.first(f'line_{lineno}_{key}')
                           for key in input_names}
                 if 0 == lineno:
-                    code = inputs["date"] + ' ' + inputs["target"]
+                    line_raw = inputs['date'] + SPACE + inputs['target']
                 else:
-                    code = (' ' * int(inputs["len_indent"])
-                            + inputs["account"] + ' ' * 2
-                            + inputs["amount"] + ' ' + inputs["currency"])
-                new_lines += [f'{code} ; {inputs["comment"]}']
+                    line_raw = (
+                            SPACE * int(inputs['len_indent'])
+                            + inputs['account'] + SPACE * 2
+                            + inputs['amount'] + SPACE + inputs['currency'])
+                if (comment := inputs['comment']):
+                    line_raw += f'{SPACE}{SEP_COMMENTS}{SPACE}{comment}'
+                new_lines += [line_raw]
         new_lines += self.postvars.first('raw_lines').splitlines()
         new_id = self.server.ledger.rewrite_block(old_id, new_lines)
         return Path('/', self.pagename, f'{new_id}')
index dc0196bcebec80b6f3e2a49cf40f17c9d73562c7..c9bc62edfca93c4be850a3ffef0a3712f14eb756 100644 (file)
@@ -7,8 +7,9 @@ from pathlib import Path
 from typing import Any, Iterator, Optional, Self
 
 
-_INDENT_CHARS = {' ', '\t'}
-_SEP_COMMENTS = ';'
+SPACE = ' '
+_INDENT_CHARS = {SPACE, '\t'}
+SEP_COMMENTS = ';'
 _PREFIX_DEF = '#def '
 
 
@@ -131,7 +132,7 @@ class _DatLine:
                 else:
                     stage_count += 1
             if stage_count == 1:
-                if c != _SEP_COMMENTS:
+                if c != SEP_COMMENTS:
                     code += c
                 else:
                     stage_count += 1
@@ -165,7 +166,7 @@ class _DatLine:
         instructions = {}
         if self.comment.startswith(_PREFIX_DEF):
             parts = [part.strip() for part
-                     in self.comment[len(_PREFIX_DEF):].split(_SEP_COMMENTS)]
+                     in self.comment[len(_PREFIX_DEF):].split(SEP_COMMENTS)]
             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 ''