From: Christian Heller Date: Sun, 29 Oct 2023 05:04:55 +0000 (+0100) Subject: Improve ledger.py X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/copy_free?a=commitdiff_plain;h=ebc562af576469da5f0011e10f80c7b0490ed959;p=misc Improve ledger.py --- diff --git a/ledger.py b/ledger.py index 0785b1a..ee6ed80 100755 --- a/ledger.py +++ b/ledger.py @@ -422,10 +422,11 @@ input[type=number] { text-align: right; font-family: monospace; } if 'save' in postvars.keys(): if start == end == 0: db.append(lines) + redir_url = f'/#last' else: db.replace(start, end, lines) + redir_url = f'/#{start}' self.send_response(301) - redir_url = '/' self.send_header('Location', redir_url) self.end_headers() else: @@ -495,7 +496,7 @@ input[type=number] { text-align: right; font-family: monospace; } def ledger2_as_html(self, db): single_c_tmpl = jinja2.Template('{{c|e}}
') booking_tmpl = jinja2.Template(""" -

{{date}} {{desc}} {{head_comment|e}} +

{{date}} {{desc}} {{head_comment|e}} [edit: structured / free | copy:structured @@ -558,7 +559,7 @@ input[type=number] { text-align: right; font-family: monospace; } def ledger_as_html(self, db): single_c_tmpl = jinja2.Template('{{c|e}}
') booking_tmpl = jinja2.Template(""" -

{{date}} {{desc}} {{head_comment|e}} +

{{date}} {{desc}} {{head_comment|e}} [edit: structured / free | copy:structured @@ -575,6 +576,7 @@ input[type=number] { text-align: right; font-family: monospace; } """) elements_to_write = [] last_i = i = 0 + last_start = db.bookings[-1].start_line for booking in db.bookings: i = booking.start_line elements_to_write += [single_c_tmpl.render(c=c) for c in db.comments[last_i:i] if c != ''] @@ -592,6 +594,7 @@ input[type=number] { text-align: right; font-family: monospace; } money = f'{booking_line[1]} {booking_line[2]}' booking_lines += [{'acc': booking_line[0], 'money':money, 'comment':comment}] elements_to_write += [booking_tmpl.render( + last=booking.start_line == last_start, start=booking.start_line, end=booking_end, date=booking.date_string, @@ -603,7 +606,7 @@ input[type=number] { text-align: right; font-family: monospace; } def add_free(self, db, start=0, end=0, copy=False): tmpl = jinja2.Template(""" -

+