Ejemplo n.º 1
0
    cancellation_duration = Column(Integer, default=10)
    state = Column(Enum(StateType), default="active")
    next_sync_token = Column(String, nullable=True)
    events = relationship('Events', cascade="all, delete-orphan")
    response = relationship('Response', cascade="all, delete-orphan")
    room_tags = relationship('Tag',
                             secondary="room_tags",
                             backref=('tags'),
                             lazy="joined")
    devices = relationship('Devices',
                           cascade="all, delete-orphan",
                           order_by="func.lower(Devices.name)")

    __table_args__ = (Index('ix_unique_room_in_location_content',
                            'name',
                            'location_id',
                            unique=True,
                            postgresql_where=(state == 'active')), )


@event.listens_for(Room, 'before_insert')
def receive_before_insert(mapper, connection, target):
    @event.listens_for(db_session, "after_flush", once=True)
    def receive_after_flush(session, context):
        if not verify_calendar_id(target.calendar_id):
            raise GraphQLError("Room calendar Id is invalid")
        pass


cascade_soft_delete(Room, 'events', 'room_id')
Ejemplo n.º 2
0
class TimeZoneType(enum.Enum):
    EAST_AFRICA_TIME = "UTC+3"
    WEST_AFRICA_TIME = "UTC+1"


class Location(Base, Utility):
    __tablename__ = 'locations'
    id = Column(Integer,
                Sequence('locations_id_seq', start=1, increment=1),
                primary_key=True)
    name = Column(String, nullable=False)
    abbreviation = Column(String)
    country = Column(Enum(CountryType))
    time_zone = Column(Enum(TimeZoneType))
    image_url = Column(String)
    state = Column(Enum(StateType), default="active")
    structure = Column(String, nullable=True)
    rooms = relationship(
        'Room',
        cascade="all, delete-orphan",
        order_by="func.lower(Room.name)",
        primaryjoin="and_(Location.id==Room.location_id, Room.state=='active')"
    )
    __table_args__ = (Index('ix_unique_location_content',
                            'name',
                            unique=True,
                            postgresql_where=(state == 'active')), )


cascade_soft_delete(Location, 'room', 'location_id')