Source code for user.collections.group

from __future__ import annotations

from onegov.user.models import UserGroup
from onegov.core.collection import GenericCollection


from typing import overload, Literal, TYPE_CHECKING
if TYPE_CHECKING:
    from sqlalchemy.orm import Query, Session


[docs] class UserGroupCollection[T: UserGroup](GenericCollection[T]): """ Manages a list of user groups. Use it like this:: from onegov.user import UserGroupCollection groups = UserGroupCollection(session) """ @overload def __init__( self: UserGroupCollection[UserGroup], session: Session, type: Literal['*', 'generic'] = ... ): ... @overload def __init__(self, session: Session, type: str): ... def __init__(self, session: Session, type: str = '*'):
[docs] self.session = session
[docs] self.type = type
@property
[docs] def model_class(self) -> type[T]: return UserGroup.get_polymorphic_class( # type:ignore[return-value] self.type, default=UserGroup) # type:ignore[arg-type]
[docs] def query(self) -> Query[T]: query = super().query() return query.order_by(self.model_class.name)