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


Python Result.isError方法代码示例

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


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

示例1: getUser

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import isError [as 别名]
def getUser(request):
    res = Result()
    data = {}
    if request.user.is_anonymous():
        res.isError = True
        data['prefs'] = DefaultPrefs
    elif request.GET.get('q'):
        return JsonResponse(res.asDict())
    else:
        data['user'] = userToJson(request.user)
        data['user']['isManager'] = any(request.user.groups.filter(name='manager')) or request.user.is_staff
        data['gallery'] = None
        personal = Gallery.objects.filter(owner=request.user, security=Gallery.PERSONAL)
        if personal:
            data['personal_gallery'] = personal[0].json()
        data['prefs'] = request.user.frog_prefs.get_or_create(user=request.user)[0].json()
        galleryid = request.GET.get('gallery')
        if galleryid is not None:
            gallery = Gallery.objects.filter(pk=galleryid, owner=request.user)
            if gallery:
                data['gallery'] = gallery[0].json()

    res.append(data)

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

示例2: isUnique

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import isError [as 别名]
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,代码行数:29,代码来源:__init__.py

示例3: post

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import isError [as 别名]
def post(request):
    """Creates a tag object

    :param name: Name for tag
    :type name: str
    :returns: json
    """
    res = Result()
    name = request.POST.get("name", None)

    if not name:
        res.isError = True
        res.message = "No name given"

        return JsonResponse(res)

    tag, created = Tag.objects.get_or_create(name=name)

    res.isSuccess = True
    if created:
        res.message = "Created"

    res.append(tag.json())

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

示例4: filterObjects

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import isError [as 别名]
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,代码行数:30,代码来源:gallery.py

