From: Christian Heller Date: Mon, 16 Oct 2023 23:05:57 +0000 (+0200) Subject: Improve ledger.py. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/templates?a=commitdiff_plain;h=a628dc4404bec729a4989c7d2198eac474d667c1;p=misc Improve ledger.py. --- diff --git a/ledger.py b/ledger.py index 0dbc9fe..276b1cc 100755 --- a/ledger.py +++ b/ledger.py @@ -282,7 +282,10 @@ class MyServer(BaseHTTPRequestHandler): new_main = f'{account} {amount} {currency}' if '' == new_main.rstrip() == comment.rstrip(): # don't write empty lines continue - lines += [f'{new_main} ; {comment}'] + new_line = new_main + if comment.rstrip() != '': + new_line += f' ; {comment}' + lines += [new_line] elif '/add_free' == parsed_url.path: lines = postvars['booking'][0].splitlines() start = int(postvars['start'][0]) @@ -391,7 +394,7 @@ class MyServer(BaseHTTPRequestHandler): lines = [] line_sep = '
' for comment in db.comments: - line = f'; {comment}' if comment != '' else '' + line = f' ; {comment}' if comment != '' else '' lines += [line + line_sep] for booking in db.bookings: i = booking.start_line @@ -434,26 +437,27 @@ edit: input_lines = '' last_line = 0 def inpu(name, val=""): + val = val if val is not None else "" safe_val = html.escape(str(val)) return f'' if len(bookings) == 0: today = str(datetime.datetime.now())[:10] - input_lines += f'{inpu("date", today)} {inpu("description")} ; {inpu("comment")}
' + input_lines += f'{inpu("date", today)} {inpu("description")} ; {inpu("line_0_comment")}
' last_line = 1 else: booking = bookings[0] last_line = len(comments) - input_lines += f'{inpu("date", booking.date_string)} {inpu("description", booking.description)} ; {inpu("comment", comments[0])}
' + input_lines += f'{inpu("date", booking.date_string)} {inpu("description", booking.description)} ; {inpu("line_0_comment", comments[0])}
' for i in range(1, len(comments)): account = amount = currency = '' if i < len(booking.lines) and booking.lines[i] != '': account = booking.lines[i][0] amount = booking.lines[i][1] currency = booking.lines[i][2] - input_lines += f'{inpu("line_{i}_account", account)} {inpu("line_{i}_amount", amount)} {inpu("line_{i}_currency", currency)} ; {inpu("line_{i}_comment", comments[i])}
' + input_lines += f'{inpu(f"line_{i}_account", account)} {inpu(f"line_{i}_amount", amount)} {inpu(f"line_{i}_currency", currency)} ; {inpu(f"line_{i}_comment", comments[i])}
' for j in range(bonus_lines): i = j + last_line - input_lines += f'{inpu("line_{i}_account")} {inpu("line_{i}_amount")} {inpu("line_{i}_currency")} ; {inpu("line_{i}_comment")}
' + input_lines += f'{inpu(f"line_{i}_account")} {inpu(f"line_{i}_amount")} {inpu(f"line_{i}_currency")} ; {inpu(f"line_{i}_comment")}
' return f'{self.header_add_form("add_structured")}{input_lines}{self.footer_add_form(start, end)}'