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


Python Collection.get_recs_from_ids方法代码示例

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


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

示例1: recommendations

# 需要导入模块: from bandwagon.models import Collection [as 别名]
# 或者: from bandwagon.models.Collection import get_recs_from_ids [as 别名]
def recommendations(request, version, platform, limit=9):
    """
    Figure out recommended add-ons for an anonymous user based on POSTed guids.

    POST body looks like {"guids": [...]} with an optional "token" key if
    they've been here before.
    """
    try:
        POST = json.loads(request.raw_post_data)
        guids = POST['guids']
    except (ValueError, TypeError, KeyError):
        # Errors: invalid json, didn't get a dict, didn't find "guids".
        return http.HttpResponseBadRequest()

    addon_ids = get_addon_ids(guids)
    index = Collection.make_index(addon_ids)

    ids, recs = Collection.get_recs_from_ids(addon_ids, request.APP, version)
    recs = _recommendations(request, version, platform, limit,
                            index, ids, recs)

    # We're only storing a percentage of the collections we see because the db
    # can't keep up with 100%.
    if not waffle.sample_is_active('disco-pane-store-collections'):
        return recs

    # Users have a token2 if they've been here before. The token matches
    # addon_index in their SyncedCollection.
    if 'token2' in POST:
        token = POST['token2']
        if token == index:
            # We've seen them before and their add-ons have not changed.
            return recs
        elif token != index:
            # We've seen them before and their add-ons changed. Remove the
            # reference to their old synced collection.
            (SyncedCollection.objects.filter(addon_index=index)
             .update(count=F('count') - 1))

    # Try to create the SyncedCollection. There's a unique constraint on
    # addon_index so it will fail if this addon_index already exists. If we
    # checked for existence first and then created a collection there would
    # be a race condition between multiple users with the same addon_index.
    try:
        c = SyncedCollection.objects.create(addon_index=index, count=1)
        c.set_addons(addon_ids)
    except IntegrityError:
        try:
            (SyncedCollection.objects.filter(addon_index=index)
             .update(count=F('count') + 1))
        except Exception, e:
            log.error(u'Could not count++ "%s" (%s).' % (index, e))
开发者ID:ricardodani,项目名称:zamboni,代码行数:54,代码来源:views.py

示例2: get_compat_mode

# 需要导入模块: from bandwagon.models import Collection [as 别名]
# 或者: from bandwagon.models.Collection import get_recs_from_ids [as 别名]
    """
    if not compat_mode:
        compat_mode = get_compat_mode(version)

    try:
        POST = json.loads(request.raw_post_data)
        guids = POST['guids']
    except (ValueError, TypeError, KeyError), e:
        # Errors: invalid json, didn't get a dict, didn't find "guids".
        log.debug('Recommendations return 405 because: %s' % e)
        return http.HttpResponseBadRequest()

    addon_ids = get_addon_ids(guids)
    index = Collection.make_index(addon_ids)

    ids, recs = Collection.get_recs_from_ids(addon_ids, request.APP, version,
                                             compat_mode)
    recs = _recommendations(request, version, platform, limit, index, ids,
                            recs, compat_mode)

    # We're only storing a percentage of the collections we see because the db
    # can't keep up with 100%.
    if not waffle.sample_is_active('disco-pane-store-collections'):
        return recs

    # Users have a token2 if they've been here before. The token matches
    # addon_index in their SyncedCollection.
    if 'token2' in POST:
        token = POST['token2']
        if token == index:
            # We've seen them before and their add-ons have not changed.
            return recs
开发者ID:sjhewitt,项目名称:zamboni,代码行数:34,代码来源:views.py


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