当前位置: 首页>>代码示例>>Python>>正文


Python Film._rated_film_ids方法代码示例

本文整理汇总了Python中film20.core.models.Film._rated_film_ids方法的典型用法代码示例。如果您正苦于以下问题:Python Film._rated_film_ids方法的具体用法?Python Film._rated_film_ids怎么用?Python Film._rated_film_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在film20.core.models.Film的用法示例。


在下文中一共展示了Film._rated_film_ids方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: user_recommendations

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import _rated_film_ids [as 别名]
def user_recommendations(user, films, with_rated=False, order_by=None):
    film_ids = [f.id for f in films]

    if user and user.is_authenticated():
        profile = user.get_profile()
        basket = BasketItem.user_basket(user)
        rated_ids = Film._rated_film_ids(user)
        if profile.recommendations_status in (profile.NORMAL_RECOMMENDATIONS, profile.FAST_RECOMMENDATIONS):
            recommendations = _user_film_recommendations(user, film_ids)
        else:
            recommendations = {}

        for f in films:
            r = recommendations.get(f.id)
            b = basket.get(f.id)
            f._rated = f.id in rated_ids
            f._guess_rating = r or 0
            f._on_wishlist = b and b[0] and (b[0] != BasketItem.NOT_INTERESTED) or False
            f._on_shitlist = b and (b[0] == BasketItem.NOT_INTERESTED) or False
    else:
        for f in films:
            f._rated = False
            f._guess_rating = 0
            f._on_wishlist = False
            f._on_shitlist = False

    test_with_rated = lambda f: with_rated or not f._rated

    films = list(f for f in films if not f._on_shitlist and test_with_rated(f))

    comparator = create_film_comparator(order_by)
    return sorted(films, cmp=comparator)
开发者ID:thuvh,项目名称:filmmaster,代码行数:34,代码来源:showtimes_helper.py

示例2: _get_recommendations

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import _rated_film_ids [as 别名]
    def _get_recommendations(self):
        self.films = set()
        film_ids = []

        for film_set in self.film_sets:
            for f in film_set.values():
                if not f in self.films and f.has_screenings(self.channel_ids, self.since):
                    self.films.add(f)
                    if f.film_id:
                        film_ids.append(f.film_id)

        if self.user and self.user.is_authenticated():
            profile = self.user.get_profile()
            basket = BasketItem.user_basket(self.user)
            rated_ids = Film._rated_film_ids(self.user)
            if profile.recommendations_status in (profile.NORMAL_RECOMMENDATIONS, profile.FAST_RECOMMENDATIONS):
                recommendations = recommendations_engine.compute_guess_score_for_films(self.user, film_ids)
            else:
                recommendations = {}

            for f in self.films:
                if not f.film_id:
                    continue
                r = recommendations.get(f.film_id)
                b = basket.get(f.film_id)
                f._rated = f.film_id in rated_ids
                f._guess_rating = r or 0
                f._on_wishlist = b and b[0] and (b[0] != BasketItem.NOT_INTERESTED) or False
                f._on_shitlist = b and (b[0] == BasketItem.NOT_INTERESTED) or False

        test_with_rated = lambda f: self.with_rated or not f._rated
        test_unmatched = lambda f: not self.without_unmatched or f.film_id

        films = list(f for f in self.films if not f._on_shitlist and test_with_rated(f) and test_unmatched(f))

        comparator = create_film_comparator(self.order_by)
        return sorted(films, cmp=comparator)
开发者ID:,项目名称:,代码行数:39,代码来源:


注:本文中的film20.core.models.Film._rated_film_ids方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。