class ApprovalDetail(db.Model): __tablename__ = 'approval_detail' db.Table( 'approval_detail', db.Model.metadata, db.Column('fk_order_id', Integer, ForeignKey('Order.pk_id')), extend_existing=True, )
class AdditionalRunDate(db.Model): __tablename__ = 'additional_run_date' db.Table( 'additional_run_date', db.Model.metadata, db.Column('pk_id', Integer, primary_key=True), extend_existing=True, ) order = relationship( 'Order', foreign_keys='Order.pk_id', primaryjoin='AdditionalRunDate.fk_order_id == Order.pk_id', backref='addtionalRunDates')
class Order(db.Model): __tablename__ = 'cdg_order' db.Table( 'cdg_order', db.Model.metadata, db.Column('fk_creator_id', Integer, ForeignKey(User.pk_id)), db.Column('fk_branch_id', Integer, ForeignKey(Branch.pk_id)), extend_existing=True, ) approvalDetails = relationship( 'ApprovalDetail', foreign_keys='ApprovalDetail.fk_order_id', primaryjoin='ApprovalDetail.fk_order_id == Order.pk_id', backref='order') @hybrid_property def dateApprovedBM(self): for detail in self.approvalDetails: if (detail.status_description == APPROVED and (detail.user_role == BM_APPROVAL or detail.user_role == MM_APPROVAL or detail.user_role == SITE_ADMIN)): return self.date_created @hybrid_property def approvedBM(self): for detail in self.approvalDetails: if (detail.status_description == APPROVED and (detail.user_role == BM_APPROVAL or detail.user_role == MM_APPROVAL)): return detail.user_name elif (detail.status_description == APPROVED and detail.user_role == SITE_ADMIN): return ADMIN @hybrid_property def approvedDM(self): for detail in self.approvalDetails: if detail.status_description == APPROVED and detail.user_role == SITE_ADMIN: return detail.user_name @hybrid_property def dateApprovedDM(self): for detail in self.approvalDetails: if detail.status_description == APPROVED and detail.user_role == SITE_ADMIN: return self.date_created @hybrid_property def hi_res_path(self): return prepare_file_path(self.hi_res_uri)
class UserInfoBranchJoin(db.Model): __tablename__ = 'user_info_to_branch' db.Table( 'user_info_to_branch', db.Model.metadata, db.Column('cpkfk_branch_id', Integer, ForeignKey(Branch.pk_id), primary_key=True), db.Column('cpkfk_user_info_id', Integer, ForeignKey(UserInfo.pk_id), primary_key=True), extend_existing=True, )
class UserInfo(db.Model): __tablename__ = 'lab_user_info' db.Table( 'lab_user_info', db.Model.metadata, db.Column('fk_branch_id', Integer, ForeignKey(Branch.pk_id)), extend_existing=True, ) @hybrid_property def nameFull(self): return ' '.join([self.name_last, self.name_first]) @hybrid_property def branchManager(self): if len(self.branch.managers) > 0: return self.branch.managers[0] return None
from model import db from model.book import Book """ Helper table to define relationships between books and collections. """ collection_table = db.Table( 'collections', db.Column('book_id', db.Integer, db.ForeignKey('book.book_id'), primary_key=True), db.Column('collection_id', db.Integer, db.ForeignKey('book_collection.collection_id'), primary_key=True)) class BookCollection(db.Model): collection_id = db.Column(db.Integer, primary_key=True) book_ids = db.relationship(Book, secondary=collection_table, backref=db.backref('books', lazy='dynamic')) title = db.Column(db.String, nullable=False, unique=True) def __repr__(self): return "<Collection(collection_id='%s',books='%s',title='%s'>" \ % (self.collection_id, self.book.ids, self.title) def to_dict(self): """ Method to transform BookCollection to a dictionary object. :return: dictionary object.
from model import db """ Helper table to define the many to many relationship between books and authors. """ authorship_table = db.Table( 'authorship', db.Column('book_id', db.Integer, db.ForeignKey('book.book_id'), primary_key=True), db.Column('author_id', db.Integer, db.ForeignKey('author.author_id'), primary_key=True)) class Book(db.Model): book_id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String, nullable=False) publish_date = db.Column(db.Date, nullable=False) subject = db.Column(db.String, nullable=False) genre = db.Column(db.String, nullable=False) notes = db.relationship('Note', backref=db.backref('book')) authors = db.relationship('Author', secondary=authorship_table, backref=db.backref('books', lazy='dynamic')) copies = db.relationship('BookCopy', cascade="all,delete", backref=db.backref('book')) def __repr__(self): return"<Book(book_id='%s',title='%s',publish_date='%s',subject='%s',genre='%s'," \
from auth.roles import Role __author__ = "Noah Hummel" from model import db ownership_table = db.Table( 'ownership_assoc', db.Model.metadata, db.Column( 'person_id', db.Integer, db.ForeignKey('person.id', ondelete='CASCADE', onupdate='CASCADE')), db.Column( 'ownership_base_id', db.Integer, db.ForeignKey('ownership_base.id', ondelete='CASCADE', onupdate='CASCADE'))) def query_owned(person_type: db.Model, person_id: int, owned_type: db.Model): query = owned_type.query.join(ownership_table).join(person_type).\ filter((ownership_table.c.person_id == person_type.id) & (ownership_table.c.ownership_base_id == owned_type.id)).\ filter(person_type.id == person_id) return query class OwnershipBase(db.Model): id = db.Column(db.Integer, primary_key=True) # polymorphic config ownership_base_type = db.Column(db.String(50))