Source code for reservation.models.custom_allocation

from libres.db.models import Allocation
from onegov.core.orm import ModelBase
from onegov.reservation.models.resource import Resource
from sqlalchemy.orm import object_session


[docs] class CustomAllocation(Allocation, ModelBase):
[docs] __mapper_args__ = {'polymorphic_identity': 'custom'}
@property
[docs] def is_virtual(self) -> bool: return self.resource.version == 5
@property
[docs] def resource_obj(self) -> Resource: session = object_session(self) assert session is not None return session.query(Resource).filter( # NOTE: We automatically detect whether we are linked via virtual # resource id and apply the correct filter Resource.virtual_id == self.resource if self.is_virtual else Resource.id == self.resource ).one()
@property
[docs] def access(self) -> str: return (self.data or {}).get('access', 'public')