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 (parent:
1b9c909
)
Improve ledger.py.
author
Christian Heller
<c.heller@plomlompom.de>
Mon, 16 Oct 2023 23:05:57 +0000
(
01:05
+0200)
committer
Christian Heller
<c.heller@plomlompom.de>
Mon, 16 Oct 2023 23:05:57 +0000
(
01:05
+0200)
ledger.py
patch
|
blob
|
history
diff --git
a/ledger.py
b/ledger.py
index 0dbc9fe4debe3c133a766d039394d1828a88a600..276b1cc87a07d5dd4b30323871736886405e217c 100755
(executable)
--- a/
ledger.py
+++ b/
ledger.py
@@
-282,7
+282,10
@@
class MyServer(BaseHTTPRequestHandler):
new_main = f'{account} {amount} {currency}'
if '' == new_main.rstrip() == comment.rstrip(): # don't write empty lines
continue
new_main = f'{account} {amount} {currency}'
if '' == new_main.rstrip() == comment.rstrip(): # don't write empty lines
continue
- lines += [f'{new_main} ; {comment}']
+ new_line = new_main
+ if comment.rstrip() != '':
+ new_line += f' ; {comment}'
+ lines += [new_line]
elif '/add_free' == parsed_url.path:
lines = postvars['booking'][0].splitlines()
start = int(postvars['start'][0])
elif '/add_free' == parsed_url.path:
lines = postvars['booking'][0].splitlines()
start = int(postvars['start'][0])
@@
-391,7
+394,7
@@
class MyServer(BaseHTTPRequestHandler):
lines = []
line_sep = '<br />'
for comment in db.comments:
lines = []
line_sep = '<br />'
for comment in db.comments:
- line = f'; {comment}' if comment != '' else ''
+ line = f'
; {comment}' if comment != '' else ''
lines += [line + line_sep]
for booking in db.bookings:
i = booking.start_line
lines += [line + line_sep]
for booking in db.bookings:
i = booking.start_line
@@
-434,26
+437,27
@@
edit:
input_lines = ''
last_line = 0
def inpu(name, val=""):
input_lines = ''
last_line = 0
def inpu(name, val=""):
+ val = val if val is not None else ""
safe_val = html.escape(str(val))
return f'<input name="{name}" value="{safe_val}" />'
if len(bookings) == 0:
today = str(datetime.datetime.now())[:10]
safe_val = html.escape(str(val))
return f'<input name="{name}" value="{safe_val}" />'
if len(bookings) == 0:
today = str(datetime.datetime.now())[:10]
- input_lines += f'{inpu("date", today)} {inpu("description")} ; {inpu("comment")}<br />'
+ input_lines += f'{inpu("date", today)} {inpu("description")} ; {inpu("
line_0_
comment")}<br />'
last_line = 1
else:
booking = bookings[0]
last_line = len(comments)
last_line = 1
else:
booking = bookings[0]
last_line = len(comments)
- input_lines += f'{inpu("date", booking.date_string)} {inpu("description", booking.description)} ; {inpu("comment", comments[0])}<br />'
+ input_lines += f'{inpu("date", booking.date_string)} {inpu("description", booking.description)} ; {inpu("
line_0_
comment", comments[0])}<br />'
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]
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]
- input_lines += f'{inpu(
"line_{i}_account", account)} {inpu("line_{i}_amount", amount)} {inpu("line_{i}_currency", currency)} ; {inpu(
"line_{i}_comment", comments[i])}<br />'
+ input_lines += f'{inpu(
f"line_{i}_account", account)} {inpu(f"line_{i}_amount", amount)} {inpu(f"line_{i}_currency", currency)} ; {inpu(f
"line_{i}_comment", comments[i])}<br />'
for j in range(bonus_lines):
i = j + last_line
for j in range(bonus_lines):
i = j + last_line
- input_lines += f'{inpu(
"line_{i}_account")} {inpu("line_{i}_amount")} {inpu("line_{i}_currency")} ; {inpu(
"line_{i}_comment")}<br />'
+ input_lines += f'{inpu(
f"line_{i}_account")} {inpu(f"line_{i}_amount")} {inpu(f"line_{i}_currency")} ; {inpu(f
"line_{i}_comment")}<br />'
return f'{self.header_add_form("add_structured")}{input_lines}{self.footer_add_form(start, end)}'
return f'{self.header_add_form("add_structured")}{input_lines}{self.footer_add_form(start, end)}'