From: Christian Heller Date: Sun, 26 Jan 2025 11:39:17 +0000 (+0100) Subject: Add structured handling of intro lines. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/static/%7B%7Bprefix%7D%7D/%27%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28escapeHTML%28span%5B2%5D%29%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28%27?a=commitdiff_plain;h=eb0b706bb21d1ac988f2987790bcd759d092041d;p=plomledger Add structured handling of intro lines. --- diff --git a/ledger.py b/ledger.py index 87f58f5..364ca1f 100755 --- a/ledger.py +++ b/ledger.py @@ -126,14 +126,17 @@ class IntroLine(BookingLine): def __init__(self, booking: 'Booking', code: str) -> None: super().__init__(booking) + self.date = '#' + self.target = '' if code[0].isspace(): self.errors += ['intro line indented'] toks = code.lstrip().split(maxsplit=1) if len(toks) != 2: self.errors += ['illegal number of tokens'] - if len(toks) < 1: + elif len(toks) < 1: return - self.date = '#' + else: + self.target = toks[1] try: dt_date.fromisoformat(toks[0]) except ValueError: @@ -246,8 +249,10 @@ class Handler(PlomHttpHandler): comment = self.postvars.first(f'line_{lineno}_comment') for name in input_names: input_ = self.postvars.first(f'line_{lineno}_{name}') - if name == 'intro': + if name == 'date': data = input_ + elif name == 'target': + data += f' {input_}' elif name == 'error': data = f'{indent}{input_}' elif name == 'account': diff --git a/templates/_macros.tmpl b/templates/_macros.tmpl index 1412c84..dd45db6 100644 --- a/templates/_macros.tmpl +++ b/templates/_macros.tmpl @@ -29,7 +29,8 @@ td.invalid, tr.warning td.invalid { background-color: #ff0000; } {% else %} {% if dat_line.is_intro %} - {{dat_line.code}} + {{dat_line.booking_line.date}} + {{dat_line.booking_line.target}} {% elif not dat_line.error %} {{dat_line.booking_line.amount_short}} {{dat_line.booking_line.currency|truncate(4,true,"…")}} diff --git a/templates/edit_structured.tmpl b/templates/edit_structured.tmpl index 6e13a9a..89919e5 100644 --- a/templates/edit_structured.tmpl +++ b/templates/edit_structured.tmpl @@ -14,7 +14,8 @@ {% for dat_line in dat_lines %} {% if dat_line.is_intro %} - + + {% elif not dat_line.error %}