from __future__ import annotations
from onegov.page import Page, PageCollection
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from onegov.core.orm.abstract import (
AdjacencyList, AdjacencyListCollection, MoveDirection)
from sqlalchemy.orm import Session
[docs]
class AdjacencyListMove[L: AdjacencyList]:
""" Represents a single move of an adjacency list item. """
[docs]
__collection__: type[AdjacencyListCollection[L]]
def __init__(
self,
session: Session,
subject: L,
target: L,
direction: MoveDirection
) -> None:
[docs]
self.direction = direction
@property
[docs]
def subject_id(self) -> int:
return self.subject.id
@property
[docs]
def target_id(self) -> int:
return self.target.id
[docs]
def execute(self) -> None:
self.__collection__(self.session).move(
subject=self.subject,
target=self.target,
direction=self.direction
)
[docs]
class PageMove(AdjacencyListMove[Page]):
[docs]
__collection__ = PageCollection