class Deposit(sqla.Model): __tablename__ = 'deposits' __table_args__ = config.documents_table_args id = Column(sqla.Integer, primary_key=True) price = Column(sqla.Integer) name = Column(sqla.String) by_user = Column(sqla.String) date = Column(sqla.DateTime(timezone=True), server_default=sqla.func.now()) lectures = sqla.relationship('Lecture', secondary=deposit_lectures)
class Order(sqla.Model): __tablename__ = 'orders' __table_args__ = config.odie_table_args id = Column(sqla.Integer, primary_key=True) name = Column(sqla.String(256)) creation_time = Column(sqla.DateTime(timezone=True), server_default=sqla.func.now()) items = sqla.relationship('OrderDocument', cascade='all', order_by=OrderDocument.index, lazy='subquery', back_populates='order') def __init__(self, name, document_ids, creation_time=None): self.name = name self.creation_time = creation_time for idx, doc in enumerate(document_ids): OrderDocument(order=self, document_id=doc, index=idx) @property def documents(self): return [item.document for item in self.items]
class Document(sqla.Model): __tablename__ = 'documents' __table_args__ = config.documents_table_args id = Column(sqla.Integer, primary_key=True) department = Column( sqla.Enum('mathematics', 'computer science', 'other', name='department', inherit_schema=True)) date = Column(sqla.Date()) number_of_pages = Column(sqla.Integer, server_default='0') solution = Column(sqla.Enum('official', 'inofficial', 'none', name='solution', inherit_schema=True), nullable=True) comment = Column(sqla.String, server_default='') document_type = Column(document_type) has_file = Column(sqla.Boolean, server_default=sqlalchemy.sql.expression.false()) has_barcode = Column(sqla.Boolean, server_default=sqlalchemy.sql.expression.false()) validation_time = Column(sqla.DateTime(timezone=True), nullable=True) submitted_by = Column(sqla.String, nullable=True) legacy_id = Column( sqla.Integer, nullable=True ) # old id from fs-deluxe, so we can recognize the old barcodes early_document_eligible = Column( sqla.Boolean, nullable=False, server_default=sqlalchemy.sql.expression.false()) deposit_return_eligible = Column( sqla.Boolean, nullable=False, server_default=sqlalchemy.sql.expression.false()) publicly_available = Column( sqla.Boolean, server_default=sqlalchemy.sql.expression.false()) lectures = sqla.relationship('Lecture', secondary=lecture_docs, back_populates='documents') examinants = sqla.relationship('Examinant', secondary=document_examinants, back_populates='documents') printed_in = sqla.relationship('Folder', secondary=folder_docs, back_populates='printed_docs') @property def examinants_names(self): return [ex.name for ex in self.examinants] @hybrid_property def validated(self): return self.validation_time is not None @validated.expression def validated(self): return Document.validation_time.isnot(None).label('validated') @property def price(self): return config.FS_CONFIG['PRICE_PER_PAGE'] * self.number_of_pages