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


Python common.Result类代码示例

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


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

示例1: userList

def userList(request):
    res = Result()

    for user in User.objects.filter(is_active=True).order_by('first_name'):
        res.append(userToJson(user))

    return JsonResponse(res.asDict())
开发者ID:theiviaxx,项目名称:Frog,代码行数:7,代码来源:__init__.py

示例2: csrf

def csrf(request):
    res = Result()
    try:
        res.append(request.COOKIES['csrftoken'])
    except KeyError:
        pass
    return JsonResponse(res.asDict())
开发者ID:theiviaxx,项目名称:Frog,代码行数:7,代码来源:__init__.py

示例3: switchArtist

def switchArtist(request):
    data = request.POST or json.loads(request.body)['body']
    artist = data.get('artist', None)
    guids = data.get('guids', '').split(',')

    res = Result()
    if artist:
        if isinstance(artist, int):
            author = User.objects.get(pk=artist)
            tag = Tag.objects.get_or_create(name=author.get_full_name().lower(), defaults={'artist': True})[0]
        else:
            first, last = artist.lower().split(' ')
            author = User.objects.get_or_create(first_name=first, last_name=last, defaults={
                'username': '%s%s' % (first[0], last),
            })[0]
            tag = Tag.objects.get_or_create(name=artist.lower(), defaults={'artist': True})[0]

        objects = getObjectsFromGuids(guids)
        for n in objects:
            n.author = author
            n.tagArtist(tag)

        res.append(userToJson(author))
        res.value['tag'] = tag.id

    return JsonResponse(res.asDict())
开发者ID:theiviaxx,项目名称:Frog,代码行数:26,代码来源:__init__.py

示例4: isUnique

def isUnique(request):
    path = request.GET.get('path', None)
    res = Result()
    if path:
        if request.user.is_anonymous():
            username = request.GET.get('user', 'noauthor')
            user = User.objects.get(username=username)
        else:
            user = request.user
        
        uniqueID = Piece.getUniqueID(path, user)

        img = Image.objects.filter(unique_id=uniqueID)
        vid = Video.objects.filter(unique_id=uniqueID)
        if img:
            res.append(img[0].json())
        elif vid:
            res.append(vid[0].json())
        else:
            res.append(True)

        res.isSuccess = True
    else:
        res.isError = True
        res.message = "No path provided"

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

示例5: put

def put(request, obj_id=None):
    """ Adds Image and Video objects to Gallery based on GUIDs """
    guids = filter(None, request.PUT.get('guids', '').split(','))
    security = request.PUT.get('security')
    object_ = Gallery.objects.get(pk=obj_id)
    
    if guids:
        objects = getObjectsFromGuids(guids)

        images = filter(lambda x: isinstance(x, Image), objects)
        videos = filter(lambda x: isinstance(x, Video), objects)

        object_.images.add(*images)
        object_.videos.add(*videos)
    
    if security is not None:
        object_.security = json.loads(security)
        object_.save()
        for child in object_.gallery_set.all():
            child.security = object_.security
            child.save()

    res = Result()
    res.append(object_.json())
    res.isSuccess = True

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

示例6: post

def post(request):
    """ Create a Gallery """
    defaultname = 'New Gallery %i' % Gallery.objects.all().count()
    title = request.POST.get('title', defaultname)
    description = request.POST.get('description', '')
    security = int(request.POST.get('security', Gallery.PUBLIC))
    parentid = request.POST.get('parent')
    if parentid:
        parent = Gallery.objects.get(pk=int(parentid))
        g, created = parent.gallery_set.get_or_create(title=title)
        g.security = parent.security
    else:
        g, created = Gallery.objects.get_or_create(title=title)
        g.security = security

    g.description = description
    g.owner = request.user
    g.save()

    res = Result()
    res.isSuccess = True
    res.append(g.json())
    res.message = 'Gallery created' if created else ''

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

示例7: filterObjects

def filterObjects(request, obj_id):
    """
    Filters Gallery for the requested ImageVideo objects.  Returns a Result object with 
    serialized objects
    """
    print obj_id
    obj = Gallery.objects.get(pk=obj_id)

    if request.user.is_anonymous() and obj.security != Gallery.PUBLIC:
        res = Result()
        res.isError = True
        res.message = 'This gallery is not public'

        return JsonResponse(res)

    
    tags = json.loads(request.GET.get('filters', '[[]]'))
    rng = request.GET.get('rng', None)
    more = json.loads(request.GET.get('more', 'false'))
    models = request.GET.get('models', 'image,video')
    if models == '':
        models = 'image,video'

    tags = filter(None, tags)

    models = [ContentType.objects.get(app_label='frog', model=x) for x in models.split(',')]

    return _filter(request, obj, tags=tags, rng=rng, models=models, more=more)
