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
cf6ce279
Kaydet (Commit)
cf6ce279
authored
Haz 16, 2015
tarafından
Andriy Sokolovskiy
Kaydeden (comit)
Tim Graham
Haz 16, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24948 -- Fixed crash when uploading bitmap images in forms.ImageField
üst
fbc618c1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
6 deletions
+35
-6
fields.py
django/forms/fields.py
+3
-1
fields.txt
docs/ref/forms/fields.txt
+8
-5
1.8.3.txt
docs/releases/1.8.3.txt
+3
-0
1x1.bmp
tests/forms_tests/tests/filepath_test_files/1x1.bmp
+0
-0
test_fields.py
tests/forms_tests/tests/test_fields.py
+21
-0
No files found.
django/forms/fields.py
Dosyayı görüntüle @
cf6ce279
...
...
@@ -683,7 +683,9 @@ class ImageField(FileField):
# Annotating so subclasses can reuse it for their own validation
f
.
image
=
image
f
.
content_type
=
Image
.
MIME
[
image
.
format
]
# Pillow doesn't detect the MIME type of all formats. In those
# cases, content_type will be None.
f
.
content_type
=
Image
.
MIME
.
get
(
image
.
format
)
except
Exception
:
# Pillow doesn't recognize it as an image.
six
.
reraise
(
ValidationError
,
ValidationError
(
...
...
docs/ref/forms/fields.txt
Dosyayı görüntüle @
cf6ce279
...
...
@@ -684,13 +684,16 @@ For each field, we describe the default widget used if you don't specify
When you use an ``ImageField`` on a form, you must also remember to
:ref:`bind the file data to the form <binding-uploaded-files>`.
After the field has been cleaned and validated, the ``UploadedFile``
object will have an additional ``image`` attribute containing the Pillow
`Image`_ instance used to check if the file was a valid image. Also,
``UploadedFile.content_type`` will be updated with the image's content type
if Pillow can determine it, otherwise it will be set to ``None``.
.. versionchanged:: 1.8
After the field has been cleaned and validated, the ``UploadedFile``
object will have an additional ``image`` attribute containing the Pillow
`Image`_ instance used to check if the file was a valid image.
``UploadedFile.content_type`` is also updated with the image's content
type as determined by Pillow.
The ``image`` and ``content_type`` attributes described in the last
paragraph were added.
.. _Pillow: http://pillow.readthedocs.org/en/latest/
.. _Image: https://pillow.readthedocs.org/en/latest/reference/Image.html
...
...
docs/releases/1.8.3.txt
Dosyayı görüntüle @
cf6ce279
...
...
@@ -71,3 +71,6 @@ Bugfixes
using UUID primary keys (:ticket:`24912`).
* Fixed removing ``unique_together`` constraints on MySQL (:ticket:`24972`).
* Fixed crash when uploading images with MIME types that Pillow doesn't detect,
such as bitmap, in ``forms.ImageField`` (:ticket:`24948`).
tests/forms_tests/tests/filepath_test_files/1x1.bmp
0 → 100644
Dosyayı görüntüle @
cf6ce279
58 Bytes
tests/forms_tests/tests/test_fields.py
Dosyayı görüntüle @
cf6ce279
...
...
@@ -829,6 +829,26 @@ class FieldsTests(SimpleTestCase):
self
.
assertEqual
(
'PNG'
,
uploaded_file
.
image
.
format
)
self
.
assertEqual
(
'image/png'
,
uploaded_file
.
content_type
)
@skipIf
(
Image
is
None
,
"Pillow is required to test ImageField"
)
def
test_imagefield_annotate_with_bitmap_image_after_clean
(
self
):
"""
This also tests the situation when Pillow doesn't detect the MIME type
of the image (#24948).
"""
f
=
ImageField
()
img_path
=
os
.
path
.
dirname
(
upath
(
__file__
))
+
'/filepath_test_files/1x1.bmp'
with
open
(
img_path
,
'rb'
)
as
img_file
:
img_data
=
img_file
.
read
()
img_file
=
SimpleUploadedFile
(
'1x1.bmp'
,
img_data
)
img_file
.
content_type
=
'text/plain'
uploaded_file
=
f
.
clean
(
img_file
)
self
.
assertEqual
(
'BMP'
,
uploaded_file
.
image
.
format
)
self
.
assertIsNone
(
uploaded_file
.
content_type
)
# URLField ##################################################################
def
test_urlfield_1
(
self
):
...
...
@@ -1372,6 +1392,7 @@ class FieldsTests(SimpleTestCase):
f
.
choices
.
sort
()
expected
=
[
(
'/tests/forms_tests/tests/filepath_test_files/.dot-file'
,
'.dot-file'
),
(
'/tests/forms_tests/tests/filepath_test_files/1x1.bmp'
,
'1x1.bmp'
),
(
'/tests/forms_tests/tests/filepath_test_files/1x1.png'
,
'1x1.png'
),
(
'/tests/forms_tests/tests/filepath_test_files/directory'
,
'directory'
),
(
'/tests/forms_tests/tests/filepath_test_files/fake-image.jpg'
,
'fake-image.jpg'
),
...
...
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