Example #1
0
class Featured(SurrogatePK, Model):
    """
    Model for featured dapps.
    """
    __tablename__ = 'featured'

    id = Column(db.Integer,
                unique=True,
                nullable=False,
                primary_key=True,
                autoincrement=True)
    page = Column(db.SmallInteger,
                  db.ForeignKey('category.id'),
                  unique=False,
                  nullable=False)
    position = Column(db.SmallInteger, unique=False, nullable=False)
    dapp_id = Column(db.Integer, db.ForeignKey('dapp.id'), nullable=False)
    banner_path = Column(db.String(100), unique=True, nullable=False)

    # TODO: consider change value type to decimal
    #bid_value = Column(db.Float, unique=False, nullable=False)
    #btc_value = Column(db.Float, unique=False, nullable=False)

    duration = Column(db.Integer, unique=False, nullable=False)
    start_date = Column(db.DateTime, unique=False, nullable=False)
    end_date = Column(db.DateTime, unique=False, nullable=False)

    @hybrid_property
    def banner_url(self):
        return join(current_app.config['S3_BUCKET_PATH'], self.banner_path)

    def __repr__(self):
        return '<Featured({id})>'.format(id=self.id)
class ContactForm(SurrogatePK, Model):
    """
    Model for contact form.
    """
    __tablename__ = 'contact_form'

    id = Column(db.Integer,
                unique=True,
                nullable=False,
                primary_key=True,
                autoincrement=True)
    name = Column(db.String(32), unique=False, nullable=False)
    email = Column(db.String(80), unique=False, nullable=False)
    message = Column(db.String(1000), unique=False, nullable=False)

    def __repr__(self):
        return '<ContactForm()>'
class DappSubmission(SurrogatePK, Model):
    """
    Model for all dapp submissions.
    """
    __tablename__ = 'dapp_submission'

    id = Column(db.Integer, unique=True, nullable=False,
                primary_key=True, autoincrement=True)
    name = Column(db.String(80), unique=False, nullable=False)
    url = Column(db.String(80), unique=False, nullable=False)
    address = Column(ARRAY(db.String), unique=False, nullable=False)
    blockchain_id = Column(db.Integer, db.ForeignKey('blockchain.id'), unique=False, nullable=False)
    category_id = Column(db.Integer, db.ForeignKey(
        'category.id'), nullable=False)
    user_id = Column(db.Integer, db.ForeignKey('dappest_user.id'), nullable=False)
    author = Column(ARRAY(db.String), unique=False, nullable=False)
    email = Column(db.String(80), unique=False, nullable=False)
    logo_path = Column(db.String(100), unique=False, nullable=False)
    screenshot = Column(ARRAY(db.String), unique=True, nullable=False)
    tagline = Column(db.String(80), unique=False, nullable=False)
    description = Column(db.String(500), unique=False, nullable=False)
    whitepaper = Column(db.String(160), unique=True, nullable=True, default=None)
    social_media = Column(JSONB, unique=False, nullable=False, default={})
    s3_id = Column(UUID, unique=True, nullable=False)
    status = Column(db.SmallInteger, unique=False, nullable=False,
                    default=0)
    uploaded_at = Column(db.DateTime, nullable=False,
                         default=dt.datetime.utcnow)
    launch_date = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)

    def __repr__(self):
        return '<DappSubmission({id})>'.format(id=self.id)
class RankingName(SurrogatePK, Model):
    """
    Model for all ranking names.
    """
    __tablename__ = 'ranking_name'

    id = Column(db.SmallInteger, unique=True, nullable=False,
                primary_key=True, autoincrement=True)
    name = Column(db.String(32), unique=True, nullable=False)

    ranking = relationship('Ranking', back_populates='ranking_name', lazy='noload')

    def __repr__(self):
        return '<RankingName({name})>'.format(name=self.name)
