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


Python File.filename方法代码示例

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


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

示例1: upload

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import filename [as 别名]
def upload(request):
    if request.POST:
        userid = request.POST.get('userid')
        
        # Queries all non-expired sessions
        sessions = Session.objects.filter(expire_date__gte=datetime.now())

        # Checks if session is active
        for session in sessions:
            data = session.get_decoded()
            found_userid=data.get('_auth_user_id')

            # Prceeds when user id is validated
            if found_userid!=None and long(userid)==found_userid:
                user = User.objects.filter(id=userid)[0]
                faculty=None
                faculty=Faculty.objects.filter(id=request.POST.get('fid'))[0]
                transaction = Transaction.objects.get(id=request.POST.get('transaction'))
                document = Dokument()
                document.faculty= faculty
                document.transaction= transaction
                document.save()

                #Generates a random alphanum string for filename template
                while True:
                    fnameTemplate=''
                    fnameTemplate = ''.join(random.choice(string.ascii_lowercase))
                    fnameTemplate += ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(4)) + '_'
                    if len(File.objects.filter(filename__startswith = fnameTemplate))==0: break

                #Processes uploaded files, page by page
                for key in request.FILES:
                    files = request.FILES[key]
                    filename = fnameTemplate + key.split('_')[1] + '.bmp'
                    with open('DCSArchivingSystem/testapp/media/files/' + filename, 'wb+') as destination:
                        for chunk in files.chunks():
                            destination.write(chunk)
                        file = File()
                        file.filename = filename
                        file.file = 'files/' + filename
                        file.save()                    
                        document.files.add(file)
                    Log.create(user, "Uploaded file", file, document).save()    
                Log.create(user, "Created Document", None, document).save()    
                return HttpResponseRedirect("/dashboard/")
            
    else:
        return render_to_response('upload.html', context_instance=RequestContext(request))
开发者ID:mariciabalayan,项目名称:DCS_Archiving_System2,代码行数:50,代码来源:views.py

示例2: upload

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import filename [as 别名]
def upload(request, name):
    if request.method == 'POST':
        if request.FILES is None:
            return HttpResponseBadRequest('No file[] found')

        file = request.FILES[u'files[]']
        wrapped_file = UploadedFile(file)
        filename = wrapped_file.name
        file_size = wrapped_file.file.size

        entry = File()
        entry.filename = unicode(filename)
        entry.username = unicode(name)
        entry.size = file_size
        entry.slug = generate_slug(8)
        entry.data = file
        entry.save()

        uploaded = [{'name': filename, 'size': filesizeformat(file_size), 'slug': entry.slug,
                     'date': entry.created.date().isoformat()}]

        return HttpResponse(json.dumps({'files': uploaded}))
    else:
        raise Http404
开发者ID:antofik,项目名称:meimew,代码行数:26,代码来源:views.py

示例3: multiuploader

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import filename [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.filename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。