class Biobox(db.Model): """ represents a standard biobox. """ KEY_IMAGE = 'image' KEY_ID = 'pmid' KEY_HOME_PAGE = 'homepage' KEY_MAILING_LIST = 'mailing_list' KEY_DESCRIPTION = 'description' KEY_TASKS = 'tasks' KEY_TITLE = 'title' pmid = db.Column(db.Integer, primary_key=True) title = db.Column(db.String, unique=True, nullable=False) homepage = db.Column(db.String) mailing_list = db.Column(db.String) description = db.Column(db.String, nullable=False) tasks = db.relationship('Task', cascade='all', secondary=biobox_tasks) image = db.relationship('Image', cascade='all', uselist=False, back_populates='biobox') source_id = db.Column(db.Integer, db.ForeignKey('source.id'), nullable=False)
class Interface(db.Model): """ represents an interface a biobox or task can implement. """ id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, unique=True, nullable=False) tasks = db.relationship('Task', backref='interface', lazy='dynamic')
class Source(db.Model): """ represents a source from where bioboxes are loaded. """ id = db.Column(db.Integer, primary_key=True) url = db.Column(db.String, unique=True, nullable=False) name = db.Column(db.String, unique=True, nullable=False) bioboxes = db.relationship('Biobox', cascade='all, delete-orphan', backref='source', lazy='dynamic')
class User(db.Model): """ user representation """ id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String, unique=True, nullable=False) email = db.Column(db.String, unique=True, nullable=False) password_hash = db.Column(db.String, nullable=False) active = db.Column(db.Boolean()) confirmed_at = db.Column(db.DateTime()) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic')) def hash_password(self, password): """ creates a password hash. """ self.password_hash = pwd_context.encrypt(password) def verify_password(self, password): """ verifies the password of the user. """ return pwd_context.verify(password, self.password_hash) def generate_auth_token(self, expiration=600): """ generates a new authentication token for the user. """ s = Serializer(SECRET_KEY, expires_in=expiration) return s.dumps({'id': self.id}) @staticmethod def verify_auth_token(token): """ verifies the authentication token of the user. """ s = Serializer(SECRET_KEY) data = s.loads(token) user = User.query.get(data['id']) return user
class Image(db.Model): """ represents the image part of a biobox. existence is based solely on the quest for conformity with the schema. """ KEY_CONTAINER_URI = 'dockerhub' KEY_REPO_URL = 'repo' KEY_SRC_URL = 'source' id = db.Column(db.Integer, primary_key=True) dockerhub = db.Column(db.String, unique=True, nullable=False) repo = db.Column(db.String, unique=True, nullable=False) source = db.Column(db.String) biobox_id = db.Column(db.Integer, db.ForeignKey("biobox.pmid"), nullable=False) biobox = db.relationship("Biobox", back_populates='image', uselist=False)