コード例 #1
0
class Actor(db.Model):
    id = db.Column(db.Integer(), primary_key=True)  # 1-1 w/ api
    query_class = ActorQuery
    search_vector = db.Column(TSVectorType('name'))

    biography = db.Column(db.Text())
    birthday = db.Column(db.Date())
    deathday = db.Column(db.Date())
    homepage = db.Column(db.Text())
    name = db.Column(db.Text())
    place_of_birth = db.Column(db.Text())
    profile_path = db.Column(db.Text())
    imdb_id = db.Column(db.Text())

    def get_actor_metadata(self):
        ret = dict()
        ret['biography'] = self.biography
        ret['birthday'] = self.birthday
        ret['deathday'] = self.deathday
        ret['homepage'] = self.homepage
        ret['name'] = self.name
        ret['place_of_birth'] = self.place_of_birth
        ret['profile_path'] = self.profile_path
        ret['imdb_id'] = self.imdb_id
        return ret
コード例 #2
0
ファイル: list.py プロジェクト: jjmar/myflickslist
class FlicksListItem(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    movie = db.relationship('Movie')
    movie_id = db.Column(db.Integer(), db.ForeignKey('movie.id'))
    list_id = db.Column(db.Integer(), db.ForeignKey('flicks_list.id'))
    notes = db.Column(db.String(64))
    completed = db.Column(db.Boolean(), default=False)
    rating = db.Column(db.Integer())
    completion_date = db.Column(db.Date())
    ordering = db.Column(db.Integer())
コード例 #3
0
class Review(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    body = db.Column(db.String(10000))

    # M:1
    movie_id = db.Column(db.Integer, db.ForeignKey('movie.id'))
    movie = db.relationship('Movie', backref='reviews')

    timestamp = db.Column(db.Date(), default=date.today)
コード例 #4
0
ファイル: user.py プロジェクト: fangxuan/YQV-Services
class User(BaseModel, Model):
    __tablename__ = 'user'
    name = Column(db.String(50), comment='用户名')
    password = Column(db.String(128), comment='密码')
    gender = Column(db.String(4), comment='性别')
    phone = Column(db.String(20), comment='手机号')
    email = Column(db.String(50), comment='邮箱')
    avatar = Column(db.String(128), comment='头像')
    birthday = Column(db.Date(), comment='生日')
    coin = Column(db.Integer, comment='积分')
コード例 #5
0
class Recommendation(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    body = db.Column(db.String(500))
    timestamp = db.Column(db.Date(), default=date.today)

    recommendation_from = db.Column(db.Integer(), db.ForeignKey('movie.id'))

    # M : 1
    recommendation_to = db.Column(db.Integer(), db.ForeignKey('movie.id'))
    recommendation = db.relationship('Movie', foreign_keys='Recommendation.recommendation_to')
コード例 #6
0
ファイル: farm.py プロジェクト: fangxuan/YQV-Services
class UserPlant(BaseModel, Model):
    __tablename__ = 'user_plant'
    plant_id = Column(db.ForeignKey('plant.id'), comment="植物id")
    user_id = Column(db.ForeignKey('user.id'), comment="用户id")
    active_flag = Column(db.Boolean(), server_default=db.text("True"), comment="是否启用,True启用 False不启用", index=True)
    water = Column(db.Integer(), comment='水分')
    fertilizer = Column(db.Integer(), comment='肥料')
    pesticide = Column(db.Integer(), comment='药')
    price = Column(db.Numeric(4, 2), comment='价值')
    harvest_at = Column(db.Date(), comment='预计收获时间')
    status = Column(db.Enum(PlantStatus), comment='状态')
    image = Column(db.String(1024), comment='图片')
コード例 #7
0
class Assignment(db.Model):
    __tablename__ = 'assignment'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String())
    grade = db.Column(db.String())
    student = db.Column(db.Integer())
    attachment = db.Column(db.String())
    comments = db.Column(db.String())
    date = db.Column(db.Date())

    def __init__(self, student, date, title, grade, attachment, comments):
        self.student = student
        self.date = date
        self.title = title
        self.grade = grade
        self.attachment = attachment
        self.comments = comments
コード例 #8
0
class Movie(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    query_class = MovieQuery
    search_vector = db.Column(TSVectorType('title'))

    # Movie Metadata
    title = db.Column(db.Text())
    status = db.Column(db.Text())
    budget = db.Column(db.BigInteger())
    imdb_id = db.Column(db.Text())
    revenue = db.Column(db.BigInteger())
    backdrop_path = db.Column(db.Text())
    poster_path = db.Column(db.Text())
    adult = db.Column(db.Boolean, default=False)
    original_language = db.Column(db.Text())
    overview = db.Column(db.Text())
    release_date = db.Column(db.Date())
    runtime = db.Column(db.Integer())
    tagline = db.Column(db.Text())
    homepage = db.Column(db.Text())

    # Relationships
    genres = db.relationship('Genre',
                             backref='movies',
                             secondary=movie_genre_lnk)
    characters = db.relationship(
        'Character', backref='found_in')  # Should this be many to many?
    videos = db.relationship('Video')
    countries = db.relationship('Country',
                                backref='movies',
                                secondary=movie_country_lnk)
    recommendations = db.relationship(
        'Recommendation',
        foreign_keys='Recommendation.recommendation_from',
        backref='from_movie')

    # Statistics
    rating_sum = db.Column(db.Integer(), default=0)  # Sum of all ratings
    num_ratings = db.Column(db.Integer(),
                            default=0)  # Number of non-NULL ratings
    num_favourites = db.Column(db.Integer(), default=0)
    num_completed = db.Column(db.Integer(), default=0)
    num_ptw = db.Column(db.Integer(), default=0)
    num_custom = db.Column(db.Integer(), default=0)

    def add_completed_member(self, rating):
        self.num_completed += 1

        if rating:
            self.rating_sum += rating
            self.num_ratings += 1

    def remove_completed_member(self, rating):
        self.num_completed -= 1

        if rating:
            self.rating_sum -= rating
            self.num_ratings -= 1

    def add_ptw_member(self):
        self.num_ptw += 1

    def remove_ptw_member(self):
        self.num_ptw -= 1

    def get_movie_metadata(self):
        ret = dict()
        ret['title'] = self.title
        ret['status'] = self.status
        ret['budget'] = self.budget
        ret['imdb_id'] = self.imdb_id
        ret['revenue'] = self.revenue
        ret['backdrop_path'] = self.backdrop_path
        ret['poster_path'] = self.poster_path
        ret['adult'] = self.adult
        ret['orginal_language'] = self.original_language
        ret['overview'] = self.overview
        ret['release_date'] = self.release_date
        ret['runtime'] = self.runtime
        ret['tagline'] = self.tagline
        ret['homepage'] = self.homepage

        ret['genres'] = [g.genre for g in self.genres]
        ret['characters'] = [{
            'character_name': c.character_name,
            'actor_name': c.actor_name,
            'profile_path': c.profile_path,
            'actor_id': c.actor_id,
            'order': c.order
        } for c in self.characters]
        ret['videos'] = [{
            'site': v.site,
            'key': v.key,
            'type': v.type,
            'name': v.name
        } for v in self.videos]
        ret['countries'] = [c.name for c in self.countries]
        return ret

    def get_movie_statistics(self):
        ret = dict()
        ret['rating_sum'] = self.rating_sum
        ret['num_ratings'] = self.num_ratings
        ret['num_favourites'] = self.num_favourites
        ret['num_completed'] = self.num_completed
        ret['num_ptw'] = self.num_ptw
        ret['num_custom'] = self.num_custom
        return ret
コード例 #9
0
ファイル: user.py プロジェクト: jjmar/myflickslist
class User(db.Model):
    query_class = UserQuery
    search_vector = db.Column(TSVectorType('username'))

    # Account Specific
    id = db.Column(db.Integer(), primary_key=True)
    username = db.Column(db.String(64), unique=True, index=True)
    email = db.Column(db.String(128), unique=True)
    pw_hash = db.Column(db.String(128), nullable=False)
    verified = db.Column(db.Boolean(), default=False)

    # Profile Specific
    fav_genre = db.Column(db.String(64))
    join_date = db.Column(db.Date(), default=date.today)
    last_online = db.Column(db.DateTime(), default=datetime.utcnow)
    gender = db.Column(db.String(64))
    location = db.Column(db.String(64))
    website = db.Column(db.String(64))
    about = db.Column(db.String(256))
    profile_views = db.Column(db.Integer(), default=0)

    friends = db.relationship('Friendship',
                              primaryjoin=id == Friendship.user_id,
                              lazy='dynamic')  # M:M

    profile_comments = db.relationship('Comment',
                                       foreign_keys='Comment.host_id')  # 1:M
    posted_comments = db.relationship('Comment',
                                      foreign_keys='Comment.author_id',
                                      backref='author')  # 1:M

    flicks_list = db.relationship('FlicksList', backref='owner',
                                  uselist=False)  # 1:1
    favourites = db.relationship('Favourite')  # M:M
    custom_lists = db.relationship('CustomList', backref='owner')  # 1:M

    recommendations = db.relationship('Recommendation',
                                      backref='author')  # 1:M
    reviews = db.relationship('Review', backref='author')  # 1:M

    def __init__(self, **kwargs):
        super(User, self).__init__(**kwargs)
        self.flicks_list = FlicksList(name='Flickslist')

    @classmethod
    def verify_confirmation_token(cls, token):
        serializer = Serializer(current_app.config['SECRET_KEY'])

        try:
            data = serializer.loads(token)
            user_id = data.get('user_id_confirm')
        except:
            return None

        return User.query.get(user_id)

    @classmethod
    def verify_reset_password_token(cls, token):
        serializer = Serializer(current_app.config['SECRET_KEY'])

        try:
            data = serializer.loads(token)
            user_id = data.get('user_id_reset_pass')
        except:
            return None

        return User.query.get(user_id)

    def set_password(self, password):
        self.pw_hash = bcrypt.generate_password_hash(password).decode('utf-8')

    def verify_password(self, password):
        return bcrypt.check_password_hash(self.pw_hash, password)

    def generate_confirm_token(self):
        serializer = Serializer(
            current_app.config['SECRET_KEY'],
            expires_in=current_app.config['JWT_CONFIRM_TOKEN_EXPIRES'])
        return serializer.dumps({'user_id_confirm': self.id}).decode('utf-8')

    def generate_reset_password_token(self):
        serializer = Serializer(
            current_app.config['SECRET_KEY'],
            expires_in=current_app.config['JWT_RESET_PASS_TOKEN_EXPIRES'])
        return serializer.dumps({
            'user_id_reset_pass': self.id
        }).decode('utf-8')

    def add_friend(self, friend, active=0):
        self.friends.append(
            Friendship(user_id=self.id, friend_id=friend.id, active=active))
        db.session.commit()

    def remove_friend(self, friend):
        self.friends.remove(friend)
        friend.friends.remove(self)
        db.session.commit()