from onegov.activity import ActivityCollection
from onegov.feriennet.policy import ActivityQueryPolicy
from sqlalchemy.orm import joinedload
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from morepath.authentication import Identity, NoIdentity
from onegov.activity.collections.activity import ActivityFilter
from onegov.feriennet.models import VacationActivity
from sqlalchemy.orm import Query, Session
from typing import Self, TypeVar
[docs]
class VacationActivityCollection(ActivityCollection['VacationActivity']):
# type is ignored, but present to keep the same signature as the superclass
def __init__(
self,
session: 'Session',
type: None = None,
pages: tuple[int, int] | None = (0, 0),
filter: 'ActivityFilter | None' = None,
identity: 'Identity | NoIdentity | None' = None
) -> None:
super().__init__(
session=session,
type='vacation',
pages=pages,
filter=filter
)
[docs]
self.identity = identity
@property
[docs]
def policy(self) -> ActivityQueryPolicy:
return ActivityQueryPolicy.for_identity(self.identity)
[docs]
def query_base(self) -> 'Query[VacationActivity]':
return self.policy.granted_subset(self.session.query(self.model_class))
[docs]
def by_page_range(self, page_range: tuple[int, int] | None) -> 'Self':
return self.__class__(
session=self.session,
identity=self.identity,
pages=page_range,
filter=self.filter
)