+ content = html.escape(''.join(db.real_lines[start:end]))
+ return f'<form method="POST" action="/add_free"><textarea name="booking" rows="8" cols="80">{content}</textarea><input type="hidden" name="start" value={start} /><input type="hidden" name="end" value={end} /><input type="submit"></form>'
+
+ def add_structured(self, db, start=0, end=0, bonus_lines=10):
+ if start == end == 0:
+ lines = []
+ else:
+ lines= db.real_lines[start:end]
+ bookings, comments = parse_lines(lines)
+ if len(bookings) > 1:
+ raise HandledException('can only edit single Booking')
+ input_lines = ''
+ if len(bookings) == 0:
+ input_lines += f'<input name="date" /> <input name="description" /> ; <input name="line_0_comment" /><br />'
+ comments = ['']
+ else:
+ booking = bookings[0]
+ if booking.start_line != 0:
+ raise HandledException('need to start on first Booking line')
+ for i, comment in enumerate(comments):
+ if i == 0:
+ safe_date_string = html.escape(booking.date_string)
+ safe_description = html.escape(booking.description)
+ safe_comment = html.escape(comment)
+ input_lines += f'<input name="date" value="{safe_date_string}" /> <input name="description" value="{safe_description}" /> ; <input name="line_{i}_comment" value="{safe_comment}" /><br />'
+ continue
+ safe_account = safe_amount = safe_currency = ''
+ safe_comment = html.escape(comment)
+ if i < len(booking.lines):
+ main = booking.lines[i]
+ if main != '':
+ safe_account = html.escape(main[0])
+ safe_amount = '' if main[1] is None else html.escape(str(main[1]))
+ safe_currency = '' if main[2] is None else html.escape(main[2])
+ input_lines += f'<input name="line_{i}_account" value="{safe_account}" /> <input name="line_{i}_amount" value="{safe_amount}" /> <input name="line_{i}_currency" value="{safe_currency}" /> ; <input name="line_{i}_comment" value="{safe_comment}" /><br />'
+ for j in range(bonus_lines):
+ i = j + len(comments)
+ input_lines += f'<input name="line_{i}_account"/> <input name="line_{i}_amount"/> <input name="line_{i}_currency"/> ; <input name="line_{i}_comment" /><br />'
+ return f'<form method="POST" action="/add_structured">{input_lines}<input type="hidden" name="start" value={start} /><input type="hidden" name="end" value={end} /><input type="submit"></form>'