Esempio n. 1
0
 def _make_field_fieldvalue(type_):
     return db.relationship(
         lambda: CollectionFieldFieldvalue,
         primaryjoin=lambda: db.and_(
             Collection.id == CollectionFieldFieldvalue.id_collection,
             CollectionFieldFieldvalue.type == type_),
         order_by=lambda: CollectionFieldFieldvalue.score)
Esempio n. 2
0
 def _collection_type(type_):
     return db.relationship(
         Collection,
         primaryjoin=lambda: db.and_(
             CollectionExternalcollection.id_collection == Collection.id,
             CollectionExternalcollection.type == type_),
         backref='_externalcollections_{0}'.format(str(type_))
     )
Esempio n. 3
0
    __tablename__ = 'user_accROLE'
    id_user = db.Column(db.Integer(15, unsigned=True), db.ForeignKey(User.id),
                        nullable=False, primary_key=True)
    id_accROLE = db.Column(db.Integer(15, unsigned=True),
                           db.ForeignKey(AccROLE.id), nullable=False,
                           primary_key=True)
    expiration = db.Column(db.DateTime, nullable=False,
                           server_default='9999-12-31 23:59:59')

    user = db.relationship(User, backref='roles')
    role = db.relationship(AccROLE, backref='users')

User.active_roles = db.relationship(
    UserAccROLE,
    lazy="dynamic",
    primaryjoin=db.and_(
        User.id == UserAccROLE.id_user,
        UserAccROLE.expiration >= db.func.now()
    )
)

User.has_admin_role = property(
    lambda self:
    self.has_super_admin_role or db.object_session(self).query(
        db.func.count(User.id) > 0
    ).join(
        User.active_roles,
        UserAccROLE.role,
        AccROLE.authorizations
    ).filter(
        AccAuthorization.id_accACTION.in_(
            db.select([AccACTION.id]).where(
Esempio n. 4
0
 def bibxxx(cls):
     return db.relationship(cls._bibxxx, backref='bibrecs')
Esempio n. 5
0
 def bibrec(cls):
     return db.relationship(Record)
Esempio n. 6
0
                                 onupdate=datetime.now)
    user = db.relationship(
        User,
        backref=db.backref('usergroups'))
    usergroup = db.relationship(
        Usergroup,
        backref=db.backref('users', cascade="all, delete-orphan"))

    def is_admin(self):
        """Return True if user is a admin."""
        return self.user_status == self.USER_STATUS['ADMIN']

# define query to get admins
Usergroup.admins = db.relationship(
    UserUsergroup,
    lazy="dynamic",
    primaryjoin=db.and_(
        Usergroup.id == UserUsergroup.id_usergroup,
        UserUsergroup.user_status == UserUsergroup.USER_STATUS['ADMIN']))


class UserEXT(db.Model):

    """Represent a UserEXT record."""

    __tablename__ = 'userEXT'

    id = db.Column(db.VARBINARY(255), primary_key=True, nullable=False)
    method = db.Column(db.String(50), primary_key=True, nullable=False)
    id_user = db.Column(db.Integer(15, unsigned=True),
                        db.ForeignKey(User.id), nullable=False)