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


Python Result.message方法代码示例

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


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

示例1: post

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import message [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

示例2: isUnique

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

示例4: filterObjects

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import message [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 message [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 message [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 message [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: post

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import message [as 别名]
def post(request):
    """ Create a Gallery """
    defaultname = 'New Gallery %i' % Gallery.objects.all().count()
    data = request.POST or json.loads(request.body)['body']
    title = data.get('title', defaultname)
    description = data.get('description', '')
    security = int(data.get('security', Gallery.PUBLIC))

    g, created = Gallery.objects.get_or_create(title=title)
    g.security = security
    g.description = description
    g.owner = request.user
    g.save()

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

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

示例9: put

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import message [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 message [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 message [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

示例12: _filter

# 需要导入模块: from frog.common import Result [as 别名]
# 或者: from frog.common.Result import message [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


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