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


Python File.key_data方法代码示例

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


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

示例1: multiuploader

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import key_data [as 别名]
def multiuploader(request):
    """
    Main Multiuploader module.
    Parses data from jQuery plugin and makes database changes.
    """
    if request.method == 'POST':
        log.info('received POST to main multiuploader view')
        if request.FILES == None:
            return HttpResponseBadRequest('Must have files attached!')

        #getting file data for farther manipulations
        file = request.FILES[u'files[]']
        wrapped_file = UploadedFile(file)
        filename = wrapped_file.name
        file_size = wrapped_file.file.size
        log.info ('Got file: "%s"' % filename)

        #writing file manually into model
        #because we don't need form of any type.
        image = File()
        image.filename= filename
        image.image=file
        image.key_data = image.key_generate
        image.save()
        log.info('File saving done')

        #settings imports
        try:
            file_delete_url = settings.MULTI_FILE_DELETE_URL+'/'
            # file_url = settings.MULTI_IMAGE_URL+'/'+image.key_data+'/'
        except AttributeError:
            file_delete_url = 'multi_delete/'
            # file_url = 'multi_image/'+image.key_data+'/'

        file_url = image.image.url;

        #generating json response array
        result = []
        context = {"name":filename, 
            "size":file_size, 
            "url":file_url,
            "file_id": image.id,
            "delete_url":file_delete_url+str(image.pk)+'/', 
            "delete_type":"POST",
        }
        #getting thumbnail url using sorl-thumbnail
        print image.is_image
        if image.is_image:
            im = get_thumbnail(image, "80x80", quality=50)
            context['thumbnail_url'] = im.url

        result.append(context)
        response_data = simplejson.dumps(result)
        
        #checking for json data type
        #big thanks to Guy Shapiro
        if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
            mimetype = 'application/json'
        else:
            mimetype = 'text/plain'
        return HttpResponse(response_data, mimetype=mimetype)
    else: #GET
        return HttpResponse('Only POST accepted')
开发者ID:matheussl,项目名称:django_multiuploader,代码行数:65,代码来源:views.py


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