X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;ds=sidebyside;f=ledger.py;h=276b1cc87a07d5dd4b30323871736886405e217c;hb=a628dc4404bec729a4989c7d2198eac474d667c1;hp=640c63afca0a601488ca55fce96a311cec60aa89;hpb=ed21ddf65324afb6cdce3aec0b97449e6c5c2829;p=misc diff --git a/ledger.py b/ledger.py index 640c63a..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 @@ -426,6 +429,7 @@ edit: return f'{self.header_add_form("add_free")}{self.footer_add_form(start, end)}' def add_structured(self, db, start=0, end=0, bonus_lines=10): + import datetime lines = db.get_lines(start, end) bookings, comments = parse_lines(lines) if len(bookings) > 1: @@ -433,25 +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: - input_lines += f'{inpu("date")} {inpu("description")} ; {inpu("comment")}
' + today = str(datetime.datetime.now())[:10] + 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)}'