# 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')
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}')
from typing import Any, Iterator, Optional, Self
-_INDENT_CHARS = {' ', '\t'}
-_SEP_COMMENTS = ';'
+SPACE = ' '
+_INDENT_CHARS = {SPACE, '\t'}
+SEP_COMMENTS = ';'
_PREFIX_DEF = '#def '
else:
stage_count += 1
if stage_count == 1:
- if c != _SEP_COMMENTS:
+ if c != SEP_COMMENTS:
code += c
else:
stage_count += 1
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 ''