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


Python Film.get_user_seen_films方法代码示例

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


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

示例1: refill_tag_basket

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import get_user_seen_films [as 别名]
    def refill_tag_basket(cls, user, tag):

        TAG_BASKET_SIZE = getattr(settings, 'TAG_BASKET_SIZE')
        MIN_TAG_BASKET_SIZE = getattr(settings, 'MIN_TAG_BASKET_SIZE')
        try:
            lang = user.get_profile().LANG
        except AttributeError:
            lang = 'en'

        basket_key = cache.Key(cache.CACHE_TAG_BASKET, user, tag)
        tag_basket = cache.get(basket_key) or dict()

        if len(tag_basket) < MIN_TAG_BASKET_SIZE:
            # get films with this tag
            films_dict = Film.get_film_ids_by_tag(tag, lang)
            # get films seen by user
            seen_films = Film.get_user_seen_films(user)

            # remove films seen by user
            films_dict = dict([(k,v) for k,v in films_dict.items() if k not in seen_films])
            # how many we want to refill
            to_refill = TAG_BASKET_SIZE - len(tag_basket)
            # reverse sort by popularity
            sorted_films = sorted(films_dict, key=films_dict.get, reverse=True)[:to_refill]
            refill_dict = dict([(fid, films_dict[fid]) for fid in sorted_films])

            tag_basket.update(refill_dict)
            cache.set(basket_key, tag_basket, cache.A_MONTH)
开发者ID:thuvh,项目名称:filmmaster,代码行数:30,代码来源:rating_helper.py

示例2: test_get_user_seen_films

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import get_user_seen_films [as 别名]
    def test_get_user_seen_films(self):
        """ Tests storing rated and seen films in cache. """

        films = Film.objects.all()
        API_VERSION = "1.1"
        username = self.user.username
        put_url = "/api/" + API_VERSION + "/user/" + username + "/ratings/film/"

        # We rate movies and check if they were added to seen_films
        for film in films[:10]:
            film_put_url = put_url + film.permalink + "/" + str(Rating.TYPE_FILM) + "/"
            self.client.put(film_put_url, {'rating': 2})
            # We check if the film was added to user_seen_films
            seen_films = Film.get_user_seen_films(self.user)
            self.assertTrue(film.id in seen_films)

        # We mark movies as seen and check if they were added to seen_films
        for film in films[10:20]:
            film.mark_as_seen(self.user)
            # We check if the film was added to user_seen_films
            seen_films = Film.get_user_seen_films(self.user)
            self.assertTrue(film.id in seen_films)
开发者ID:thuvh,项目名称:filmmaster,代码行数:24,代码来源:test_rate_films.py

示例3: refill_user_basket

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import get_user_seen_films [as 别名]
    def refill_user_basket(cls, user):

        BASKET_SIZE = getattr(settings, 'RATE_BASKET_SIZE')
        MIN_BASKET_SIZE = getattr(settings, 'MIN_RATE_BASKET_SIZE')
        rating_basket_key = cache.Key(cache.CACHE_USER_BASKET, user)
        rating_basket = cache.get(rating_basket_key) or set()
        seen_films = Film.get_user_seen_films(user)
        if len(rating_basket) < MIN_BASKET_SIZE:
            while len(rating_basket) < BASKET_SIZE:
                size = len(rating_basket) # we will check if it changes
                for tag in settings.BASKETS_TAGS_LIST:
                    films = cls.get_from_tag_basket(user, tag, number_of_films=1)
                    if films and films[0] not in seen_films:
                        rating_basket.update(films) 
                # if the size hasn't changed
                if len(rating_basket) <= size:
                    break

            cache.set(rating_basket_key, rating_basket, cache.A_MONTH)
开发者ID:thuvh,项目名称:filmmaster,代码行数:21,代码来源:rating_helper.py


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