Ejemplo n.º 1
0
class Item(db.Model):
    __tablename__ = 'item'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(20), nullable=False)  # 商品名
    description = db.Column(db.Text)  # 商品説明文
    period = db.Column(db.Integer, nullable=False)  # 販売日数
    remaining_days = db.Column(db.Integer, nullable=False)
    remaining_format_id = db.Column(
        db.Integer,
        db.ForeignKey('remaining_format.id',
                      onupdate='CASCADE',
                      ondelete='CASCADE'))
    category_id = db.Column(db.Integer,
                            db.ForeignKey('category.id',
                                          onupdate='CASCADE',
                                          ondelete='CASCADE'))  # 設定したカテゴリのID
    shipment = db.Column(db.Integer, nullable=False)  # 配送にかかる時間(日)
    price = db.Column(db.Integer, nullable=False)  # 商品の値段
    state = db.Column(db.Integer)  # 商品の状態
    user_id = db.Column(
        db.Integer,
        db.ForeignKey('user.id', onupdate='CASCADE', ondelete='CASCADE'))
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.now,
                           onupdate=datetime.now)
    item_image = db.relationship('ItemImage', backref='item')

    def __init__(self,
                 name=None,
                 description=None,
                 period=None,
                 remaining_days=None,
                 remaining_format_id=None,
                 category_id=None,
                 shipment=None,
                 price=None,
                 state=None,
                 user_id=None):
        self.name = name
        self.description = description
        self.period = period
        self.remaining_days = remaining_days
        self.remaining_format_id = remaining_format_id
        self.category_id = category_id
        self.shipment = shipment
        self.price = price
        self.state = state
        self.user_id = user_id

    def postRecord(self):
        db.session.add(self)
        db.session.commit()

    @classmethod
    def getProductById(cls, item_id):
        record = cls.query.filter_by(id=item_id).first()
        return record
Ejemplo n.º 2
0
class ItemImage(db.Model):
    __tablename__ = 'item_image'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    item_id = db.Column(
        db.Integer,
        db.ForeignKey('item.id', onupdate='CASCADE', ondelete='CASCADE'))
    url = db.Column(db.String(255), nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.now,
                           onupdate=datetime.now)

    def __init__(self, url='', item_id=None):
        self.url = url
        self.item_id = item_id

    def postRecord(self):
        db.session.add(self)
        db.session.commit()
        db.session.refresh(self)
        return self

    @classmethod
    def getImage(cls, image_id):
        record = cls.query.filter_by(id=image_id).first()
        return record
Ejemplo n.º 3
0
class Candlestick(db.Model):
    __tablename__ = 'candlesticks'
    __table_args__ = (db.UniqueConstraint(
        'datetime', 'asset_id', name='unique_candlesticks_date_asset_id'), )

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    datetime = db.Column(db.DateTime, nullable=False)
    low_price = db.Column(db.Float, nullable=True, default=None)
    high_price = db.Column(db.Float, nullable=True, default=None)
    open_price = db.Column(db.Float, nullable=True, default=None)
    close_price = db.Column(db.Float, nullable=True, default=None)
    volume = db.Column(db.Float, nullable=True)
    weighted_volume = db.Column(db.Float, nullable=True)
    asset_id = db.Column(db.Integer, db.ForeignKey('assets.id'))

    asset = db.relationship('Asset',
                            back_populates='candlesticks',
                            uselist=False)

    def __repr__(self) -> str:
        return (
            f'Candlestick(datetime={self.datetime}, close_price={self.close_price}, open_price={self.open_price}, '
            f'low_price={self.low_price}, high_price={self.high_price}), volume={self.volume}'
        )

    __str__ = __repr__
Ejemplo n.º 4
0
class Comments(db.Model):

    # Generates default class name for table. For changing use
    # __tablename__ = 'users'

    # User id.
    id = db.Column(db.Integer, primary_key=True)
	
	# User id.
    noteid = db.Column(db.Integer, db.ForeignKey('notes.id'))
	
    # User name.
    username = db.Column(db.String(length=80))

    # User email address.
    description = db.Column(db.String(length=250))

    # Creation time for user.
    created = db.Column(db.DateTime, default=datetime.utcnow)


    def __repr__(self):

        # This is only for representation how you want to see user information after query.
        return "<User(id='%s', name='%s', title='%s', description='%s', created='%s')>" % (
                      self.id, self.username, self.title, self.description, self.created)
