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
a52a531a
Kaydet (Commit)
a52a531a
authored
Mar 22, 2016
tarafından
Alexey Kotlyarov
Kaydeden (comit)
Tim Graham
Mar 23, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #26398 -- Made FieldFile.open() respect its mode argument.
üst
9390da7f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
4 deletions
+13
-4
files.py
django/db/models/fields/files.py
+3
-4
tests.py
tests/file_storage/tests.py
+10
-0
No files found.
django/db/models/fields/files.py
Dosyayı görüntüle @
a52a531a
...
@@ -42,10 +42,10 @@ class FieldFile(File):
...
@@ -42,10 +42,10 @@ class FieldFile(File):
if
not
self
:
if
not
self
:
raise
ValueError
(
"The '
%
s' attribute has no file associated with it."
%
self
.
field
.
name
)
raise
ValueError
(
"The '
%
s' attribute has no file associated with it."
%
self
.
field
.
name
)
def
_get_file
(
self
):
def
_get_file
(
self
,
mode
=
'rb'
):
self
.
_require_file
()
self
.
_require_file
()
if
not
hasattr
(
self
,
'_file'
)
or
self
.
_file
is
None
:
if
not
hasattr
(
self
,
'_file'
)
or
self
.
_file
is
None
:
self
.
_file
=
self
.
storage
.
open
(
self
.
name
,
'rb'
)
self
.
_file
=
self
.
storage
.
open
(
self
.
name
,
mode
)
return
self
.
_file
return
self
.
_file
def
_set_file
(
self
,
file
):
def
_set_file
(
self
,
file
):
...
@@ -74,8 +74,7 @@ class FieldFile(File):
...
@@ -74,8 +74,7 @@ class FieldFile(File):
size
=
property
(
_get_size
)
size
=
property
(
_get_size
)
def
open
(
self
,
mode
=
'rb'
):
def
open
(
self
,
mode
=
'rb'
):
self
.
_require_file
()
self
.
_get_file
(
mode
)
self
.
file
.
open
(
mode
)
# open() doesn't alter the file's contents, but it does reset the pointer
# open() doesn't alter the file's contents, but it does reset the pointer
open
.
alters_data
=
True
open
.
alters_data
=
True
...
...
tests/file_storage/tests.py
Dosyayı görüntüle @
a52a531a
...
@@ -710,6 +710,16 @@ class FileFieldStorageTests(TestCase):
...
@@ -710,6 +710,16 @@ class FileFieldStorageTests(TestCase):
self
.
assertEqual
(
list
(
obj
.
normal
.
chunks
(
chunk_size
=
2
)),
[
b
"co"
,
b
"nt"
,
b
"en"
,
b
"t"
])
self
.
assertEqual
(
list
(
obj
.
normal
.
chunks
(
chunk_size
=
2
)),
[
b
"co"
,
b
"nt"
,
b
"en"
,
b
"t"
])
obj
.
normal
.
close
()
obj
.
normal
.
close
()
def
test_filefield_write
(
self
):
# Files can be written to.
obj
=
Storage
.
objects
.
create
(
normal
=
SimpleUploadedFile
(
'rewritten.txt'
,
b
'content'
))
with
obj
.
normal
as
normal
:
normal
.
open
(
'wb'
)
normal
.
write
(
b
'updated'
)
obj
.
refresh_from_db
()
self
.
assertEqual
(
obj
.
normal
.
read
(),
b
'updated'
)
obj
.
normal
.
close
()
def
test_duplicate_filename
(
self
):
def
test_duplicate_filename
(
self
):
# Multiple files with the same name get _(7 random chars) appended to them.
# Multiple files with the same name get _(7 random chars) appended to them.
objs
=
[
Storage
()
for
i
in
range
(
2
)]
objs
=
[
Storage
()
for
i
in
range
(
2
)]
...
...
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