- input_lines += f'{inpu(f"line_{i}_account")} {inpu(f"line_{i}_amount")} {inpu(f"line_{i}_currency")} ; {inpu(f"line_{i}_comment")}<br />'
- 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")}<br />'
+ 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'<datalist id="{name}">' + "\n"
+ for item in datalist_sets[name]:
+ safe_item = html.escape(item)
+ datalist += f'<option value="{safe_item}">{safe_item}</option>' + "\n"
+ return f"{datalist}</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)}'