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


Python UploadedFile.close方法代码示例

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


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

示例1: stitch_chunks

# 需要导入模块: from django.core.files.uploadedfile import UploadedFile [as 别名]
# 或者: from django.core.files.uploadedfile.UploadedFile import close [as 别名]
 def stitch_chunks(self):
     f = open(os.path.join(settings.MEDIA_ROOT, cloud_path(self, self.filename)), "wb")
     for chunk in self.chunks.all().order_by("pk"):
         f.write(chunk.chunk.read())
     f.close()
     f = UploadedFile(open(f.name, "rb"))
     self.upload.save(self.filename, f)
     self.state = Upload.STATE_COMPLETE
     self.save()
     f.close()
开发者ID:joskid,项目名称:django-chunked-uploads,代码行数:12,代码来源:models.py

示例2: handle_noargs

# 需要导入模块: from django.core.files.uploadedfile import UploadedFile [as 别名]
# 或者: from django.core.files.uploadedfile.UploadedFile import close [as 别名]

#.........这里部分代码省略.........
                review_request = ReviewRequest.objects.create(new_user, None)
                review_request.public = True
                review_request.summary = self.lorem_ipsum("summary")
                review_request.description = self.lorem_ipsum("description")
                review_request.shipit_count = 0
                review_request.repository = self.repository
                # Set the targeted reviewer to superuser or 1st defined.
                if j == 0:
                    review_request.target_people.add(User.objects.get(pk=1))
                review_request.save()

                # Add the diffs if any to add.
                diff_val = self.pickRandomValue(num_of_diffs)

                # If adding diffs add history.
                if diff_val > 0:
                    diffset_history = DiffSetHistory.objects.create(
                        name='testDiffFile' + str(i))
                    diffset_history.save()

                # Won't execute if diff_val is 0, ie: no diffs requested.
                for k in range(0, diff_val):
                    if int(verbosity) > NORMAL:
                        print "%s:\tDiff #%s" % (i, k)

                    random_number = random.randint(0, len(files) - 1)
                    file_to_open = diff_dir + files[random_number]
                    f = UploadedFile(open(file_to_open, 'r'))
                    form = UploadDiffForm(review_request.repository, f)
                    cur_diff = form.create(f, None, diffset_history)
                    review_request.diffset_history = diffset_history
                    review_request.save()
                    review_request.publish(new_user)
                    f.close()

                    # Add the reviews if any.
                    review_val = self.pickRandomValue(num_of_reviews)

                    for l in range(0, review_val):
                        if int(verbosity) > NORMAL:
                            print "%s:%s:\t\tReview #%s:" % (i, j, l)

                        reviews = Review.objects.create(
                            review_request=review_request,
                            user=new_user)

                        reviews.publish(new_user)

                        # Add comments if any.
                        comment_val = self.pickRandomValue(
                            num_of_diff_comments)

                        for m in range(0, comment_val):
                            if int(verbosity) > NORMAL:
                                print "%s:%s:\t\t\tComments #%s" % (i, j, m)

                            if m == 0:
                                file_diff = cur_diff.files.order_by('id')[0]

                            # Choose random lines to comment.
                            # Max lines: should be mod'd in future to read
                            # diff.
                            max_lines = 220
                            first_line = random.randrange(1, max_lines - 1)
                            remain_lines = max_lines - first_line
                            num_lines = random.randrange(1, remain_lines)
开发者ID:harrifeng,项目名称:reviewboard,代码行数:70,代码来源:fill-database.py

示例3: editOrCreateStuff

# 需要导入模块: from django.core.files.uploadedfile import UploadedFile [as 别名]
# 或者: from django.core.files.uploadedfile.UploadedFile import close [as 别名]
def editOrCreateStuff(project, request, creating):

## Note: if creating == true this is a post being created.
#Because there are so many similarities in creating a post vs editing a post we are using this method, and using creating when we need to do something different for editing vs creating.

  ## postmode! We are getting pretty post data from the user!!!
    if request.method == 'POST':
    ## get the forms and check that they are valid
        formValid=False
        if creating:
            form = createForm(request.POST, project)
            form2 = defaulttag(request.POST)
            if form.is_valid() and form2.is_valid() and request.user.is_authenticated():
                formValid=True
               # If we are creating the post we need to set the author and title.
                project.author = request.user
                project.title = form.cleaned_data["title"]
        else:
            form = ProjectForm(request.POST, project)
            if form.is_valid() and str(project.author) == str(request.user):
                formValid=True
       ## if the form is valid make the changes to the project!
        if formValid:

          # Editing the Readme.md file stuff.

            if not creating:
          # Delete the old body text file... cause I'm a bad person and I don't know how to just open and write to the old one easily.
	        readme = project.bodyFile
                try:
                    readme = project.bodyFile
                    readmename = path.split(str(readme.filename))[1]
                    readme.delete()
                except:
                    pass

           # Save body as file
            bodyText = fileobject()

            bodyText.parent = project

            from django.core.files.uploadedfile import UploadedFile
            import base64
            from io import BytesIO
            from io import TextIOWrapper
            from io import StringIO

           #io = TextIOWrapper(TextIOBase(form.cleaned_data["body"]))
            io = StringIO(form.cleaned_data["body"])
            txfl = UploadedFile(io)


            #editfield may be renaming your readme to readme.md every time. That's not good.
            try:
                bodyText.filename.save(readmename, txfl)
            except:
                bodyText.filename.save('README.md', txfl)

            txfl.close()
            io.close()

            bodyText.save()

     #### this did not appear to be happening in the create.... but I think it should have been?
            project.bodyFile = bodyText

         # Done with editing the README.md textfile.

         # 
            list_to_tags(form.cleaned_data["tags"], project.tags)
            if creating:
                for i in form2.cleaned_data["categories"]:
                    project.tags.add(i)

         # This may be redundant, but either way, this post is not a draft past this point.
            project.draft=False

            project.save()

            return HttpResponseRedirect('/project/'+str(project.pk))

     #### If the form data was NOT valid
        else:
            if creating:
                return render_to_response('create.html', dict(user=request.user,  form=form, form2=form2, project=project))
            else:
                if str(project.author) == str(request.user):
                    return render_to_response('edit.html', dict(project=project, user=request.user, form=form, ))
                else:
                    return HttpResponse(status=403)

   #### Not POSTmode! We are setting up the form for the user to fill in. We are not getting form data from the user.

##### CREATE
    elif creating and request.user.is_authenticated():
        form = createForm("",project)
        form2 = defaulttag()
        return render_to_response('create.html', dict(user=request.user, form=form, form2=form2, project=project))

##### EDIT
#.........这里部分代码省略.........
开发者ID:RTLShadow,项目名称:rhombik-object-repository,代码行数:103,代码来源:views.py


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