home · contact · privacy
Base .tainted calculation on current .dat_lines hash.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 26 Jan 2025 09:11:54 +0000 (10:11 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 26 Jan 2025 09:11:54 +0000 (10:11 +0100)
ledger.py

index 80b60990ba02cb7242182d0bd39c4eaaee91797e..016e087fc267085c3ea60622169c66036eff1034 100755 (executable)
--- a/ledger.py
+++ b/ledger.py
@@ -237,7 +237,6 @@ class Handler(PlomHttpHandler):
                                      + new_dat_lines
                                      + self.server.dat_lines[end_idx+1:])
             self.server.load_bookings()
-            self.server.tainted = True
             self.redirect(Path('/').joinpath('booking').joinpath(str(id_)))
             return
         self.redirect(Path('/'))
@@ -280,8 +279,16 @@ class Server(PlomHttpServer):
         self.dat_lines = [
             DatLine(line)
             for line in self._path_dat.read_text(encoding='utf8').splitlines()]
+        self.last_save_hash = self._hash_dat_lines()
         self.load_bookings()
-        self.tainted = False
+
+    def _hash_dat_lines(self) -> int:
+        return hash(tuple(dl.raw for dl in self.dat_lines))
+
+    @property
+    def tainted(self) -> bool:
+        """If .dat_lines different to those of last .load()."""
+        return self._hash_dat_lines() != self.last_save_hash
 
     def load_bookings(self) -> None:
         """Read .dat_lines into Bookings / full ledger."""