Ejemplo n.º 5
0
class LanguageDetail(db.Model):

    __tablename__ = "language_details" # table name will default to name of the model

    # Create columns
    id = db.Column(db.Integer, primary_key=True)
    # page id
    page_id = db.Column(db.Integer, db.ForeignKey('pages.id'))
    # language id
    lang_id = db.Column(db.Integer, db.ForeignKey('languages.id'))
    # language content
    content = db.Column(db.Text)
    # language content translated
    translate = db.Column(db.Text)
    # Creation time for language details.
    created = db.Column(db.DateTime, default=datetime.utcnow)

    # this is not essential, but a valuable method to overwrite as this is what we will see when we print out an instance in a REPL.
    def __repr__(self):
        return "<LanguageDetail(id='%s', page_id='%d', lang_id='%d', content='%s', translate='%s')>" % (
                      self.id, self.page_id, self.lang_id, self.content, self.translate)
Ejemplo n.º 6
0
class Auth(db.Model):
    __tablename__ = 'auth'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_id = db.Column(
        db.Integer,
        db.ForeignKey('user.id', onupdate='CASCADE', ondelete='CASCADE'))
    email = db.Column(db.String(50), unique=True, nullable=False)
    password = db.Column(db.String(300), nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.now,
                           onupdate=datetime.now)

    def __init__(self, user_id='', email='', password=''):
        self.user_id = user_id
        self.email = email
        self.password = hashlib.sha256(password.encode('utf-8')).hexdigest()

    def setAttr(self, user_id='', email='', password=''):
        self.user_id = user_id
        self.email = email
        self.password = hashlib.sha256(password.encode('utf-8'))

    def postRecord(self):
        db.session.add(self)
        db.session.commit()
        return

    @classmethod
    def getRecordsAll(cls):
        records = cls.query.all()
        return records

    @classmethod
    def getRecordByEmail(cls, email):
        record = cls.query.filter_by(email=email).first()
        return record

    @classmethod
    def getRecordsByUserId(cls, user_id):
        record = cls.query.filter_by(user_id=user_id).first()
        return record
Ejemplo n.º 7
0
class User(db.Model):

    # Generates default class name for table. For changing use
    # __tablename__ = 'users'

    # User id.
    id = db.Column(db.Integer, primary_key=True)
    # User name.
    username = db.Column(db.String(length=80))
    # User email address.
    email = db.Column(db.String(length=80))
    # User password.
    password = db.Column(db.String(length=80))
    # First name.
    first_name = db.Column(db.String(length=80))
    # Last name.
    last_name = db.Column(db.String(length=80))
    # Unless otherwise stated default role is user.
    user_role = db.Column(db.Integer)
    # User country.
    user_country = db.Column(db.Integer, db.ForeignKey('countries.id'))
    # User language.
    user_language = db.Column(db.Integer, db.ForeignKey('languages.id'))    
    # Creation time for user.
    created = db.Column(db.DateTime, default=datetime.utcnow)

    # Relationships
    languages = relationship("Language")
    countries = relationship("Country")
    # Generates auth token.
    def generate_auth_token(self, permission_level):

        # Check if admin.
        if permission_level == 1:

            # Generate admin token with flag 1.
            token = jwt.dumps({'email': self.email, 'admin': 1})

            # Return admin flag.
            return token

            # Check if admin.
        elif permission_level == 2:

            # Generate admin token with flag 1.
            token = jwt.dumps({'email': self.email, 'admin': 2})

            # Return admin flag.
            return token

        # Return normal user flag.
        return jwt.dumps({'email': self.email, 'admin': 0})

    # Generates a new access token from refresh token.
    @staticmethod
    @auth.verify_token
    def verify_auth_token(token):

        # Create a global none user.
        g.user = None

        try:
            # Load token.
            data = jwt.loads(token)

        except:
            # If any error return false.
            return False

        # Check if email and admin permission variables are in jwt.
        if 'email' and 'admin' in data:

            # Set email from jwt.
            g.user = data['email']

            # Set admin permission from jwt.
            g.admin = data['admin']

            # Return true.
            return True

        # If does not verified, return false.
        return False

    def __repr__(self):

        # This is only for representation how you want to see user information after query.
        return "<User(id='%s', name='%s', password='******', email='%s', created='%s')>" % (
                      self.id, self.user_country, self.user_language, self.username, self.password, self.email, self.created)