From: Christian Heller Date: Sun, 26 Jan 2025 09:11:54 +0000 (+0100) Subject: Base .tainted calculation on current .dat_lines hash. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bdb.prefix%7D%7D/%7B%7Bprefix%7D%7D/day?a=commitdiff_plain;h=9e56fda97d051c739b1d129beb310166365ccb00;p=plomledger Base .tainted calculation on current .dat_lines hash. --- diff --git a/ledger.py b/ledger.py index 80b6099..016e087 100755 --- 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."""