class Blockchain(SurrogatePK, Model):
    """
    Model for blockchains.
    """
    __tablename__ = 'blockchain'

    # Columns
    id = Column(db.Integer,
                unique=True,
                nullable=False,
                primary_key=True,
                autoincrement=True)
    name = Column(db.String(32), unique=True, nullable=False)
    symbol = Column(db.String(16), unique=True, nullable=False)

    # Relationships to other tables
    dapps = relationship('Dapp', back_populates='blockchain', lazy='noload')
    users = relationship('User', back_populates='blockchain', lazy='noload')
    block_intervals = relationship('BlockInterval',
                                   back_populates='blockchain',
                                   lazy='noload')

    def __repr__(self):
        return '<Blockchain({id})>'.format(id=self.symbol)
class MailingList(SurrogatePK, Model):
    """
    Model for mailing list.
    """
    __tablename__ = 'mailing_list'

    # Columns
    id = Column(db.Integer, unique=True, nullable=False,
                primary_key=True, autoincrement=True)
    email = Column(db.String(80), unique=True, nullable=False)
    uploaded_at = Column(db.DateTime, nullable=False,
                         default=dt.datetime.utcnow)

    def __repr__(self):
        return '<MailingList()>'
class DailyItem(SurrogatePK, Model):
    """
    Model for items that change daily.
    """
    __tablename__ = 'daily_item'

    id = Column(db.Integer,
                unique=True,
                nullable=False,
                primary_key=True,
                autoincrement=True)
    item_name = Column(db.String(32), unique=True, nullable=False)
    item_id = Column(db.Integer, unique=False, nullable=False, default=0)

    def __repr__(self):
        return '<DailyItem({name})>'.format(name=self.item_name)
Example #8
0
class Category(SurrogatePK, Model):
    """
    Model for categories.
    """
    __tablename__ = 'category'

    id = Column(db.Integer,
                unique=True,
                nullable=False,
                primary_key=True,
                autoincrement=True)
    name = Column(db.String(32), unique=True, nullable=False)

    dapps = relationship('Dapp', back_populates='category', lazy='noload')

    def __repr__(self):
        return '<Category({name})>'.format(name=self.name)
Example #9
0
class Review(SurrogatePK, Model):
    """
    Model for all dapp reviews.
    """
    __tablename__ = 'review'

    # Columns
    id = Column(db.Integer,
                unique=True,
                nullable=False,
                primary_key=True,
                autoincrement=True)
    dapp_id = Column(db.Integer, db.ForeignKey('dapp.id'), nullable=False)
    user_id = Column(db.Integer,
                     db.ForeignKey('dappest_user.id'),
                     nullable=False)
    rating = Column(db.SmallInteger, unique=False, nullable=False)
    title = Column(db.String(50), unique=False, nullable=False)
    review = Column(db.Text, unique=False, nullable=False)
    feature = Column(JSONB, unique=False, nullable=False, default={})
    uploaded_at = Column(db.DateTime,
                         nullable=False,
                         default=dt.datetime.utcnow)
    data = Column(JSONB, unique=False, nullable=False, default={})
    verified = Column(db.Boolean, unique=False, nullable=False, default=False)

    dapp = relationship('Dapp', back_populates='reviews', lazy='select')
    user = relationship('User', back_populates='reviews', lazy='joined')
    helpful_votes = relationship(
        'ReviewLike',
        primaryjoin='and_(Review.id==ReviewLike.review_id, '
        'ReviewLike.helpful==1)')

    # not_helpful_votes = relationship('ReviewLike',
    #                                  primaryjoin='and_(Review.id==ReviewLike.review_id, '
    #                                              'ReviewLike.helpful==0)')

    def __repr__(self):
        return '<Review({id})>'.format(id=self.id)
