Exemplo n.º 1
0
class Role(SurrogatePK, Model):  # RoleMixin
    """A role for a user."""

    __tablename__ = 'roles'
    name = Column(db.String(80), unique=True, nullable=False)
    description = Column(db.String(255))  #
    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.º 2
0
class Images(SurrogatePK, Model):
    """An image to be added to an item."""

    __tablename__ = 'images'
    image = Column(db.String(80), nullable=False)
    caption = Column(db.String(80))
    is_primary = Column(db.Boolean(), default=False)
    item_id = reference_col('items')  # , nullable=True)
    item = relationship('Item', backref='images')

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

    def __repr__(self):
        """Represent instance as a unique string."""
        return '<Image({caption})>'.format(caption=self.caption)
Exemplo n.º 3
0
class Item(SurrogatePK, Model):
    """An item to be created by a user."""

    __tablename__ = 'items'
    name = Column(db.String(80), nullable=False)
    description = Column(db.String(255))  #
    terms = Column(db.String(255))
    price = Column(db.String(80))
    is_active = Column(db.Boolean(), default=True)
    created_at = Column(db.DateTime, default=dt.datetime.utcnow)
    user_id = reference_col('users')  # , nullable=True)
    user = relationship('User', backref='items')

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

    def __repr__(self):
        """Represent instance as a unique string."""
        # return '<Item({name})>'.format(name=self.name)
        return str(id)
Exemplo n.º 4
0
class Reviews(SurrogatePK, Model):
    """A review to be added to an item."""

    __tablename__ = 'reviews'
    stars = Column(db.Integer(), nullable=False)
    comment = Column(db.String(255))
    is_active = Column(db.Boolean(), default=True)
    created_at = Column(
        db.DateTime, default=dt.datetime.utcnow)  # server_default=text('now()'
    item_id = reference_col('items')  # , nullable=True)
    item = relationship('Item', backref='reviews')
    user_id = reference_col('users')  # , nullable=True) for anon reviews
    user = relationship('User', backref='reviews')

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

    def __repr__(self):
        """Represent instance as a unique string."""
        return '<Image({stars})>'.format(stars=self.stars)
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)
    password = Column(db.Binary(128), nullable=True)  #: The hashed password
    # password = Column(db.String(255))  #
    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)
    confirmed_at = Column(db.DateTime)  #
    last_login_at = Column(db.DateTime)  #
    current_login_at = Column(db.DateTime)  #
    last_login_ip = Column(db.String(80))  #
    current_login_ip = Column(db.String(80))  #
    login_count = Column(db.Integer)  #

    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)