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'):
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]:
{% elif dat_line.booking_line.idx == 1 %}
<td><a href="/balance?up_incl={{dat_line.booking_id}}">[b]</a><input type="submit" name="move_{{dat_line.booking_id}}_down" value="v"{% if dat_line.booking_id == max_id %} disabled{% endif %}/></td>
{% elif dat_line.booking_line.idx == 2 %}
- <td><input type="submit" name="copy_{{dat_line.booking_id}}" value="c" /></td>
+ <td><input type="submit" name="copy_{{dat_line.booking_id}}_here" value="c" /><input type="submit" name="copy_{{dat_line.booking_id}}_to_end" value="C" /></td>
{% else %}
<td></td>
{% endif %}