示例#1
0
class UserMessages(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    from_user = db.Column(db.String(50), nullable=False)
    from_user_image = db.Column(db.String(50))
    message_date = db.Column(db.DateTime, default=get_cst)
    message_body = db.Column(db.String(2000), nullable=False)
    acknowledged = db.Column(db.Boolean(), default=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User', back_populates='messages')
    has_read = db.Column(db.Boolean(), default=False)

    def __repr__(self):
        return f"User('{self.id}','{self.from_user}', '{self.from_user_image}', '{self.message_date}', '{self.user_id}', '{self.acknowledged}')"
示例#2
0
class Set(db.Model):
    __tablename__ = 'sets'
    no = db.Column(db.String(255), primary_key=True, nullable=False)
    name = db.Column(db.Text(150), nullable=False)
    type = db.Column(db.String(255), nullable=False)
    category_id = db.Column(db.String(255), nullable=False)
    category = db.Column(db.String(255), nullable=False)
    image_url = db.Column(db.String(255))
    thumbnail_url = db.Column(db.String(255))
    weight = db.Column(db.Float())
    dim_x = db.Column(db.Float())
    dim_y = db.Column(db.Float())
    dim_z = db.Column(db.Float())
    year_released = db.Column(db.String(4))
    obsolete = db.Column(db.Boolean())
    complete = db.Column(db.Boolean(), nullable=False)
    extras = db.Column(db.Boolean(), nullable=False)
    children = db.relationship("Part")
    __table_args__ = (
        db.UniqueConstraint("no"),
    )

    def __init__(self, no, name, type, category_id, category, image_url, thumbnail_url, weight, dim_x, dim_y, dim_z, year_released, obsolete, complete, extras):
        self.no = no
        self.name = name
        self.type = type
        self.category_id = category_id
        self.category = category
        self.image_url = image_url
        self.thumbnail_url = thumbnail_url
        self.weight = weight
        self.dim_x = dim_x
        self.dim_y = dim_y
        self.dim_z = dim_z
        self.year_released = year_released
        self.obsolete = obsolete
        self.complete = complete
        self.extras = extras

    def __repr__(self):
        return self.no + ", " + \
               self.name + ", "

    # subclass JSONEncoder
    class SetEncoder(JSONEncoder):
        def default(self, o):
            return o.__dict__
class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(100), unique=True)
    password = db.Column(db.String(100))
    email_verified = db.Column(db.Boolean())
    email_code = db.Column(db.String(64))
    password_reset_code = db.Column(db.String(64))
    classes = db.Column(db.JSON)
示例#4
0
class Part(db.Model):
    __tablename__ = 'parts'
    no = db.Column(db.String(255), primary_key=True, nullable=False)
    set_no = db.Column(db.String(255), db.ForeignKey('sets.no'), primary_key=True, nullable=False)
    color_id = db.Column(db.String(255), primary_key=True, nullable=False)
    color_name = db.Column(db.String(255), nullable=False)
    color_code = db.Column(db.String(255), nullable=False)
    color_type = db.Column(db.String(255), nullable=False)
    name = db.Column(db.Text(150), nullable=False)
    type = db.Column(db.String(255), nullable=False)
    category_id = db.Column(db.String(255), nullable=False)
    owned_quantity = db.Column(db.Integer())
    quantity = db.Column(db.Integer())
    extra_quantity = db.Column(db.Integer())
    is_alternate = db.Column(db.Boolean())
    is_counterpart = db.Column(db.Boolean())
    thumbnail_url = db.Column(db.String(255))
    __table_args__ = (
        db.UniqueConstraint("no", "set_no", "color_id"),
    )

    def __init__(self, no, set_no, name, type, category_id, color_id, color_name, color_code, color_type, owned_quantity, quantity, extra_quantity, is_alternate, is_counterpart, thumbnail_url):
        self.no = no
        self.set_no = set_no
        self.name = name
        self.type = type
        self.category_id = category_id
        self.color_id = color_id
        self.color_name = color_name
        self.color_code = color_code
        self.color_type = color_type
        self.owned_quantity = owned_quantity
        self.quantity = quantity
        self.extra_quantity = extra_quantity
        self.is_alternate = is_alternate
        self.is_counterpart = is_counterpart
        self.thumbnail_url = thumbnail_url

    def __repr__(self):
        return '<Part %r>' % self.no

    # subclass JSONEncoder
    class PartEncoder(JSONEncoder):
        def default(self, o):
            return o.__dict__
示例#5
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(255), unique=True)
    password = db.Column(db.String(255))
    first_name = db.Column(db.String(255))
    last_name = db.Column(db.String(255))
    organization = db.Column(db.String(255))
    active = db.Column(db.Boolean())
    confirmed_at = db.Column(db.DateTime())
    roles = db.relationship('Role', secondary=roles_users,
    backref=db.backref('users', lazy='dynamic'))
