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


Python Result.value方法代码示例

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


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

示例1: delete

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import value [as 别名]
def delete(self, request, obj):
    obj.deleted = True
    obj.save()
    res = Result()
    res.isSuccess = True
    res.value = obj.json()

    return JsonResponse(res)
开发者ID:davideilering,项目名称:Frog,代码行数:10,代码来源:piece.py

示例2: manage

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import value [as 别名]
def manage(request):
    if request.method == "GET":
        guids = request.GET.get("guids", "").split(",")
        guids = filter(None, guids)

        objects = getObjectsFromGuids(guids)
        ids = [o.id for o in objects]

        imgtags = list(Tag.objects.filter(image__id__in=ids).exclude(artist=True))
        vidtags = list(Tag.objects.filter(video__id__in=ids).exclude(artist=True))
        tags = list(set(imgtags + vidtags))

        if request.GET.get("json", False):
            res = Result()
            data = {"queries": connection.queries}

            res.value = data

            res.isSuccess = True

            return JsonResponse(res)

        return render(request, "frog/tag_manage.html", {"tags": tags})
    else:
        add = request.POST.get("add", "").split(",")
        rem = request.POST.get("rem", "").split(",")
        guids = request.POST.get("guids", "").split(",")

        add = filter(None, add)
        rem = filter(None, rem)
        addList = []

        for t in add:
            try:
                addList.append(int(t))
            except ValueError:
                tag, created = Tag.objects.get_or_create(name=t)
                tag.save()
                addList.append(tag.id)

        objects = getObjectsFromGuids(guids)
        addTags = Tag.objects.filter(id__in=addList)
        remTags = Tag.objects.filter(id__in=rem)

        for o in objects:
            for a in addTags:
                o.tags.add(a)
            for r in remTags:
                o.tags.remove(r)

        res = Result()
        res.isSuccess = True

        return JsonResponse(res)
开发者ID:nickryand,项目名称:Frog,代码行数:56,代码来源:tag.py

示例3: _filter

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import value [as 别名]
def _filter(request, object_, tags=None, models=(Image, Video), rng=None, more=False):
    """Filters Piece objects from self based on filters, search, and range

    :param tags: List of tag IDs to filter
    :type tags: list
    :param models: List of model classes to filter on
    :type models: list
    :param rng: Range of objects to return. i.e. 0:100
    :type rng: str
    :param more -- bool, Returns more of the same filtered set of images based on session range

    return list, Objects filtered
    """
    
    NOW = time.clock()

    res = Result()
    
    idDict = {}
    objDict = {}
    lastIDs = {}
    data = {}

    LOGGER.debug('init: %f' % (time.clock() - NOW))
    if request.user.is_anonymous():
        gRange = 300
    else:
        Prefs = json.loads(UserPref.objects.get(user=request.user).data)
        gRange = Prefs['batchSize']
    request.session.setdefault('frog_range', '0:%i' % gRange)

    if rng:
        s, e = [int(x) for x in rng.split(':')]
    else:
        if more:
            s = int(request.session.get('frog_range', '0:%i' % gRange).split(':')[1])
            e = s + gRange
            s, e = 0, gRange
        else:
            s, e = 0, gRange

    ## -- Gat all IDs for each model
    for m in models:
        indexes = list(m.model_class().objects.all().values_list('id', flat=True))
        if not indexes:
            continue

        lastIndex = indexes[0]
        if more:
            ## -- This is a request for more results
            idx = request.session.get('last_%s_id' % m.model, lastIndex + 1)
            lastIDs.setdefault('last_%s_id' % m.model, idx)
        else:
            lastIDs['last_%s_id' % m.model] = lastIndex + 1
        
        ## -- Start with objects within range
        idDict[m.model] = m.model_class().objects.filter(gallery=object_, id__lt=lastIDs['last_%s_id' % m.model])
        LOGGER.debug(m.model + '_initial_query: %f' % (time.clock() - NOW))

        if tags:
            for bucket in tags:
                searchQuery = ""
                o = None
                for item in bucket:
                    ## -- filter by tag
                    if isinstance(item, int) or isinstance(item, long):
                        if not o:
                            o = Q()
                        o |= Q(tags__id=item)
                    ## -- add to search string
                    else:
                        searchQuery += item + ' '
                        if not HAYSTACK:
                            if not o:
                                o = Q()
                            ## -- use a basic search
                            LOGGER.debug('search From LIKE')
                            o |= Q(title__icontains=item)
                if HAYSTACK and searchQuery != "":
                    ## -- once all tags have been filtered, filter by search
                    searchIDs = search(searchQuery, m.model_class())
                    if searchIDs:
                        if not o:
                            o = Q()
                        LOGGER.debug('searchFrom haystack:' + str(searchIDs))
                        o |= Q(id__in=searchIDs)

                if o:
                    ## -- apply the filters
                    idDict[m.model] = idDict[m.model].filter(o)
                else:
                    idDict[m.model] = idDict[m.model].none()

            LOGGER.debug(m.model + '_added_buckets(%i): %f' % (len(tags), time.clock() - NOW))
        
        ## -- Get all ids of filtered objects, this will be a very fast query
        idDict[m.model] = list(idDict[m.model].values_list('id', flat=True))
        LOGGER.debug(m.model + '_queried_ids: %f' % (time.clock() - NOW))

        res.message = str(s) + ':' + str(e)
