From: Christian Heller Date: Mon, 16 Oct 2023 23:33:16 +0000 (+0200) Subject: In ledger.py, to structured booking adding add datalists based on previous inputs. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/new_day?a=commitdiff_plain;h=88432b5868d90a30de13a6745f68817d54d40092;p=misc In ledger.py, to structured booking adding add datalists based on previous inputs. --- diff --git a/ledger.py b/ledger.py index 276b1cc..7771f7f 100755 --- a/ledger.py +++ b/ledger.py @@ -436,29 +436,46 @@ edit: raise HandledException('can only edit single Booking') input_lines = '' last_line = 0 - def inpu(name, val=""): + def inpu(name, val="", datalist=""): val = val if val is not None else "" safe_val = html.escape(str(val)) - return f'' + datalist_string = '' if datalist == '' else f'list="{datalist}"' + return f'' if len(bookings) == 0: today = str(datetime.datetime.now())[:10] - input_lines += f'{inpu("date", today)} {inpu("description")} ; {inpu("line_0_comment")}
' + 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)} ; {inpu("line_0_comment", comments[0])}
' + input_lines += f'{inpu("date", booking.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] != '': account = booking.lines[i][0] amount = booking.lines[i][1] currency = booking.lines[i][2] - 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])}
' + 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")} {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)}' + 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) + for account, moneys in b.account_changes.items(): + datalist_sets['accounts'].add(account) + for currency in moneys.keys(): + datalist_sets['currencies'].add(currency) + def build_datalist(name): + datalist = f'' + "\n" + for item in datalist_sets[name]: + safe_item = html.escape(item) + datalist += f'' + "\n" + return f"{datalist}\n" + 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)}' db = Database()