+ db = Database()
+ length = int(self.headers['content-length'])
+ postvars = parse_qs(self.rfile.read(length).decode(), keep_blank_values=1)
+ parsed_url = urlparse(self.path)
+ lines = []
+ add_empty_line = None
+ start = int(postvars['start'][0])
+ end = int(postvars['end'][0])
+ if '/add_structured' == parsed_url.path and not 'revert' in postvars.keys():
+ date = postvars['date'][0]
+ description = postvars['description'][0]
+ start_comment = postvars['line_0_comment'][0]
+ lines = [f'{date} {description} ; {start_comment}']
+ if 'line_0_add' in postvars.keys():
+ add_empty_line = 0
+ i = j = 1
+ while f'line_{i}_comment' in postvars.keys():
+ if f'line_{i}_delete' in postvars.keys():
+ i += 1
+ continue
+ elif f'line_{i}_delete_after' in postvars.keys():
+ break
+ elif f'line_{i}_add' in postvars.keys():
+ add_empty_line = j
+ account = postvars[f'line_{i}_account'][0]
+ amount = postvars[f'line_{i}_amount'][0]
+ currency = postvars[f'line_{i}_currency'][0]
+ comment = postvars[f'line_{i}_comment'][0]
+ i += 1
+ new_main = f' {account} {amount}'
+ if '' == new_main.rstrip() == comment.rstrip(): # don't write empty lines, ignore currency if nothing else set
+ continue
+ if len(amount.rstrip()) > 0:
+ new_main += f' {currency}'
+ j += 1
+ new_line = new_main
+ if comment.rstrip() != '':
+ new_line += f' ; {comment}'
+ lines += [new_line]
+ if 'add_sink' in postvars.keys():
+ temp_lines = lines.copy() + ['_']
+ try:
+ temp_bookings, _ = parse_lines(temp_lines)
+ for currency in temp_bookings[0].sink:
+ amount = temp_bookings[0].sink[currency]
+ lines += [f'Assets {amount:.2f} {currency}']
+ except HandledException:
+ pass
+ if 'add_taxes' in postvars.keys():
+ lines += db.add_taxes(lines, finish=False)
+ elif 'add_taxes2' in postvars.keys():
+ lines += db.add_taxes(lines, finish=True)
+ elif '/add_free' == parsed_url.path:
+ lines = postvars['booking'][0].splitlines()