if 'save' in postvars.keys():
if start == end == 0:
db.append(lines)
+ redir_url = f'/#last'
else:
db.replace(start, end, lines)
+ redir_url = f'/#{start}'
self.send_response(301)
- redir_url = '/'
self.send_header('Location', redir_url)
self.end_headers()
else:
def ledger2_as_html(self, db):
single_c_tmpl = jinja2.Template('<span class="comment">{{c|e}}</span><br />')
booking_tmpl = jinja2.Template("""
-<p>{{date}} {{desc}} <span class="comment">{{head_comment|e}}</span>
+<p id="{{start}}"><a href="#{{start}}">{{date}}</a> {{desc}} <span class="comment">{{head_comment|e}}</span>
[edit: <a href="/add_structured?start={{start}}&end={{end}}">structured</a>
/ <a href="/add_free?start={{start}}&end={{end}}">free</a>
| copy:<a href="/copy_structured?start={{start}}&end={{end}}">structured</a>
def ledger_as_html(self, db):
single_c_tmpl = jinja2.Template('<span class="comment">{{c|e}}</span><br />')
booking_tmpl = jinja2.Template("""
-<p>{{date}} {{desc}} <span class="comment">{{head_comment|e}}</span>
+<p id="{{start}}"><a {% if last %}id="last"{% endif %} href="#{{start}}">{{date}}</a> {{desc}} <span class="comment">{{head_comment|e}}</span>
[edit: <a href="/add_structured?start={{start}}&end={{end}}">structured</a>
/ <a href="/add_free?start={{start}}&end={{end}}">free</a>
| copy:<a href="/copy_structured?start={{start}}&end={{end}}">structured</a>
""")
elements_to_write = []
last_i = i = 0
+ last_start = db.bookings[-1].start_line
for booking in db.bookings:
i = booking.start_line
elements_to_write += [single_c_tmpl.render(c=c) for c in db.comments[last_i:i] if c != '']
money = f'{booking_line[1]} {booking_line[2]}'
booking_lines += [{'acc': booking_line[0], 'money':money, 'comment':comment}]
elements_to_write += [booking_tmpl.render(
+ last=booking.start_line == last_start,
start=booking.start_line,
end=booking_end,
date=booking.date_string,
def add_free(self, db, start=0, end=0, copy=False):
tmpl = jinja2.Template("""
-<form method="POST" action="{{action}}">
+<form method="POST" action="{{action|e}}">
<textarea name="booking" rows=10 cols=80>
{% for line in lines %}{{ line }}
{% endfor %}
lines = db.get_lines(start, end)
if copy:
start = end = 0
- return tmpl.render(start=start, end=end, lines=lines)
+ return tmpl.render(action='add_free', 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("""