Esempio n. 1
0
class Order(db.Model):

    __tablename__ = "orders"

    class STATUS(Enum):
        PENDING = 'pending'
        COMPLETED = 'completed'
        CANCELLED = 'cancelled'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    number = db.Column(db.String(255), nullable=False, unique=True)
    status = db.Column(db.Enum(STATUS), nullable=False, default=STATUS.PENDING)
    date_created_gmt = db.Column(db.DateTime,
                                 nullable=False,
                                 default=datetime.utcnow)
    modification_date_gmt = db.Column(db.DateTime,
                                      nullable=False,
                                      default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)

    order_items = db.relationship("OrderItem")

    def get_id(self):
        return self.id

    def total(self):
        return sum(oi.total() for oi in self.order_items)

    def get_status(self):
        return self.status

    def __repr__(self):
        return "<Order {0}>".format(self.number)
Esempio n. 2
0
class Image(db.Model, CRUDMixin):
    """ Images and SVGS """

    __tablename__ = "image"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), index=True, nullable=False)
    path = db.Column(db.String(1024), index=True, nullable=False)

    # There are four defaults: One for Devices, one for repairs, one for tablets and one for manufacturers
    # Use a enum instead of a Boolean and leave False fields None to make sure that only one img can be default
    device_default = db.Column(db.Enum(Default), unique=True)
    repair_default = db.Column(db.Enum(Default), unique=True)
    tablet_default = db.Column(db.Enum(Default), unique=True)
    manufacturer_default = db.Column(db.Enum(Default), unique=True)

    def __repr__(self):
        return self.name

    def get_path(self) -> str:
        return url_for('static', filename=f"images/{self.path}")
Esempio n. 3
0
class UserComparison(db.Model):
    """
    Join table of users & comparisons, with any meta (eg permissions)
    """
    __tablename__ = 'users_comparisons'

    user_id = db.Column(pg.UUID, db.ForeignKey('users.id', **fk_cascade), primary_key=True)
    comparison_id = db.Column(pg.UUID, db.ForeignKey('comparisons.id', **fk_cascade), primary_key=True)
    comparison = relationship('Comparison', backref='user_comparison')

    permission = db.Column(db.Enum(PermissionEnum), default=PermissionEnum.owner)
    weight = db.Column(db.Float)  # how much this user's vote counts (keep?)
Esempio n. 4
0
class MailLog(BaseModel, UserMixin):
    __tablename__ = "mail_log"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    timestamp = db.Column(db.DateTime,
                          nullable=False,
                          default=datetime.datetime.now)
    subject = db.Column(db.String(255), nullable=True)
    recipients = db.Column(db.Text())
    retries = db.Column(db.Integer, default=0)

    status = db.Column(db.Enum(MailStatus), default=MailStatus.PENDING)
    err_traceback = db.Column(db.Text())

    def __repr__(self):
        return f"<MailLog: [Status:{self.status}]>"