home · contact · privacy
Extend tests, fine-tune layout of templates code for ledger_structured view. master
authorChristian Heller <c.heller@plomlompom.de>
Wed, 7 Jan 2026 23:36:36 +0000 (00:36 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 7 Jan 2026 23:36:36 +0000 (00:36 +0100)
src/ledgplom/testing.py
src/templates/_base.tmpl
src/templates/_macros.tmpl
src/templates/ledger_structured.tmpl
src/tests/empty.dat [new file with mode: 0644]
src/tests/empty.html [new file with mode: 0644]
src/tests/full.dat [new file with mode: 0644]
src/tests/full.html [new file with mode: 0644]
src/tests/test.dat [deleted file]
src/tests/test.html [deleted file]

index 4bc4ba944f29d4838e730ada53c293a7f47d4ea3..0bcb54548c1c1b8e437f9a38a24c14fda41d25a2 100644 (file)
@@ -24,8 +24,10 @@ def run_tests() -> None:
         print(f'{msg_prefix} FAILED – {abort_msg}')
         sys_exit(1)
 
         print(f'{msg_prefix} FAILED – {abort_msg}')
         sys_exit(1)
 
-    jinja = JinjaEnv(loader=JinjaFSLoader(PATH_TEMPLATES), autoescape=True)
-    tmpl = jinja.get_template(f'{PAGENAME_LEDGER_STRUCTURED}.tmpl')
+    tmpl = JinjaEnv(loader=JinjaFSLoader(PATH_TEMPLATES),
+                    autoescape=True,
+                    trim_blocks=True,
+                    ).get_template(f'{PAGENAME_LEDGER_STRUCTURED}.tmpl')
     for path in [p for p in _PATH_TESTS.iterdir()
                  if p.parts[-1].endswith(_EXT_DAT)]:
         with Path(str(path)[:-len(_EXT_DAT)] + _EXT_HTML
     for path in [p for p in _PATH_TESTS.iterdir()
                  if p.parts[-1].endswith(_EXT_DAT)]:
         with Path(str(path)[:-len(_EXT_DAT)] + _EXT_HTML
index b5d2bf1f39bcdea6493d7f1d9abc43ae2072ff03..d91f5d8370d03a175525b9c198fa4a34270797da 100644 (file)
@@ -4,7 +4,8 @@
 <head>
 <meta charset="UTF-8">
 <script>
 <head>
 <meta charset="UTF-8">
 <script>
-{% block script %}{% endblock %}
+{% block script %}
+{% endblock %}
 </script>
 <style>
 html {
 </script>
 <style>
 html {
@@ -37,30 +38,31 @@ td {
 div.critical, td.critical, tr.critical, span.critical, input[type="submit"].critical {
     {{macros.css_bg_red()}}
 }
 div.critical, td.critical, tr.critical, span.critical, input[type="submit"].critical {
     {{macros.css_bg_red()}}
 }
-{% block css %}{% endblock %}
+{% block css %}
+{% endblock %}
 </style>
 </head>
 <body>
 </style>
 </head>
 <body>
-
 <div id="header">
 <div id="header">
-<form action="{{path}}" method="POST">
-<span class="disable_on_change">
-ledger <a href="/ledger_structured">structured</a>
-/ <a href="/ledger_raw">raw</a>
-· <a href="/balance">balance</a>
+    <form action="{{path}}" method="POST">
+        <span class="disable_on_change">
+            ledger <a href="/ledger_structured">structured</a>
+            / <a href="/ledger_raw">raw</a>
+            · <a href="/balance">balance</a>
 {% if unsaved_changes %}
 {% if unsaved_changes %}
-    <span class="critical">unsaved changes:
+            <span class="critical">
+                · unsaved changes:
+                <input type="submit"name="file_load" value="reload" />
+                · <input type="submit" name="file_save" value="save">
+                &nbsp;
+            </span>
+{% else %}
+            · <input type="submit"name="file_load" value="reload" />
 {% endif %}
 {% endif %}
-<input type="submit"name="file_load" value="reload" />
-{% if unsaved_changes %}
-    · <input type="submit" name="file_save" value="save">
-    &nbsp;</span>
-{% endif %}
-</span>
-</form>
+        </span>
+    </form>
 </div>
 </div>
-
-{% block content %}{% endblock %}
+{% block content %}
+{% endblock %}
 </body>
 </html>
 </body>
 </html>
index dcb3f828d6aac9b450e24d2ffa4403d24953b774..46a55a3c7c8a4adecb1c97e976f7435db75cfab8 100644 (file)
 {% endmacro %}
 
 
 {% endmacro %}
 
 
-
 {% macro css_tabular_money() %}
 td.amount {
     text-align: right;
 }
 td.amount, td.currency {
 {% macro css_tabular_money() %}
 td.amount {
     text-align: right;
 }
 td.amount, td.currency {
-    {{ css_noninput_monospace() }}
-}
-{% endmacro %}
+{{ css_noninput_monospace()
+}}}{% endmacro %}
+{# endmacro #}
 
 
 
 
 
 
@@ -35,8 +34,9 @@ td.balance.amount {
 }
 td.balance.currency {
     width: 3em;
 }
 td.balance.currency {
     width: 3em;
-}
-{% endmacro %}
+}{%
+endmacro %}
+{# endmacro #}
 
 
 
 
 
 
@@ -65,8 +65,8 @@ td.block_column {
 }
 td.block_column.critical {
     {{css_bg_red()}}
 }
 td.block_column.critical {
     {{css_bg_red()}}
-}
-{% endmacro %}
+}{% endmacro %}
+{# endmacro #}
 
 
 
 
 
 
@@ -80,21 +80,20 @@ td.block_column.critical {
 
 
 {% macro ledger_block_columns(mode, block) %}
 
 
 {% macro ledger_block_columns(mode, block) %}
-<tr></tr><!-- just to keep the background-color alternation in proper order -->
-<tr id="block_{{block.id_}}">
-<td class="block_column {% if block.date_error %}critical{% endif %}" rowspan={{block.lines|length + 1}}>
-<input type="submit" name="ledger_moveup_{{block.id_}}" value="^" {% if not block.can_move(1) %}disabled{% endif %}/><br />
-<input type="submit" name="ledger_movedown_{{block.id_}}" value="v" {% if not block.can_move(0) %}disabled{% endif %}/><br />
-<input type="submit" name="ledger_copy_{{block.id_}}" value="C" />
-</td>
-<td class="block_column {% if block.booking and block.booking.sink_error %}critical{% endif %}" rowspan={{block.lines|length + 1}}>
-[<a href="#block_{{block.id_}}">#</a>]<br />
-[<a href="/balance?up_incl={{block.id_}}">b</a>]<br />
-[<a href="/edit_{{mode}}/{{block.id_}}">e</a>]
-</td>
-</tr >
-{% endmacro %}
-
+    <tr></tr><!-- just to keep the background-color alternation in proper order -->
+    <tr id="block_{{block.id_}}">
+        <td class="block_column {% if block.date_error %}critical{% endif %}" rowspan={{block.lines|length + 1}}>
+            <input type="submit" name="ledger_moveup_{{block.id_}}" value="^" {% if not block.can_move(1) %}disabled{% endif %}/><br />
+            <input type="submit" name="ledger_movedown_{{block.id_}}" value="v" {% if not block.can_move(0) %}disabled{% endif %}/><br />
+            <input type="submit" name="ledger_copy_{{block.id_}}" value="C" />
+        </td>
+        <td class="block_column {% if block.booking and block.booking.sink_error %}critical{% endif %}" rowspan={{block.lines|length + 1}}>
+            [<a href="#block_{{block.id_}}">#</a>]<br />
+            [<a href="/balance?up_incl={{block.id_}}">b</a>]<br />
+            [<a href="/edit_{{mode}}/{{block.id_}}">e</a>]
+        </td>
+    </tr >{% endmacro %}
+{# endmacro #}
 
 
 {# =====================[ for edit pages ]======================= #}
 
 
 {# =====================[ for edit pages ]======================= #}
index efb742e37c6f3ed149be3c9b0f11cc7910b199a3..fd1c120e4161fa9b6c2ba7e5ddddebb7577936f2 100644 (file)
@@ -5,41 +5,35 @@
 {% block css %}
 {{macros.css_ledger()}}
 {{macros.css_tabular_money()}}
 {% block css %}
 {{macros.css_ledger()}}
 {{macros.css_tabular_money()}}
-td.amount {
-    text-align: right;
-}
-td.amount, td.currency {
-    vertical-align: bottom;
-}
 {% endblock %}
 
 
 
 {% block content %}
 <form action="/ledger_structured" method="POST">
 {% endblock %}
 
 
 
 {% block content %}
 <form action="/ledger_structured" method="POST">
-{{macros.ledger_empty_lines_fix(has_redundant_empty_lines)}}
-<table class="alternating">
+{{ macros.ledger_empty_lines_fix(has_redundant_empty_lines)
+}}<table class="alternating">
 {% for block in blocks %}
 {% for block in blocks %}
-    {{macros.ledger_block_columns('structured', block)}}
-    {% if block.booking %}
-        <tr>
+{##}{{ macros.ledger_block_columns('structured', block) }}
+{##}{% if block.booking %}
+    <tr>
         <td colspan=3 {% if block.booking.intro_line.errors %}class="critical"{% endif %}>{{block.booking.date}} {{block.booking.target}}</td>
         <td>{{block.booking.intro_line.comment}}</td>
         <td colspan=3 {% if block.booking.intro_line.errors %}class="critical"{% endif %}>{{block.booking.date}} {{block.booking.target}}</td>
         <td>{{block.booking.intro_line.comment}}</td>
-        </tr>
-        {% for line in block.booking.transfer_lines %}
-            <tr>
-            <td class="amount {% if line.errors %}critical{% endif %}">{{line.amount_short}}</td>
-            <td class="currency {% if line.errors %}critical{% endif %}">{{ macros.currency_short(line.currency) }}</td>
-            <td {% if line.errors %}class="critical"{% endif %}>{{line.account}}</td>
-            <td>{{line.comment}}</td>
-            </tr>
-        {% endfor %}
-    {% endif %}
-    {% for line in block.gap.lines %}
-        <tr>
+    </tr>
+{######}{% for line in block.booking.transfer_lines %}
+    <tr>
+        <td class="amount {% if line.errors %}critical{% endif %}">{{line.amount_short}}</td>
+        <td class="currency {% if line.errors %}critical{% endif %}">{{ macros.currency_short(line.currency) }}</td>
+        <td {% if line.errors %}class="critical"{% endif %}>{{line.account}}</td>
+        <td>{{line.comment}}</td>
+    </tr>
+{######}{% endfor %}
+{##}{% endif %}
+{##}{% for line in block.gap.lines %}
+    <tr>
         <td colspan=4>{{ line.raw }}&nbsp;</td>
         <td colspan=4>{{ line.raw }}&nbsp;</td>
-        </tr>
-    {% endfor %}
+    </tr>
+{##}{% endfor %}
 {% endfor %}
 </table>
 <input type="submit" name="add_booking" value="add booking" />
 {% endfor %}
 </table>
 <input type="submit" name="add_booking" value="add booking" />
diff --git a/src/tests/empty.dat b/src/tests/empty.dat
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/tests/empty.html b/src/tests/empty.html
new file mode 100644 (file)
index 0000000..15c4cde
--- /dev/null
@@ -0,0 +1,86 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<script>
+</script>
+<style>
+html {
+    scroll-padding-top: 2em;
+}
+body {
+    background: #ffffff;
+    font-family: sans-serif;
+    text-align: left;
+    margin: 0;
+    padding: 0;
+}
+#header {
+    background: #ffffff;
+    position: sticky;
+    top: 0;
+    padding-left: 0.5em;
+    padding-bottom: 0.25em;
+    border-bottom: 1px solid black;
+}
+table.alternating > tbody > tr:nth-child(odd) {
+    background-color: #dcdcdc;
+}
+table.alternating > tbody > tr:nth-child(even) {
+    background: #ffffff;;
+}
+td {
+    vertical-align: top;
+}
+div.critical, td.critical, tr.critical, span.critical, input[type="submit"].critical {
+    background: #ff6666;
+}
+td.block_column {
+    background: #ffffff;
+}
+td.block_column.critical {
+    background: #ff6666;
+}
+td.amount {
+    text-align: right;
+}
+td.amount, td.currency {
+    font-family: monospace;
+    font-size: 1.25em;
+}
+</style>
+</head>
+<body>
+<div id="header">
+    <form action="" method="POST">
+        <span class="disable_on_change">
+            ledger <a href="/ledger_structured">structured</a>
+            / <a href="/ledger_raw">raw</a>
+            · <a href="/balance">balance</a>
+            · <input type="submit"name="file_load" value="reload" />
+        </span>
+    </form>
+</div>
+<form action="/ledger_structured" method="POST">
+<table class="alternating">
+    <tr></tr><!-- just to keep the background-color alternation in proper order -->
+    <tr id="block_0">
+        <td class="block_column " rowspan=2>
+            <input type="submit" name="ledger_moveup_0" value="^" disabled/><br />
+            <input type="submit" name="ledger_movedown_0" value="v" disabled/><br />
+            <input type="submit" name="ledger_copy_0" value="C" />
+        </td>
+        <td class="block_column " rowspan=2>
+            [<a href="#block_0">#</a>]<br />
+            [<a href="/balance?up_incl=0">b</a>]<br />
+            [<a href="/edit_structured/0">e</a>]
+        </td>
+    </tr >
+    <tr>
+        <td colspan=4>&nbsp;</td>
+    </tr>
+</table>
+<input type="submit" name="add_booking" value="add booking" />
+</form>
+</body>
+</html>
diff --git a/src/tests/full.dat b/src/tests/full.dat
new file mode 100644 (file)
index 0000000..3cf3339
--- /dev/null
@@ -0,0 +1,7 @@
+2001-01-01 test
+    foo  10 €
+    bar   -10 €
+
+2001-01-02 test
+    bar  20 €
+    baz  -20 €
diff --git a/src/tests/full.html b/src/tests/full.html
new file mode 100644 (file)
index 0000000..41c0ed6
--- /dev/null
@@ -0,0 +1,147 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<script>
+</script>
+<style>
+html {
+    scroll-padding-top: 2em;
+}
+body {
+    background: #ffffff;
+    font-family: sans-serif;
+    text-align: left;
+    margin: 0;
+    padding: 0;
+}
+#header {
+    background: #ffffff;
+    position: sticky;
+    top: 0;
+    padding-left: 0.5em;
+    padding-bottom: 0.25em;
+    border-bottom: 1px solid black;
+}
+table.alternating > tbody > tr:nth-child(odd) {
+    background-color: #dcdcdc;
+}
+table.alternating > tbody > tr:nth-child(even) {
+    background: #ffffff;;
+}
+td {
+    vertical-align: top;
+}
+div.critical, td.critical, tr.critical, span.critical, input[type="submit"].critical {
+    background: #ff6666;
+}
+td.block_column {
+    background: #ffffff;
+}
+td.block_column.critical {
+    background: #ff6666;
+}
+td.amount {
+    text-align: right;
+}
+td.amount, td.currency {
+    font-family: monospace;
+    font-size: 1.25em;
+}
+</style>
+</head>
+<body>
+<div id="header">
+    <form action="" method="POST">
+        <span class="disable_on_change">
+            ledger <a href="/ledger_structured">structured</a>
+            / <a href="/ledger_raw">raw</a>
+            · <a href="/balance">balance</a>
+            · <input type="submit"name="file_load" value="reload" />
+        </span>
+    </form>
+</div>
+<form action="/ledger_structured" method="POST">
+<table class="alternating">
+    <tr></tr><!-- just to keep the background-color alternation in proper order -->
+    <tr id="block_0">
+        <td class="block_column " rowspan=1>
+            <input type="submit" name="ledger_moveup_0" value="^" disabled/><br />
+            <input type="submit" name="ledger_movedown_0" value="v" disabled/><br />
+            <input type="submit" name="ledger_copy_0" value="C" />
+        </td>
+        <td class="block_column " rowspan=1>
+            [<a href="#block_0">#</a>]<br />
+            [<a href="/balance?up_incl=0">b</a>]<br />
+            [<a href="/edit_structured/0">e</a>]
+        </td>
+    </tr >
+    <tr></tr><!-- just to keep the background-color alternation in proper order -->
+    <tr id="block_1">
+        <td class="block_column " rowspan=5>
+            <input type="submit" name="ledger_moveup_1" value="^" disabled/><br />
+            <input type="submit" name="ledger_movedown_1" value="v" disabled/><br />
+            <input type="submit" name="ledger_copy_1" value="C" />
+        </td>
+        <td class="block_column " rowspan=5>
+            [<a href="#block_1">#</a>]<br />
+            [<a href="/balance?up_incl=1">b</a>]<br />
+            [<a href="/edit_structured/1">e</a>]
+        </td>
+    </tr >
+    <tr>
+        <td colspan=3 >2001-01-01 test</td>
+        <td></td>
+    </tr>
+    <tr>
+        <td class="amount ">10.00</td>
+        <td class="currency ">€</td>
+        <td >foo</td>
+        <td></td>
+    </tr>
+    <tr>
+        <td class="amount ">-10.00</td>
+        <td class="currency ">€</td>
+        <td >bar</td>
+        <td></td>
+    </tr>
+    <tr>
+        <td colspan=4>&nbsp;</td>
+    </tr>
+    <tr></tr><!-- just to keep the background-color alternation in proper order -->
+    <tr id="block_2">
+        <td class="block_column " rowspan=5>
+            <input type="submit" name="ledger_moveup_2" value="^" disabled/><br />
+            <input type="submit" name="ledger_movedown_2" value="v" disabled/><br />
+            <input type="submit" name="ledger_copy_2" value="C" />
+        </td>
+        <td class="block_column " rowspan=5>
+            [<a href="#block_2">#</a>]<br />
+            [<a href="/balance?up_incl=2">b</a>]<br />
+            [<a href="/edit_structured/2">e</a>]
+        </td>
+    </tr >
+    <tr>
+        <td colspan=3 >2001-01-02 test</td>
+        <td></td>
+    </tr>
+    <tr>
+        <td class="amount ">20.00</td>
+        <td class="currency ">€</td>
+        <td >bar</td>
+        <td></td>
+    </tr>
+    <tr>
+        <td class="amount ">-20.00</td>
+        <td class="currency ">€</td>
+        <td >baz</td>
+        <td></td>
+    </tr>
+    <tr>
+        <td colspan=4>&nbsp;</td>
+    </tr>
+</table>
+<input type="submit" name="add_booking" value="add booking" />
+</form>
+</body>
+</html>
diff --git a/src/tests/test.dat b/src/tests/test.dat
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/src/tests/test.html b/src/tests/test.html
deleted file mode 100644 (file)
index fd0e2f5..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-
-<!DOCTYPE html>
-<html>
-<head>
-<meta charset="UTF-8">
-<script>
-
-</script>
-<style>
-html {
-    scroll-padding-top: 2em;
-}
-body {
-    background: #ffffff;
-    font-family: sans-serif;
-    text-align: left;
-    margin: 0;
-    padding: 0;
-}
-#header {
-    background: #ffffff;
-    position: sticky;
-    top: 0;
-    padding-left: 0.5em;
-    padding-bottom: 0.25em;
-    border-bottom: 1px solid black;
-}
-table.alternating > tbody > tr:nth-child(odd) {
-    background-color: #dcdcdc;
-}
-table.alternating > tbody > tr:nth-child(even) {
-    background: #ffffff;;
-}
-td {
-    vertical-align: top;
-}
-div.critical, td.critical, tr.critical, span.critical, input[type="submit"].critical {
-    background: #ff6666;
-}
-
-
-td.block_column {
-    background: #ffffff;
-}
-td.block_column.critical {
-    background: #ff6666;
-}
-
-
-td.amount {
-    text-align: right;
-}
-td.amount, td.currency {
-    
-    font-family: monospace;
-    font-size: 1.25em;
-
-}
-
-td.amount {
-    text-align: right;
-}
-td.amount, td.currency {
-    vertical-align: bottom;
-}
-
-</style>
-</head>
-<body>
-
-<div id="header">
-<form action="" method="POST">
-<span class="disable_on_change">
-ledger <a href="/ledger_structured">structured</a>
-/ <a href="/ledger_raw">raw</a>
-· <a href="/balance">balance</a>
-
-<input type="submit"name="file_load" value="reload" />
-
-</span>
-</form>
-</div>
-
-
-<form action="/ledger_structured" method="POST">
-
-
-
-<table class="alternating">
-
-    
-<tr></tr><!-- just to keep the background-color alternation in proper order -->
-<tr id="block_0">
-<td class="block_column " rowspan=2>
-<input type="submit" name="ledger_moveup_0" value="^" disabled/><br />
-<input type="submit" name="ledger_movedown_0" value="v" disabled/><br />
-<input type="submit" name="ledger_copy_0" value="C" />
-</td>
-<td class="block_column " rowspan=2>
-[<a href="#block_0">#</a>]<br />
-[<a href="/balance?up_incl=0">b</a>]<br />
-[<a href="/edit_structured/0">e</a>]
-</td>
-</tr >
-
-    
-    
-        <tr>
-        <td colspan=4>&nbsp;</td>
-        </tr>
-    
-
-</table>
-<input type="submit" name="add_booking" value="add booking" />
-</form>
-
-</body>
-</html>