Example #10
0
class Dapp(SurrogatePK, Model):
    """
    Model for all dapps.
    """
    __tablename__ = 'dapp'

    # Columns
    id = Column(db.Integer,
                unique=True,
                nullable=False,
                primary_key=True,
                autoincrement=True)
    name = Column(db.String(80), unique=True, nullable=False)
    url = Column(db.String(80), unique=True, nullable=False)
    address = Column(ARRAY(db.String), unique=True, nullable=False)
    author = Column(ARRAY(db.String), unique=False, nullable=False)
    email = Column(db.String(80), unique=False, nullable=False)
    logo_path = Column(db.String(100), unique=True, nullable=False)
    screenshot = Column(ARRAY(db.String), unique=True, nullable=False)
    tagline = Column(db.String(80), unique=False, nullable=False)
    description = Column(db.String(500), unique=False, nullable=False)
    whitepaper = Column(db.String(160),
                        unique=False,
                        nullable=True,
                        default=None)
    social_media = Column(JSONB, unique=False, nullable=False, default={})
    category_id = Column(db.Integer,
                         db.ForeignKey('category.id'),
                         nullable=False)
    blockchain_id = Column(db.Integer,
                           db.ForeignKey('blockchain.id'),
                           nullable=False)
    user_id = Column(db.Integer,
                     db.ForeignKey('dappest_user.id'),
                     nullable=False)
    s3_id = Column(UUID, unique=True, nullable=False)
    uploaded_at = Column(db.DateTime,
                         nullable=False,
                         default=dt.datetime.utcnow)
    launch_date = Column(db.DateTime, nullable=False)

    # Relationships to other tables
    blockchain = relationship('Blockchain',
                              back_populates='dapps',
                              lazy='select')
    category = relationship('Category', back_populates='dapps', lazy='select')
    reviews = relationship('Review', back_populates='dapp', lazy='subquery')
    user = relationship('User', back_populates='dapps', lazy='select')

    @hybrid_property
    def logo_url(self):
        return join(current_app.config['S3_BUCKET_PATH'], self.logo_path)

    @hybrid_property
    def screenshot_url(self):
        return [
            join(current_app.config['S3_BUCKET_PATH'], x)
            for x in self.screenshot
        ]

    def __repr__(self):
        return '<Dapp({name})>'.format(name=self.name)
Example #11
0
class User(SurrogatePK, Model):
    """
    Model for all users.
    """
    __tablename__ = 'dappest_user'

    # Columns
    id = Column(db.Integer,
                unique=True,
                nullable=False,
                primary_key=True,
                autoincrement=True)
    address = Column(db.String(64), unique=True, nullable=False)
    username = Column(db.String(64),
                      unique=True,
                      nullable=False,
                      default=default_username)
    email = Column(db.String(64), unique=False, nullable=True, default=None)
    profile_picture = Column(db.String(100),
                             unique=False,
                             nullable=True,
                             default=None)
    blockchain_id = Column(db.Integer,
                           db.ForeignKey('blockchain.id'),
                           nullable=False)
    s3_id = Column(UUID, unique=True, nullable=False, default=str(uuid4()))
    created_at = Column(db.DateTime,
                        nullable=False,
                        default=dt.datetime.utcnow)
    nonce = Column(db.String(9),
                   nullable=False,
                   unique=False,
                   default=generate_nonce)

    # Relationships to other tables
    blockchain = relationship('Blockchain',
                              back_populates='users',
                              lazy='noload')
    reviews = relationship('Review', back_populates='user', lazy='noload')
    review_likes = relationship('ReviewLike',
                                back_populates='user',
                                lazy='noload')
    dapps = relationship('Dapp', back_populates='user', lazy='noload')

    def __repr__(self):
        return '<User({username!r})>'.format(username=self.username)

    @staticmethod
    def get_user_from_jwt_token(user_from_token):
        """
        Validate ideneity from jwt token.
        :param user_from_token:
        :return:
        """
        user_id = user_from_token.get('id')
        user_address = user_from_token.get('address')

        if user_id and user_address:
            user = User.get_by_id(user_id)

            if user and user.id == user_id and user.address == user_address:
                return user

        return None