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
6bb3b2bf
Kaydet (Commit)
6bb3b2bf
authored
Nis 07, 2017
tarafından
Ingo Klöcker
Kaydeden (comit)
Tim Graham
Haz 01, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #27777 -- Improved docs/added test for File context manager change.
üst
eee34ef6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
3 deletions
+18
-3
file.txt
docs/ref/files/file.txt
+5
-2
2.0.txt
docs/releases/2.0.txt
+2
-1
test_filefield.py
tests/model_fields/test_filefield.py
+11
-0
No files found.
docs/ref/files/file.txt
Dosyayı görüntüle @
6bb3b2bf
...
...
@@ -56,8 +56,11 @@ The ``File`` class
was originally opened with; ``None`` means to reopen with the original
mode.
Returns ``self``, so that it can be used similar to Python's
built-in :func:`python:open()` with the ``with`` statement.
It can be used as a context manager, e.g. ``with file.open() as f:``.
.. versionchanged:: 2.0
Context manager support was added.
.. method:: __iter__()
...
...
docs/releases/2.0.txt
Dosyayı görüntüle @
6bb3b2bf
...
...
@@ -150,7 +150,8 @@ Email
File Storage
~~~~~~~~~~~~
* ...
* :meth:`File.open() <django.core.files.File.open>` can be used as a context
manager, e.g. ``with file.open() as f:``.
File Uploads
~~~~~~~~~~~~
...
...
tests/model_fields/test_filefield.py
Dosyayı görüntüle @
6bb3b2bf
...
...
@@ -3,6 +3,7 @@ import sys
import
unittest
from
django.core.files
import
temp
from
django.core.files.base
import
ContentFile
from
django.core.files.uploadedfile
import
TemporaryUploadedFile
from
django.db.utils
import
IntegrityError
from
django.test
import
TestCase
,
override_settings
...
...
@@ -83,3 +84,13 @@ class FileFieldTests(TestCase):
tmp_file_path
=
tmp_file
.
temporary_file_path
()
Document
.
objects
.
create
(
myfile
=
tmp_file
)
self
.
assertFalse
(
os
.
path
.
exists
(
tmp_file_path
),
'Temporary file still exists'
)
def
test_open_returns_self
(
self
):
"""
FieldField.open() returns self so it can be used as a context manager.
"""
d
=
Document
.
objects
.
create
(
myfile
=
'something.txt'
)
# Replace the FileField's file with an in-memory ContentFile, so that
# open() doesn't write to disk.
d
.
myfile
.
file
=
ContentFile
(
b
''
,
name
=
'bla'
)
self
.
assertEqual
(
d
.
myfile
,
d
.
myfile
.
open
())
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