#.........这里部分代码省略.........
开发者ID:davideilering,项目名称:Frog,代码行数:103,代码来源:gallery.py

示例4: _filter

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import value [as 别名]
def _filter(request, object_, tags=None, more=False, orderby='created'):
    """Filters Piece objects from self based on filters, search, and range

    :param tags: List of tag IDs to filter
    :type tags: list
    :param more -- bool, Returns more of the same filtered set of images based on session range

    return list, Objects filtered
    """
    res = Result()

    models = QUERY_MODELS

    idDict = {}
    objDict = {}
    data = {}
    modelmap = {}
    length = 75

    # -- Get all IDs for each model
    for m in models:
        modelmap[m.model_class()] = m.model

        if object_:
            idDict[m.model] = m.model_class().objects.filter(gallery=object_)
        else:
            idDict[m.model] = m.model_class().objects.all()

        if idDict[m.model] is None:
            continue

        if tags:
            for bucket in tags:
                searchQuery = ""
                o = None
                for item in bucket:
                    if item == 0:
                        # -- filter by tagless
                        idDict[m.model].annotate(num_tags=Count('tags'))
                        if not o:
                            o = Q()
                        o |= Q(num_tags__lte=1)
                        break
                    elif isinstance(item, six.integer_types):
                        # -- filter by tag
                        if not o:
                            o = Q()
                        o |= Q(tags__id=item)
                    else:
                        # -- add to search string
                        searchQuery += item + ' '
                        if not HAYSTACK:
                            if not o:
                                o = Q()
                            # -- use a basic search
                            o |= Q(title__icontains=item)

                if HAYSTACK and searchQuery != "":
                    # -- once all tags have been filtered, filter by search
                    searchIDs = search(searchQuery, m.model_class())
                    if searchIDs:
                        if not o:
                            o = Q()
                        o |= Q(id__in=searchIDs)

                if o:
                    # -- apply the filters
                    idDict[m.model] = idDict[m.model].annotate(num_tags=Count('tags')).filter(o)
                else:
                    idDict[m.model] = idDict[m.model].none()

        # -- Get all ids of filtered objects, this will be a very fast query
        idDict[m.model] = list(idDict[m.model].order_by('-{}'.format(orderby)).values_list('id', flat=True))
        lastid = request.session.get('last_{}'.format(m.model), 0)
        if not idDict[m.model]:
            continue

        if not more:
            lastid = idDict[m.model][0]

        index = idDict[m.model].index(lastid)
        if more and lastid != 0:
            index += 1
        idDict[m.model] = idDict[m.model][index:index + length]

        # -- perform the main query to retrieve the objects we want
        objDict[m.model] = m.model_class().objects.filter(id__in=idDict[m.model])
        objDict[m.model] = objDict[m.model].select_related('author').prefetch_related('tags').order_by('-{}'.format(orderby))
        objDict[m.model] = list(objDict[m.model])

        # -- combine and sort all objects by date
    objects = _sortObjects(orderby, **objDict) if len(models) > 1 else objDict.values()[0]
    objects = objects[:length]

    # -- Find out last ids
    lastids = {}
    for obj in objects:
        lastids['last_{}'.format(modelmap[obj.__class__])] = obj.id

    for key, value in lastids.items():
#.........这里部分代码省略.........
开发者ID:theiviaxx,项目名称:Frog,代码行数:103,代码来源:gallery.py


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