home · contact · privacy
On reload and save button use, always redirect to where we're coming from. master
authorChristian Heller <c.heller@plomlompom.de>
Mon, 27 Jan 2025 07:16:51 +0000 (08:16 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 27 Jan 2025 07:16:51 +0000 (08:16 +0100)
ledger.py
templates/_base.tmpl

index 7a62924328642d863f58c0f4e2f1cc46257b4a57..26272373982c92523d331f697fe3732261e34426 100755 (executable)
--- a/ledger.py
+++ b/ledger.py
@@ -251,15 +251,12 @@ class Handler(PlomHttpHandler):
 
     def do_POST(self) -> None:
         # pylint: disable=invalid-name,missing-function-docstring
-        redir_path = Path('/')
         if self.pagename.startswith('edit_'):
             id_ = int(self.path_toks[2])
-            redir_path = redir_path.joinpath(self.pagename).joinpath(str(id_))
-        if self.pagename == 'file':
-            if 'reload' in self.postvars.as_dict:
-                self.server.load()
-            elif 'save' in self.postvars.as_dict:
-                self.server.save()
+        if 'reload_file' in self.postvars.as_dict:
+            self.server.load()
+        elif 'save_file' in self.postvars.as_dict:
+            self.server.save()
         elif self.pagename == 'edit_structured':
             if self.postvars.first('apply'):
                 line_keys = self.postvars.keys_prefixed('line_')
@@ -289,6 +286,7 @@ class Handler(PlomHttpHandler):
                             data += f'  {input_}'
                     new_dat_lines += [
                         DatLine(f'{data} ; {comment}' if comment else data)]
+                # pylint: disable=possibly-used-before-assignment
                 self.server.rewrite_booking(id_, new_dat_lines)
         elif self.pagename == 'edit_raw':
             if self.postvars.first('apply'):
@@ -296,11 +294,11 @@ class Handler(PlomHttpHandler):
                         DatLine(line) for line
                         in self.postvars.first('booking').splitlines()]
                 self.server.rewrite_booking(id_, new_dat_lines)
-        self.redirect(redir_path)
+        self.redirect(Path(self.path))
 
     def do_GET(self) -> None:
         # pylint: disable=invalid-name,missing-function-docstring
-        ctx = {'tainted': self.server.tainted}
+        ctx = {'tainted': self.server.tainted, 'path': self.path}
         if self.pagename == 'booking' or self.pagename.startswith('edit_'):
             ctx['id'] = int(self.path_toks[2])
         if self.pagename == 'balance':
index 0ec782d16390344c36ecfa6b63e665e1c9db2a59..af5070c8d8b468177d21d269203c3772bd679a8f 100644 (file)
@@ -16,8 +16,8 @@ span.warning, table.warning tbody tr td, tr.warning td { background-color: #ff88
 </style>
 </head>
 <body>
-<form action="/file" method="POST">
-ledger <a href="/ledger_structured">structured</a> / <a href="/ledger_raw">raw</a> · <a href="/balance">balance</a> · <input type="submit" name="reload" value="reload" />{% if tainted %} · <span class="warning">unsaved changes: <input type="submit" name="save" value="save"></span>{% endif %}
+<form action="{{path}}" method="POST">
+ledger <a href="/ledger_structured">structured</a> / <a href="/ledger_raw">raw</a> · <a href="/balance">balance</a> · <input type="submit" name="reload_file" value="reload" />{% if tainted %} · <span class="warning">unsaved changes: <input type="submit" name="save_file" value="save"></span>{% endif %}
 </form>
 <hr />
 {% block content %}{% endblock %}