home · contact · privacy
Add dat file reload button.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 22 Jan 2025 19:19:09 +0000 (20:19 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 22 Jan 2025 19:19:09 +0000 (20:19 +0100)
ledger.py
templates/_base.tmpl
templates/index.tmpl

index 89d5ca2e8eb8a6143b3ae93b38af7e562554b2b6..22e051aecc06ea17d5e636aa053f22eb0595a126 100755 (executable)
--- a/ledger.py
+++ b/ledger.py
@@ -221,6 +221,8 @@ class Handler(PlomHttpHandler):
 
     def do_POST(self) -> None:
         # pylint: disable=invalid-name,missing-function-docstring
+        if self.pagename == 'reload':
+            self.server.load()
         self.redirect(Path(''))
 
     def do_GET(self) -> None:
@@ -247,9 +249,14 @@ class Server(PlomHttpServer):
 
     def __init__(self, path_dat: Path, *args, **kwargs) -> None:
         super().__init__(PATH_TEMPLATES, (SERVER_HOST, SERVER_PORT), Handler)
+        self._path_dat = path_dat
+        self.load()
+
+    def load(self) -> None:
+        """Read into ledger file at .path_dat."""
         self.dat_lines = [
-                DatLine(line)
-                for line in path_dat.read_text(encoding='utf8').splitlines()]
+            DatLine(line)
+            for line in self._path_dat.read_text(encoding='utf8').splitlines()]
         self.bookings: list[Booking] = []
         booking_lines: list[DatLine] = []
         last_date = ''
index 268fb643542b2226bcf0e8a4f7cae5170c56ff9f..5d80c44da221bf90bde3b85d5c28af1161480f14 100644 (file)
@@ -12,7 +12,9 @@ table.warning tbody tr td, tr.warning td { background-color: #ff8888; }
 </style>
 </head>
 <body>
-<a href="/">home</a> · <a href="/raw">raw</a> · <a href="/balance">balance</a>
+<form action="/reload" method="POST">
+<a href="/">home</a> · <a href="/raw">raw</a> · <a href="/balance">balance</a> · <input type="submit" value="reload" />
+</form>
 <hr />
 {% block content %}{% endblock %}
 </body>
index 43be0f46ad0221cec1b19d95ed4db21f7139f7cf..886a01c06dbc20d29948d31718db448ad0e79a1f 100644 (file)
@@ -7,8 +7,5 @@
 {% endblock %}
 
 {% block content %}
-<form action="/" method="POST"><input type="submit" value="A" /></form>
-<form action="/" method="GET"><input type="submit" value="B" /></form>
-<hr/>
 {{ macros.table_dat_lines(dat_lines, single=false, raw=false) }}
 {% endblock %}