From: Christian Heller Date: Wed, 29 Jan 2025 03:16:02 +0000 (+0100) Subject: Differentiate copying between "to end of ledger" and "to after copied". X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/conditions?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=plomledger Differentiate copying between "to end of ledger" and "to after copied". --- diff --git a/ledger.py b/ledger.py index f61cbec..60106c7 100755 --- a/ledger.py +++ b/ledger.py @@ -261,9 +261,11 @@ class Handler(PlomHttpHandler): self.redirect(Path(self.pagename).joinpath(f'#{id_}')) return for key in self.postvars.keys_prefixed('copy_'): - id_ = int(key.split('_')[1]) - self.server.copy_booking(id_) - self.redirect(Path('/bookings').joinpath(f'{id_}')) + toks = key.split('_', maxsplit=2) + id_ = int(toks[1]) + new_id = self.server.copy_booking(int(toks[1]), + to_end=toks[2] == 'to_end') + self.redirect(Path('/bookings').joinpath(f'{new_id}')) return elif self.pagename == 'edit_structured': if self.postvars.first('apply'): @@ -422,11 +424,20 @@ class Server(PlomHttpServer): self._replace_from_to(*self._margin_indices(self.bookings[id_]), new_dat_lines) - def copy_booking(self, id_: int) -> None: - """Append copy of Booking of id_ to end of ledger.""" - self.dat_lines += [DatLine('')] + [DatLine(dat_line.raw) for dat_line - in self.bookings[id_].dat_lines] + def copy_booking(self, id_: int, to_end: bool) -> int: + """Add copy of Booking of id_ to_end of ledger, or after copied.""" + copied = self.bookings[id_] + new_lines = [DatLine('')] + [DatLine(dat_line.raw) for dat_line + in copied.dat_lines] + if to_end or copied is self.bookings[-1]: + self.dat_lines += new_lines + new_id = self.bookings[-1].id_ + 1 + else: + start = self.dat_lines.index(copied.dat_lines[-1]) + self._replace_from_to(start + 1, start, new_lines) + new_id = copied.id_ + 1 self._load_bookings() + return new_id @property def dat_lines_sans_empty(self) -> list[DatLine]: diff --git a/templates/_macros.tmpl b/templates/_macros.tmpl index dc7b13d..f8f9325 100644 --- a/templates/_macros.tmpl +++ b/templates/_macros.tmpl @@ -24,7 +24,7 @@ table.ledger tr > td:first-child { background-color: white; } {% elif dat_line.booking_line.idx == 1 %} [b] {% elif dat_line.booking_line.idx == 2 %} - + {% else %} {% endif %}