From: Christian Heller Date: Wed, 22 Jan 2025 19:19:09 +0000 (+0100) Subject: Add dat file reload button. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bprefix%7D%7D/tasks?a=commitdiff_plain;h=fa952847d51990675eefa2994f66b33162ac3c41;p=plomledger Add dat file reload button. --- diff --git a/ledger.py b/ledger.py index 89d5ca2..22e051a 100755 --- 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 = '' diff --git a/templates/_base.tmpl b/templates/_base.tmpl index 268fb64..5d80c44 100644 --- a/templates/_base.tmpl +++ b/templates/_base.tmpl @@ -12,7 +12,9 @@ table.warning tbody tr td, tr.warning td { background-color: #ff8888; } -home · raw · balance +
+home · raw · balance · +

{% block content %}{% endblock %} diff --git a/templates/index.tmpl b/templates/index.tmpl index 43be0f4..886a01c 100644 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -7,8 +7,5 @@ {% endblock %} {% block content %} -
-
-
{{ macros.table_dat_lines(dat_lines, single=false, raw=false) }} {% endblock %}