+ def add_free(self, db, start=0, end=0, copy=False):
+ tmpl = jinja2.Template("""
+<form method="POST" action="{{action}}">
+<textarea name="booking" rows=10 cols=80>
+{% for line in lines %}{{ line }}
+{% endfor %}
+</textarea>
+<input type="hidden" name="start" value={{start}} />
+<input type="hidden" name="end" value={{end}} />
+<input type="submit" name="save" value="save!">
+</form>
+""")
+ lines = db.get_lines(start, end)
+ if copy:
+ start = end = 0
+ return tmpl.render(start=start, end=end, lines=lines)
+
+ def add_structured(self, db, start=0, end=0, copy=False, temp_lines=[], add_empty_line=None):
+ tmpl = jinja2.Template("""
+<form method="POST" action="{{action}}">
+<input type="submit" name="check" value="check" />
+<input type="submit" name="revert" value="revert" />
+<input type="submit" name="add_taxes" value="add taxes" />
+<br />
+<input name="date" value="{{date}}" size=9 />
+<input name="description" value="{{desc}}" list="descriptions" />
+<textarea name="line_0_comment" rows=1 cols=20>{{head_comment}}</textarea>
+<input type="submit" name="line_0_add" value="[+]" />
+<br />
+{% for line in booking_lines %}
+<input name="line_{{line.i}}_account" value="{{line.acc}}" size=40 list="accounts" />
+<input type="number" name="line_{{line.i}}_amount" value="{{line.amt}}" size=10 />
+<input name="line_{{line.i}}_currency" value="{{line.curr}}" size=3 list="currencies" />
+<textarea name="line_{{line.i}}_comment" rows=1 cols={% if line.comm_cols %}{{line.comm_cols}}{% else %}20{% endif %}>{{line.comment}}</textarea>
+<input type="submit" name="line_{{line.i}}_delete" value="[x]" />
+<input type="submit" name="line_{{line.i}}_add" value="[+]" />
+<br />
+{% endfor %}
+{% for name, items in datalist_sets.items() %}
+<datalist id="{{name}}">
+{% for item in items %}
+ <option value="{{item}}">{{item}}</option>
+{% endfor %}
+</datalist>
+{% endfor %}
+<input type="hidden" name="start" value={{start}} />
+<input type="hidden" name="end" value={{end}} />
+<input type="submit" name="save" value="save!">
+</form>
+""")
+ import datetime
+ lines = temp_lines if len(''.join(temp_lines)) > 0 else db.get_lines(start, end)
+ bookings, comments = parse_lines(lines)
+ if len(bookings) > 1:
+ raise HandledException('can only edit single Booking')
+ if add_empty_line is not None:
+ comments = comments[:add_empty_line+1] + [''] + comments[add_empty_line+1:]
+ booking = bookings[0]
+ booking.lines = booking.lines[:add_empty_line+1] + [''] + booking.lines[add_empty_line+1:]
+ action = 'add_structured'
+ 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)
+ content = ''
+ today = str(datetime.datetime.now())[:10]
+ booking_lines = []
+ if copy:
+ start = end = 0
+ desc = head_comment = ''
+ if len(bookings) == 0:
+ for i in range(1, 3):
+ booking_lines += [{'i': i, 'acc': '', 'amt': '', 'curr': '', 'comment': ''}]
+ date=today
+ else:
+ booking = bookings[0]
+ desc = booking.description
+ date = today if copy else booking.date_string
+ head_comment=comments[0]
+ last_line = len(comments)
+ 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]
+ booking_lines += [{
+ 'i': i,
+ 'acc': account,
+ 'amt': amount,
+ 'curr': currency if currency else '',
+ 'comment': comments[i],
+ 'comm_cols': len(comments[i])}]
+ content += tmpl.render(
+ action=action,
+ date=date,
+ desc=desc,
+ head_comment=head_comment,
+ booking_lines=booking_lines,
+ datalist_sets=datalist_sets,
+ start=start,
+ end=end)
+ return content