Exemplo n.º 1
0
class PgFile(SurrogatePK, Model):
    __tablename__ = 'pgfiles'
    name = Column(db.String, unique=True, nullable=False)
    file = Column(db.String, unique=True, nullable=False)

    def __repr__(self):
        return self.name
Exemplo n.º 2
0
class InventoryItem(SurrogatePK, Model):
    __tablename__ = 'inventory'
    store_quantity = Column(db.Integer)
    storage_quantity = db.Column(db.Integer)
    store_capacity = Column(db.Integer)
    product_id = reference_col('product')
    product = relationship('Product', backref='inventory_items')

    def __repr__(self):
        return self.product.name

    def running_low(self):
        return self.store_capacity <= self.reorder_level

    def get_from_storage(self):
        return self.needed_at_store() <= self.storage_quantity

    def needed_at_store(self):
        return self.store_capacity - self.store_quantity

    def storage_retrieval(self, number_retrieved):
        self.store_quantity += number_retrieved
        self.storage_quantity -= number_retrieved

    def total_quantity(self):
        return self.store_quantity + self.store_quantity

    def cost(self):
        return self.product.unit_price * self.needed_at_store()
Exemplo n.º 3
0
class Product(SurrogatePK, Model):
    __tablename__ = 'product'
    name = Column(db.String, unique=True, nullable=False)
    unit_price = Column(db.Float)
    unit_id = reference_col('unit')
    unit = relationship('Unit', backref='products')
    vendor_id = reference_col('vendor')
    vendor = relationship('Vendor', backref='products')
    reorder_level = Column(db.Integer)

    def __repr__(self):
        return self.name
Exemplo n.º 4
0
class Role(SurrogatePK, Model):
    """A role for a user."""

    __tablename__ = 'roles'
    name = Column(db.String(80), unique=True, nullable=False)
    user_id = reference_col('users', nullable=True)
    user = relationship('User', backref='roles')

    def __init__(self, name, **kwargs):
        """Create instance."""
        db.Model.__init__(self, name=name, **kwargs)

    def __repr__(self):
        """Represent instance as a unique string."""
        return '<Role({name})>'.format(name=self.name)
Exemplo n.º 5
0
class User(UserMixin, SurrogatePK, Model):
    """A user of the app."""

    __tablename__ = 'users'
    username = Column(db.String(80), unique=True, nullable=False)
    email = Column(db.String(80), unique=True, nullable=False)
    #: The hashed password
    password = Column(db.Binary(128), nullable=True)
    created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
    first_name = Column(db.String(30), nullable=True)
    last_name = Column(db.String(30), nullable=True)
    active = Column(db.Boolean(), default=False)
    is_admin = Column(db.Boolean(), default=False)

    def __init__(self, username, email, password=None, **kwargs):
        """Create instance."""
        db.Model.__init__(self, username=username, email=email, **kwargs)
        if password:
            self.set_password(password)
        else:
            self.password = None

    def set_password(self, password):
        """Set password."""
        self.password = bcrypt.generate_password_hash(password)

    def check_password(self, value):
        """Check password."""
        return bcrypt.check_password_hash(self.password, value)

    @property
    def full_name(self):
        """Full user name."""
        return '{0} {1}'.format(self.first_name, self.last_name)

    def __repr__(self):
        """Represent instance as a unique string."""
        return '<User({username!r})>'.format(username=self.username)
Exemplo n.º 6
0
class Order(SurrogatePK, Model):
    __tablename__ = 'order'
    order_date = Column(db.DateTime)
    products = relationship('Product', secondary=order_products)
Exemplo n.º 7
0
class Vendor(SurrogatePK, Model):
    __tablename__ = 'vendor'
    name = Column(db.String, unique=True, nullable=False)
Exemplo n.º 8
0
class Unit(SurrogatePK, Model):
    __tablename__ = 'unit'
    name = Column(db.String, unique=True, nullable=False)