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])
lines = []
line_sep = '<br />'
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
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'<input name="{name}" value="{safe_val}" />'
if len(bookings) == 0:
today = str(datetime.datetime.now())[:10]
- input_lines += f'{inpu("date", today)} {inpu("description")} ; {inpu("comment")}<br />'
+ input_lines += f'{inpu("date", today)} {inpu("description")} ; {inpu("line_0_comment")}<br />'
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])}<br />'
+ input_lines += f'{inpu("date", booking.date_string)} {inpu("description", booking.description)} ; {inpu("line_0_comment", comments[0])}<br />'
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])}<br />'
+ 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])}<br />'
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")}<br />'
+ 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)}'