开发者ID:davideilering,项目名称:Frog,代码行数:28,代码来源:gallery.py

示例8: delete

def delete(request, obj_id=None):
    """Removes tags from objects resolved from guids

    :param tags: Tags to remove
    :type tags: list
    :param guids: Guids to remove tags from
    :type guids: list
    :returns: json
    """
    res = Result()

    if obj_id:
        # -- Delete the tag itself
        tag = Tag.objects.get(pk=obj_id)
        guids = []
        images = Image.objects.filter(tags__id=obj_id)
        guids += [_.guid for _ in images]
        videos = Video.objects.filter(tags__id=obj_id)
        guids += [_.guid for _ in videos]
        # -- Remove all tags from objects
        _manageTags([tag.id], guids, add=False)
        # -- Delete old tags
        tag.delete()
    else:
        tags = [_ for _ in request.DELETE.get('tags', '').split(',') if _]
        guids = [_ for _ in request.DELETE.get('guids', '').split(',') if _]

        _manageTags(tags, guids, add=False)

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

示例9: put

def put(request, obj_id=None):
    """ Adds Image and Video objects to Gallery based on GUIDs """
    data = request.PUT or json.loads(request.body)['body']
    guids = data.get('guids', '').split(',')
    move = data.get('from')
    security = request.PUT.get('security')
    gallery = Gallery.objects.get(pk=obj_id)
    
    if guids:
        objects = getObjectsFromGuids(guids)

        images = filter(lambda x: isinstance(x, Image), objects)
        videos = filter(lambda x: isinstance(x, Video), objects)

        gallery.images.add(*images)
        gallery.videos.add(*videos)

        if move:
            fromgallery = Gallery.objects.get(pk=move)
            fromgallery.images.remove(*images)
            fromgallery.videos.remove(*videos)
    
    if security is not None:
        gallery.security = json.loads(security)
        gallery.save()
        for child in gallery.gallery_set.all():
            child.security = gallery.security
            child.save()

    res = Result()
    res.append(gallery.json())

    return JsonResponse(res.asDict())
开发者ID:theiviaxx,项目名称:Frog,代码行数:33,代码来源:gallery.py

示例10: post

def post(request):
    """Sets a key to a value on the currently logged in users preferences

    :param key: Key to set
    :type key: str
    :param val: Value to set
    :type val: primitive
    :returns: json
    """
    data = request.POST or json.loads(request.body)['body']
    key = data.get('key', None)
    val = data.get('val', None)
    res = Result()
    if key is not None and val is not None:
        obj, created = UserPref.objects.get_or_create(user=request.user)
        if created:
            obj.data = json.dumps(DefaultPrefs.copy())
            obj.save()
        try:
            val = json.loads(val)
        except (TypeError, ValueError):
            pass
        obj.setKey(key, val)
        obj.save()
        res.append(obj.json())

    return JsonResponse(res.asDict())
开发者ID:theiviaxx,项目名称:Frog,代码行数:27,代码来源:userpref.py

示例11: delete

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,代码行数:8,代码来源:piece.py

示例12: get

def get(request, obj_id=None):
    """Lists all tags

    :returns: json
    """
    res = Result()
    if obj_id:
        if obj_id == '0':
            obj = {
                'id': 0,
                'name': 'TAGLESS',
                'artist': False,
            }
        else:
            obj = get_object_or_404(Tag, pk=obj_id).json()

        res.append(obj)
        return JsonResponse(res.asDict())
    else:
        if request.GET.get('count'):
            itags = Tag.objects.all().annotate(icount=Count('image'))
            vtags = Tag.objects.all().annotate(vcount=Count('video'))

            for i, tag in enumerate(itags):
                tag.count = itags[i].icount + vtags[i].vcount
                res.append(tag.json())
        else:
            for tag in Tag.objects.all():
                res.append(tag.json())

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

示例13: manage

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,代码行数:54,代码来源:tag.py

示例14: artistLookup

def artistLookup(request):
    res = Result()
    query = request.GET.get('query', False)
    if query:
        users = User.objects.filter(first_name__icontains=query.lower())
    else:
        users = User.objects.all()

    for user in users:
        res.append(userToJson(user))

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

示例15: releaseNotes

def releaseNotes(request):
    res = Result()
    lastid = request.GET.get('lastid', 0)
    today = datetime.datetime.today()
    relevent = today - datetime.timedelta(days=30)

    notes = ReleaseNotes.objects.filter(date__gte=relevent, pk__gt=lastid).order_by('-id')

    for note in notes:
        res.append(note.json())

    return JsonResponse(res.asDict())
开发者ID:theiviaxx,项目名称:Frog,代码行数:12,代码来源:__init__.py


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