home
·
contact
·
privacy
projects
/
misc
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
3edadb6
)
Improve ledger.py
author
Christian Heller
<c.heller@plomlompom.de>
Sun, 29 Oct 2023 05:04:55 +0000
(06:04 +0100)
committer
Christian Heller
<c.heller@plomlompom.de>
Sun, 29 Oct 2023 05:04:55 +0000
(06:04 +0100)
ledger.py
patch
|
blob
|
history
diff --git
a/ledger.py
b/ledger.py
index 0785b1a7559869c074080b0775d16f1a81c2cb3a..ee6ed807ef72b4a9601acf32d25fad6ec1e0757a 100755
(executable)
--- a/
ledger.py
+++ b/
ledger.py
@@
-422,10
+422,11
@@
input[type=number] { text-align: right; font-family: monospace; }
if 'save' in postvars.keys():
if start == end == 0:
db.append(lines)
if 'save' in postvars.keys():
if start == end == 0:
db.append(lines)
+ redir_url = f'/#last'
else:
db.replace(start, end, lines)
else:
db.replace(start, end, lines)
+ redir_url = f'/#{start}'
self.send_response(301)
self.send_response(301)
- redir_url = '/'
self.send_header('Location', redir_url)
self.end_headers()
else:
self.send_header('Location', redir_url)
self.end_headers()
else:
@@
-495,7
+496,7
@@
input[type=number] { text-align: right; font-family: monospace; }
def ledger2_as_html(self, db):
single_c_tmpl = jinja2.Template('<span class="comment">{{c|e}}</span><br />')
booking_tmpl = jinja2.Template("""
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>
[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>
@@
-558,7
+559,7
@@
input[type=number] { text-align: right; font-family: monospace; }
def ledger_as_html(self, db):
single_c_tmpl = jinja2.Template('<span class="comment">{{c|e}}</span><br />')
booking_tmpl = jinja2.Template("""
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>
[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>
@@
-575,6
+576,7
@@
input[type=number] { text-align: right; font-family: monospace; }
""")
elements_to_write = []
last_i = i = 0
""")
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 != '']
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 != '']
@@
-592,6
+594,7
@@
input[type=number] { text-align: right; font-family: monospace; }
money = f'{booking_line[1]} {booking_line[2]}'
booking_lines += [{'acc': booking_line[0], 'money':money, 'comment':comment}]
elements_to_write += [booking_tmpl.render(
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,
start=booking.start_line,
end=booking_end,
date=booking.date_string,
@@
-603,7
+606,7
@@
input[type=number] { text-align: right; font-family: monospace; }
def add_free(self, db, start=0, end=0, copy=False):
tmpl = jinja2.Template("""
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 %}
<textarea name="booking" rows=10 cols=80>
{% for line in lines %}{{ line }}
{% endfor %}
@@
-616,7
+619,7
@@
input[type=number] { text-align: right; font-family: monospace; }
lines = db.get_lines(start, end)
if copy:
start = end = 0
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("""
def add_structured(self, db, start=0, end=0, copy=False, temp_lines=[], add_empty_line=None):
tmpl = jinja2.Template("""