示例5: post

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import isError [as 别名]
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
    """
    key = request.POST.get('key', None)
    val = request.POST.get('val', None)
    res = Result()
    if key and val:
        obj, created = UserPref.objects.get_or_create(user=request.user)
        if created:
            obj.data = json.dumps(DefaultPrefs.copy())
            obj.save()
        val = json.loads(val)
        obj.setKey(key, val)
        obj.save()
        res.append(obj.json())
        res.isSuccess = True
    else:
        res.isError = True
        res.message = 'No key and value provided'

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

示例6: post

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import isError [as 别名]
def post(request):
    """Returns a serialized object
    :param obj_id: ID of comment object
    :type obj_id: int
    :returns: json
    """
    guid = request.POST.get('guid', None)
    res = Result()   

    if guid:
        obj = getObjectsFromGuids([guid,])[0]
        c = Comment()
        c.comment = request.POST.get('comment', 'No comment')
        c.user = request.user
        c.user_name = request.user.get_full_name()
        c.user_email = request.user.email
        c.content_object = obj
        c.site_id = 1
        c.save()
        obj.comment_count = obj.comment_count + 1
        obj.save()

        __email(c, obj)

        res.append({'id': c.id, 'comment': c.comment})
        res.isSuccess = True
    else:
        res.isError = True
        res.message = "No guid provided"

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

示例7: login_

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import isError [as 别名]
def login_(request):
    data = request.POST or json.loads(request.body)['body']
    email = data['email'].lower()
    password = data.get('password')
    result = Result()
    user = None

    if email:
        user = authenticate(username=email, password=password)
    else:
        result.message = 'Please enter an email address'
        result.isError = True

    if user:
        first_name = request.POST.get('first_name')
        last_name = request.POST.get('last_name')
        if first_name:
            user.first_name = first_name
        if last_name:
            user.last_name = last_name

        if not user.is_active:
            result.message = 'User account not active'
            result.isError = True
    else:
        result.message = 'Invalid Credentials'
        result.isError = True

    if result.isError:
        return JsonResponse(result.asDict())

    login(request, user)

    # -- Create an artist tag for them
    Tag.objects.get_or_create(
        name=user.get_full_name(),
        defaults={'artist': True}
    )

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

示例8: getUser

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import isError [as 别名]
def getUser(request):
    res = Result()
    if request.user.is_anonymous():
        res.isError = True
        res.append(DefaultPrefs)
    else:
        galleryid = request.GET.get('gallery')
        if galleryid is not None:
            gallery = Gallery.objects.filter(pk=galleryid, owner=request.user)
            if gallery:
                res.append(gallery[0].json())
        res.isSuccess = True

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

示例9: put

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import isError [as 别名]
def put(request, obj_id):
    """Updates the content of a comment
    :param obj_id: ID of comment object
    :type obj_id: int
    :returns: json
    """
    res = Result()
    c = Comment.objects.get(pk=obj_id)
    content = request.PUT.get('comment', None)
    if content:
        c.comment = content
        c.save()

        res.append(commentToJson(c))
        res.isSuccess = True
    else:
        res.isError = True
        res.message = "No comment provided"

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

示例10: switchArtist

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import isError [as 别名]
def switchArtist(request):
    artist = request.POST.get('artist', None)
    guids = request.POST.get('guids', '').split(',')
    res = Result()
    if artist:
        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.isSuccess = True
        res.append(userToJson(author))
        res.value['tag'] = Tag.objects.get(name=artist.lower()).id
    else:
        res.isError = True
        res.message = "No artist provided"

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

示例11: upload

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import isError [as 别名]
def upload(request):
    res = Result()
    uploadfile = request.FILES.get('file')

    if uploadfile:
        filename = uploadfile.name

        path = request.POST.get('path', None)
        if path:
            foreignPath = path.replace("'", "\"")
        else:
            foreignPath = filename

        galleries = request.POST.get('galleries', '1').split(',')
        tags = [_.strip() for _ in request.POST.get('tags', '').split(',') if _]
        title = request.POST.get('title')

        try:
            username = request.POST.get('user', False)
            if username:
                user = User.objects.get(username=username)
            else:
                user = request.user
            
            uniqueName = request.POST.get('uid', models.Piece.getUniqueID(foreignPath, user))

            if galleries and models.Gallery.objects.filter(pk__in=[int(g) for g in galleries], uploads=False):
                raise PermissionDenied()

            extension = Path(filename).ext.lower()
            if extension in models.FILE_TYPES['image']:
                model = models.Image
            elif extension in models.FILE_TYPES['video']:
                model = models.Video
            else:
                raise MediaTypeError('{} is not a supported file type'.format(extension))

            obj, created = model.objects.get_or_create(unique_id=uniqueName, defaults={'author': user})
            guid = obj.getGuid()
            hashVal = getHashForFile(uploadfile)

            if hashVal == obj.hash:
                for gal in galleries:
                    g = models.Gallery.objects.get(pk=int(gal))
                    obj.gallery_set.add(g)
                res.append(obj.json())
                res.message = "Files were the same"

                return JsonResponse(res.asDict())

            objPath = models.ROOT
            if models.FROG_PATH:
                objPath = objPath / models.FROG_PATH
            objPath = objPath / guid.guid[-2:] / guid.guid / filename
            
            hashPath = objPath.parent / hashVal + objPath.ext
            
            if not objPath.parent.exists():
                objPath.parent.makedirs()

            handle_uploaded_file(hashPath, uploadfile)

            obj.hash = hashVal
            obj.foreign_path = foreignPath
            obj.title = title or objPath.namebase
            obj.export(hashVal, hashPath, tags=tags, galleries=galleries)

            res.append(obj.json())

            for key, uploadfile in request.FILES.items():
                if key != 'file':
                    dest = objPath.parent / uploadfile.name
                    handle_uploaded_file(dest, uploadfile)

        except MediaTypeError as err:
            res.isError = True
            res.message = str(err)
            
            return JsonResponse(res.asDict())

    else:
        res.isError = True
        res.message = "No file found"

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


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