Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
664855b7
Kaydet (Commit)
664855b7
authored
Şub 23, 2013
tarafından
Marcin Biernat
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#18899 FileSystemStorage.save should support any file-like objects
üst
7ec2a21b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
2 deletions
+36
-2
storage.py
django/core/files/storage.py
+6
-2
tests.py
tests/modeltests/files/tests.py
+30
-0
No files found.
django/core/files/storage.py
Dosyayı görüntüle @
664855b7
...
...
@@ -37,13 +37,17 @@ class Storage(object):
def
save
(
self
,
name
,
content
):
"""
Saves new content to the file specified by name. The content should be a
proper File object, ready to be read from the beginning.
Saves new content to the file specified by name. The content should be
a proper File object or any python file-like object, ready to be read
from the beginning.
"""
# Get the proper name for the file, as it will actually be saved.
if
name
is
None
:
name
=
content
.
name
if
not
hasattr
(
content
,
'chunks'
):
content
=
File
(
content
)
name
=
self
.
get_available_name
(
name
)
name
=
self
.
_save
(
name
,
content
)
...
...
tests/modeltests/files/tests.py
Dosyayı görüntüle @
664855b7
...
...
@@ -2,6 +2,7 @@ from __future__ import absolute_import
import
gzip
import
shutil
import
StringIO
import
tempfile
from
django.core.cache
import
cache
...
...
@@ -102,6 +103,35 @@ class FileStorageTests(TestCase):
obj4
.
random
.
save
(
"random_file"
,
ContentFile
(
"random content"
))
self
.
assertTrue
(
obj4
.
random
.
name
.
endswith
(
"/random_file"
))
def
test_file_object
(
self
):
# Create sample file
temp_storage
.
save
(
'tests/example.txt'
,
ContentFile
(
'some content'
))
# Load it as python file object
file_obj
=
open
(
temp_storage
.
path
(
'tests/example.txt'
))
# Save it using storage and read its content
temp_storage
.
save
(
'tests/file_obj'
,
file_obj
)
self
.
assertTrue
(
temp_storage
.
exists
(
'tests/file_obj'
))
self
.
assertEqual
(
temp_storage
.
open
(
'tests/file_obj'
)
.
read
(),
'some content'
)
def
test_stringio
(
self
):
# Test passing StringIO instance as content argument to save
output
=
StringIO
.
StringIO
()
output
.
write
(
'content'
)
output
.
seek
(
0
)
# Save it and read written file
temp_storage
.
save
(
'tests/stringio'
,
output
)
self
.
assertTrue
(
temp_storage
.
exists
(
'tests/stringio'
))
self
.
assertEqual
(
temp_storage
.
open
(
'tests/stringio'
)
.
read
(),
'content'
)
class
FileTests
(
unittest
.
TestCase
):
def
test_context_manager
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment