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
a0c07d77
Kaydet (Commit)
a0c07d77
authored
May 28, 2017
tarafından
Manatsawin Hanmongkolchai
Kaydeden (comit)
Tim Graham
Haz 01, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28242 -- Moved ImageField file extension validation to the form field.
üst
6bb3b2bf
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
47 additions
and
11 deletions
+47
-11
files.py
django/db/models/fields/files.py
+0
-2
fields.py
django/forms/fields.py
+1
-0
1.11.2.txt
docs/releases/1.11.2.txt
+4
-0
1.11.txt
docs/releases/1.11.txt
+1
-0
test_imagefield.py
tests/forms_tests/field_tests/test_imagefield.py
+10
-1
test_imagefield.py
tests/model_fields/test_imagefield.py
+1
-7
models.py
tests/model_forms/models.py
+11
-0
tests.py
tests/model_forms/tests.py
+19
-1
No files found.
django/db/models/fields/files.py
Dosyayı görüntüle @
a0c07d77
...
...
@@ -6,7 +6,6 @@ from django.core import checks
from
django.core.files.base
import
File
from
django.core.files.images
import
ImageFile
from
django.core.files.storage
import
default_storage
from
django.core.validators
import
validate_image_file_extension
from
django.db.models
import
signals
from
django.db.models.fields
import
Field
from
django.utils.translation
import
gettext_lazy
as
_
...
...
@@ -355,7 +354,6 @@ class ImageFieldFile(ImageFile, FieldFile):
class
ImageField
(
FileField
):
default_validators
=
[
validate_image_file_extension
]
attr_class
=
ImageFieldFile
descriptor_class
=
ImageFileDescriptor
description
=
_
(
"Image"
)
...
...
django/forms/fields.py
Dosyayı görüntüle @
a0c07d77
...
...
@@ -591,6 +591,7 @@ class FileField(Field):
class
ImageField
(
FileField
):
default_validators
=
[
validators
.
validate_image_file_extension
]
default_error_messages
=
{
'invalid_image'
:
_
(
"Upload a valid image. The file you uploaded was either not an "
...
...
docs/releases/1.11.2.txt
Dosyayı görüntüle @
a0c07d77
...
...
@@ -58,3 +58,7 @@ Bugfixes
* Fixed a regression where ``file_move_safe()`` crashed when moving files to a
CIFS mount (:ticket:`28170`).
* Moved the ``ImageField`` file extension validation added in Django 1.11 from
the model field to the form field to reallow the use case of storing images
without an extension (:ticket:`28242`).
docs/releases/1.11.txt
Dosyayı görüntüle @
a0c07d77
...
...
@@ -327,6 +327,7 @@ Models
* :class:`~django.db.models.ImageField` now has a default
:data:`~django.core.validators.validate_image_file_extension` validator.
(This validator moved to the form field in :doc:`Django 1.11.2 <1.11.2>`.)
* Added support for time truncation to
:class:`~django.db.models.functions.datetime.Trunc` functions.
...
...
tests/forms_tests/field_tests/test_imagefield.py
Dosyayı görüntüle @
a0c07d77
...
...
@@ -2,7 +2,7 @@ import os
import
unittest
from
django.core.files.uploadedfile
import
SimpleUploadedFile
from
django.forms
import
ImageField
from
django.forms
import
ImageField
,
ValidationError
from
django.test
import
SimpleTestCase
try
:
...
...
@@ -55,3 +55,12 @@ class ImageFieldTest(SimpleTestCase):
self
.
assertIsNone
(
uploaded_file
.
content_type
)
finally
:
Image
.
register_mime
(
BmpImageFile
.
format
,
'image/bmp'
)
def
test_file_extension_validation
(
self
):
f
=
ImageField
()
img_path
=
get_img_path
(
'filepath_test_files/1x1.png'
)
with
open
(
img_path
,
'rb'
)
as
img_file
:
img_data
=
img_file
.
read
()
img_file
=
SimpleUploadedFile
(
'1x1.txt'
,
img_data
)
with
self
.
assertRaisesMessage
(
ValidationError
,
"File extension 'txt' is not allowed."
):
f
.
clean
(
img_file
)
tests/model_fields/test_imagefield.py
Dosyayı görüntüle @
a0c07d77
...
...
@@ -2,7 +2,7 @@ import os
import
shutil
from
unittest
import
skipIf
from
django.core.exceptions
import
ImproperlyConfigured
,
ValidationError
from
django.core.exceptions
import
ImproperlyConfigured
from
django.core.files
import
File
from
django.core.files.images
import
ImageFile
from
django.test
import
TestCase
...
...
@@ -130,12 +130,6 @@ class ImageFieldTests(ImageFieldTestMixin, TestCase):
self
.
assertEqual
(
hash
(
p1_db
.
mugshot
),
hash
(
p1
.
mugshot
))
self
.
assertIs
(
p1_db
.
mugshot
!=
p1
.
mugshot
,
False
)
def
test_validation
(
self
):
p
=
self
.
PersonModel
(
name
=
"Joan"
)
p
.
mugshot
.
save
(
"shot.txt"
,
self
.
file1
)
with
self
.
assertRaisesMessage
(
ValidationError
,
"File extension 'txt' is not allowed."
):
p
.
full_clean
()
def
test_instantiate_missing
(
self
):
"""
If the underlying file is unavailable, still create instantiate the
...
...
tests/model_forms/models.py
Dosyayı görüntüle @
a0c07d77
...
...
@@ -192,6 +192,17 @@ try:
def
__str__
(
self
):
return
self
.
description
class
NoExtensionImageFile
(
models
.
Model
):
def
upload_to
(
self
,
filename
):
return
'tests/no_extension'
description
=
models
.
CharField
(
max_length
=
20
)
image
=
models
.
ImageField
(
storage
=
temp_storage
,
upload_to
=
upload_to
)
def
__str__
(
self
):
return
self
.
description
except
ImportError
:
test_images
=
False
...
...
tests/model_forms/tests.py
Dosyayı görüntüle @
a0c07d77
...
...
@@ -32,7 +32,7 @@ from .models import (
)
if
test_images
:
from
.models
import
ImageFile
,
OptionalImageFile
from
.models
import
ImageFile
,
OptionalImageFile
,
NoExtensionImageFile
class
ImageFileForm
(
forms
.
ModelForm
):
class
Meta
:
...
...
@@ -44,6 +44,11 @@ if test_images:
model
=
OptionalImageFile
fields
=
'__all__'
class
NoExtensionImageFileForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
NoExtensionImageFile
fields
=
'__all__'
class
ProductForm
(
forms
.
ModelForm
):
class
Meta
:
...
...
@@ -2461,6 +2466,19 @@ class FileAndImageFieldTests(TestCase):
self
.
assertEqual
(
instance
.
image
.
name
,
'foo/test4.png'
)
instance
.
delete
()
# Editing an instance that has an image without an extension shouldn't
# fail validation. First create:
f
=
NoExtensionImageFileForm
(
data
=
{
'description'
:
'An image'
},
files
=
{
'image'
:
SimpleUploadedFile
(
'test.png'
,
image_data
)},
)
self
.
assertTrue
(
f
.
is_valid
())
instance
=
f
.
save
()
self
.
assertEqual
(
instance
.
image
.
name
,
'tests/no_extension'
)
# Then edit:
f
=
NoExtensionImageFileForm
(
data
=
{
'description'
:
'Edited image'
},
instance
=
instance
)
self
.
assertTrue
(
f
.
is_valid
())
class
ModelOtherFieldTests
(
SimpleTestCase
):
def
test_big_integer_field
(
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