From: Christian Heller Date: Mon, 16 Oct 2023 23:42:57 +0000 (+0200) Subject: To ledger.py, add entry copying. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bdb.prefix%7D%7D/conditions?a=commitdiff_plain;h=2b686c3a54fdd117075df17d7c12fd6e776c35ce;p=misc To ledger.py, add entry copying. --- diff --git a/ledger.py b/ledger.py index 7771f7f..5610293 100755 --- a/ledger.py +++ b/ledger.py @@ -315,13 +315,17 @@ class MyServer(BaseHTTPRequestHandler): params = parse_qs(parsed_url.query) start = int(params.get('start', ['0'])[0]) end = int(params.get('end', ['0'])[0]) + bonus_lines = int(params.get('bonus_lines', ['0'])[0]) if parsed_url.path == '/balance': page += self.balance_as_html(db) elif parsed_url.path == '/add_free': page += self.add_free(db, start, end) elif parsed_url.path == '/add_structured': - bonus_lines = int(params.get('bonus_lines', ['0'])[0]) page += self.add_structured(db, start, end) + elif parsed_url.path == '/copy_free': + page += self.add_free(db, start, end, copy=True) + elif parsed_url.path == '/copy_structured': + page += self.add_structured(db, start, end, copy=True) else: page += self.ledger_as_html(db) page += self.footer @@ -411,24 +415,29 @@ class MyServer(BaseHTTPRequestHandler): edit: structured / free +| copy: +structured +/ free
""" return '\n'.join(lines) def header_add_form(self, action): return f"
\n" - def footer_add_form(self, start, end): + def footer_add_form(self, start, end, copy): + if copy: + start = end = 0 return f"""
""" - def add_free(self, db, start=0, end=0): + def add_free(self, db, start=0, end=0, copy=False): content = html.escape(''.join(db.get_lines(start, end))) - return f'{self.header_add_form("add_free")}{self.footer_add_form(start, end)}' + return f'{self.header_add_form("add_free")}{self.footer_add_form(start, end, copy)}' - def add_structured(self, db, start=0, end=0, bonus_lines=10): + def add_structured(self, db, start=0, end=0, bonus_lines=10, copy=False): import datetime lines = db.get_lines(start, end) bookings, comments = parse_lines(lines) @@ -441,14 +450,15 @@ edit: safe_val = html.escape(str(val)) datalist_string = '' if datalist == '' else f'list="{datalist}"' return f'' + today = str(datetime.datetime.now())[:10] if len(bookings) == 0: - today = str(datetime.datetime.now())[:10] input_lines += f'{inpu("date", today)} {inpu("description", "", "descriptions")} ; {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, "descriptions")} ; {inpu("line_0_comment", comments[0])}
' + date_string = today if copy else booking.date_string + input_lines += f'{inpu("date", date_string)} {inpu("description", booking.description, "descriptions")} ; {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] != '': @@ -458,7 +468,7 @@ edit: input_lines += f'{inpu(f"line_{i}_account", account, "accounts")} {inpu(f"line_{i}_amount", amount)} {inpu(f"line_{i}_currency", currency, "currencies")} ; {inpu(f"line_{i}_comment", comments[i])}
' for j in range(bonus_lines): i = j + last_line - input_lines += f'{inpu(f"line_{i}_account", "", "accounts")} {inpu(f"line_{i}_amount", "", "amounts")} {inpu(f"line_{i}_currency", "€", "currencies")} ; {inpu(f"line_{i}_comment")}
' + input_lines += f'{inpu(f"line_{i}_account", "", "accounts")} {inpu(f"line_{i}_amount", "", "amounts")} {inpu(f"line_{i}_currency", "", "currencies")} ; {inpu(f"line_{i}_comment")}
' datalist_sets = {'descriptions': set(), 'accounts': set(), 'currencies': set()} for b in db.bookings: datalist_sets['descriptions'].add(b.description) @@ -475,7 +485,7 @@ edit: datalists = build_datalist('descriptions') datalists += build_datalist('accounts') datalists += build_datalist('currencies') - return f'{self.header_add_form("add_structured")}{input_lines}{datalists}{self.footer_add_form(start, end)}' + return f'{self.header_add_form("add_structured")}{input_lines}{datalists}{self.footer_add_form(start, end, copy)}' db = Database()