示例#6
0
class Campanha(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    empresa = db.Column(db.Integer, db.ForeignKey('empresa.id'))
    produto = db.Column(db.Integer, db.ForeignKey('produto.id'))
    campanha = db.Column(db.String(150))
    valorcamp = db.Column(db.Float)
    descr = db.Column(db.String(250))
    condicoes = db.Column(db.String(250))
    ofertas = db.Column(db.String(250))
    fotos = db.Column(db.String(250))
    campuser = db.relationship('CampUser', cascade="all, delete-orphan")
    deleted = db.Column(db.Boolean(), default=False)
示例#7
0
文件: models.py 项目: kkl116/Stonks
class Alert(db.Model):
    __tablename__ = 'alerts'
    id = db.Column(db.Integer, primary_key=True)
    ticker_name = db.Column(db.String(), unique=False, nullable=False)
    price_level = db.Column(db.Float(), unique=False, nullable=True)
    percentage_change = db.Column(db.Float(), unique=False, nullable=True)
    date_added = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow())
    email_alert = db.Column(db.Boolean(), nullable=False)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id', ondelete="CASCADE"),
                        nullable=False)

    def __repr__(self):
        return f'Alert({self.ticker_name}, {self.price_level}, {self.percentage_change}, {self.date_added}, {self.user_id})'
示例#8
0
class User(Base):
    __tablename__ = 'user'

    name = db.Column(db.String(80), unique=True, nullable=False)
    salt = db.Column(db.String(29), nullable=False)
    password = db.Column(db.String(60), nullable=False)
    is_admin = db.Column(db.Boolean(), default=False, nullable=False)

    def __init__(self, name, salt, password, is_admin=False):
        self.name = name

        self.salt = salt
        self.password = password
        self.is_admin = is_admin

    def __repr__(self):
        return '<User %r>' % self.name
示例#9
0
文件: models.py 项目: kkl116/Stonks
class User(db.Model, UserMixin):
    """static methods cant modify instnace or class state - provides a way to restrict the data
    that a method can access, primarily a way to namespace your methods"""

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20), nullable=False, default='')
    password = db.Column(db.String(60), nullable=False)
    verified = db.Column(db.Boolean(), nullable=False, default=False)
    currency = db.Column(db.String(), nullable=False, default='GBP')
    """here lazily load b/c no need to load it unless in the watchlist page..."""
    #one to many relationships
    watchlistItems = db.relationship('WatchlistItem',
                                     backref='user',
                                     lazy=True,
                                     cascade="all, delete, delete-orphan",
                                     passive_deletes=True)
    portfolioOrders = db.relationship('PortfolioOrder',
                                      backref='user',
                                      lazy=True,
                                      cascade="all, delete, delete-orphan",
                                      passive_deletes=True)
    positions = db.relationship('Position',
                                backref='user',
                                lazy=True,
                                cascade='all, delete, delete-orphan',
                                passive_deletes=True)
    alerts = db.relationship('Alert',
                             backref='user',
                             lazy=True,
                             cascade='all, delete, delete-orphan',
                             passive_deletes=True)
    #many to many relationships
    subscriptions = db.relationship('Quote',
                                    secondary=user_subscriptions,
                                    backref=db.backref('users', lazy=True),
                                    lazy=True)

    def get_reset_token(self, expires_sec=1800):
        s = TimedSerializer(current_app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    def get_verification_token(self):
        s = Serializer(current_app.config['SECRET_KEY'])
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_token(token, timed=False):
        if timed:
            s = TimedSerializer(current_app.config['SECRET_KEY'])
        else:
            s = Serializer(current_app.config['SECRET_KEY'])

        try:
            user_id = s.loads(token)['user_id']
        except Exception as e:
            return None

        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}')"