Example #1
0
class Dataset(db.Model):

    __tablename__ = 'datasets'

    id = db.Column(db.Integer, primary_key=True)
    type = db.Column(db.String(50))

    name = db.Column(db.String)
    description = db.Column(db.String)
    path = db.Column(db.String)
    created = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    closed = db.Column(db.Boolean, default=False)
    collection_id = db.Column(db.Integer, db.ForeignKey('collections.id'))
    has_thumbnail = db.Column(db.Boolean, default=False)

    collection = db.relationship('Collection', back_populates='datasets')
    accesses = db.relationship('Access', cascade='all, delete, delete-orphan')
    permissions = db.relationship('Permission', uselist=False)

    __mapper_args__ = {
        'polymorphic_identity': 'dataset',
        'polymorphic_on': type
    }

    def to_dict(self):
        path = os.path.join(app.config['NOVA_ROOT_PATH'], self.path)
        return dict(name=self.name,
                    path=path,
                    closed=self.closed,
                    description=self.description)

    def __repr__(self):
        return '<Dataset(name={}, path={}>'.format(self.name, self.path)
Example #2
0
class Process(db.Model):

    __tablename__ = 'processes'

    id = db.Column(db.Integer, primary_key=True)
    type = db.Column(db.String(50))

    task_uuid = db.Column(db.String)

    source_id = db.Column(db.Integer, db.ForeignKey('datasets.id'))
    destination_id = db.Column(db.Integer, db.ForeignKey('datasets.id'))
    collection_id = db.Column(db.Integer, db.ForeignKey('collections.id'))

    source = db.relationship('Dataset', foreign_keys=[source_id])
    destination = db.relationship('Dataset', foreign_keys=[destination_id])
    collection = db.relationship('Collection')

    __mapper_args__ = {
        'polymorphic_identity': 'process',
        'polymorphic_on': type
    }

    def __repr__(self):
        return '<Process(src={}, dst={})>'.\
            format(self.source.name, self.destination.name)
Example #3
0
class Membership(db.Model):
    __tablename__ = 'memberships'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    group_id = db.Column(db.Integer, db.ForeignKey('groups.id'))
    is_creator = db.Column(db.Boolean, default=False)
    is_admin = db.Column(db.Boolean, default=False)

    user = db.relationship('User')
    group = db.relationship('Group')
Example #4
0
class Access(db.Model):

    __tablename__ = 'accesses'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    dataset_id = db.Column(db.Integer, db.ForeignKey('datasets.id'))

    owner = db.Column(db.Boolean)
    writable = db.Column(db.Boolean)
    seen = db.Column(db.Boolean, default=False)

    user = db.relationship('User')
    dataset = db.relationship('Dataset', back_populates='accesses')

    def __repr__(self):
        return '<Access(user={}, dataset={}, owner={}, writable={}>'.\
            format(self.user.name, self.dataset.name, self.owner, self.writable)
Example #5
0
class Permission(db.Model):

    __tablename__ = 'permissions'

    id = db.Column(db.Integer, primary_key=True)
    owner_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    dataset_id = db.Column(db.Integer, db.ForeignKey('datasets.id'))

    can_read = db.Column(db.Boolean, default=True)
    can_interact = db.Column(db.Boolean, default=True)
    can_fork = db.Column(db.Boolean, default=False)

    owner = db.relationship('User')
    dataset = db.relationship('Dataset', back_populates='permissions')

    def __repr__(self):
        return '<Permission(dataset={}, owner = {}, read={}, interact={}, fork={}>'.\
            format(self.dataset, self.owner, self.can_read, self.can_interact, self.can_fork)
Example #6
0
class SampleScan(Dataset):

    __tablename__ = 'samplescans'

    __mapper_args__ = {'polymorphic_identity': 'samplescan'}

    id = db.Column(db.Integer, db.ForeignKey('datasets.id'), primary_key=True)

    taxon_id = db.Column(db.Integer, db.ForeignKey('taxons.id'), nullable=True)
    genus_id = db.Column(db.Integer,
                         db.ForeignKey('genuses.id'),
                         nullable=True)
    family_id = db.Column(db.Integer,
                          db.ForeignKey('families.id'),
                          nullable=True)
    order_id = db.Column(db.Integer, db.ForeignKey('orders.id'), nullable=True)

    taxon = db.relationship('Taxon')
    genus = db.relationship('Genus')
    family = db.relationship('Family')
    order = db.relationship('Order')
Example #7
0
class Notification(db.Model):

    __tablename__ = 'notifications'

    id = db.Column(db.Integer, primary_key=True)
    message = db.Column(db.String)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    user = db.relationship('User')
    type = db.Column(db.String)

    def __init__(self, user, type='message', message=None):
        self.user = user
        self.type = type
        self.message = message

    def __repr__(self):
        return '<Notification(user={}, message={})>'.\
            format(self.user.name, self.message)

    def to_dict(self):
        return {'message': self.message, 'id': self.id, 'type': self.type}