0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-30 01:46:24 +01:00

Move file.open call into set-file-metadata method

If the file is already open this is the same as seek(0), so there are no unwanted side effects from this.
This commit is contained in:
Matt Westcott 2022-07-05 16:41:17 +01:00 committed by Matt Westcott
parent fcb2776383
commit fe73506747
4 changed files with 4 additions and 2 deletions

View File

@ -135,6 +135,8 @@ class AbstractDocument(CollectionMember, index.Indexed, models.Model):
return self.file_hash
def _set_document_file_metadata(self):
self.file.open()
# Set new document file size
self.file_size = self.file.size

View File

@ -118,7 +118,6 @@ class CreateFromUploadedDocumentView(BaseCreateFromUploadView):
os.path.basename(self.upload.file.name), self.upload.file.file, save=False
)
self.object.uploaded_by_user = self.request.user
self.object.file.open()
self.object._set_document_file_metadata()
form.save()

View File

@ -237,6 +237,8 @@ class AbstractImage(ImageFileMixin, CollectionMember, index.Indexed, models.Mode
return self.file_hash
def _set_image_file_metadata(self):
self.file.open()
# Set new image file size
self.file_size = self.file.size

View File

@ -160,7 +160,6 @@ class CreateFromUploadedImageView(BaseCreateFromUploadView):
os.path.basename(self.upload.file.name), self.upload.file.file, save=False
)
self.object.uploaded_by_user = self.request.user
self.object.file.open()
self.object._set_image_file_metadata()
form.save()