class IdUuid(UuidMixin, BaseMixin, db.Model): __tablename__ = 'id_uuid' __uuid_primary_key__ = False is_regular = db.Column(db.Unicode(250)) is_immutable = immutable(db.Column(db.Unicode(250))) is_cached = cached(db.Column(db.Unicode(250))) # Only block changes via the relationship; raw column remains mutable referral_target_id = db.Column(None, db.ForeignKey('referral_target.id'), nullable=True) referral_target = immutable(db.relationship(ReferralTarget))
class RelationshipParent(BaseNameMixin, db.Model): __tablename__ = 'relationship_parent' children_list = db.relationship(RelationshipChild, backref='parent') children_list_lazy = db.relationship(RelationshipChild, lazy='dynamic') children_set = db.relationship(RelationshipChild, collection_class=set) children_dict_attr = db.relationship( RelationshipChild, collection_class=attribute_mapped_collection('name') ) children_dict_column = db.relationship( RelationshipChild, collection_class=column_mapped_collection(RelationshipChild.name), ) __roles__ = { 'all': { 'read': { 'name', 'title', 'children_list', 'children_set', 'children_dict_attr', 'children_dict_column', } } } __datasets__ = { 'primary': { 'name', 'title', 'children_list', 'children_set', 'children_dict_attr', 'children_dict_column', }, 'related': {'name', 'title'}, }
class IncomingMessage(BaseMixin, db.Model): __tablename__ = 'incoming_message' __uuid_primary_key__ = True from_address = db.Column(db.Unicode(254), nullable=False) to_address = db.Column(db.Unicode(254), nullable=False) subject = db.Column(db.Unicode(255), nullable=False) headers = db.Column(db.UnicodeText(), nullable=False) messageid = db.Column(db.Unicode(255), nullable=False) body = db.Column(db.UnicodeText(), nullable=True) campaign_id = db.Column(None, db.ForeignKey('campaign.id'), nullable=False) campaign = db.relationship(Campaign, backref=db.backref( 'incoming_messages', cascade='all, delete-orphan'))
class MultiroleChild(BaseMixin, db.Model): """Model that inherits roles from its parent""" __tablename__ = 'multirole_child' parent_id = db.Column(None, db.ForeignKey('multirole_document.id')) parent = with_roles( db.relationship(MultiroleDocument), grants_via={ 'parent.user': {'super_parent_role'}, # Maps to parent.parent.user 'rel_lazy.user': { # Maps to parent.rel_lazy[item].user # Map role2 and role3, but explicitly ignore role1 'role2': 'parent_role2', 'role3': 'parent_role3', }, }, )
class OutgoingMessage(BaseMixin, db.Model): __tablename__ = 'outgoing_message' __uuid_primary_key__ = True to_addresses = db.Column(postgresql.ARRAY(db.Unicode(), dimensions=1), nullable=False) cc_list = db.Column(postgresql.ARRAY(db.Unicode(), dimensions=1), nullable=True) bcc_list = db.Column(postgresql.ARRAY(db.Unicode(), dimensions=1), nullable=True) subject = db.Column(db.Unicode(255), nullable=False) headers = db.Column(db.UnicodeText(), nullable=True) messageid = db.Column(db.Unicode(255), nullable=False) campaign_id = db.Column(None, db.ForeignKey('campaign.id'), nullable=False) campaign = db.relationship(Campaign, backref=db.backref( 'outgoing_messages', cascade='all, delete-orphan'))
class AutoResponder(BaseMixin, db.Model): __tablename__ = 'auto_responder' campaign_id = db.Column(None, db.ForeignKey('campaign.id'), nullable=False) campaign = db.relationship(Campaign, backref=db.backref( 'responders', cascade='all, delete-orphan')) subject = db.Column(db.Unicode(255), nullable=False) frequency = db.Column(db.Integer, default=RESPONDER_FREQUENCY.FIRST_TIME, nullable=False) def get_template(self, txt): lang_code, score = langid.classify(txt) template = ResponseTemplate.query.filter( ResponseTemplate.lang_code == lang_code).first() if not template: template = ResponseTemplate.query.filter( ResponseTemplate.lang_code == 'en').first() return template
class MultiroleParent(BaseMixin, db.Model): """Test model to serve as a role granter to the child model""" __tablename__ = 'multirole_parent' user_id = db.Column(None, db.ForeignKey('role_user.id')) user = with_roles(db.relationship(RoleUser), grants={'prole1', 'prole2'})