mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #28242 -- Moved ImageField file extension validation to the form field.
This commit is contained in:
committed by
Tim Graham
parent
6bb3b2bff4
commit
a0c07d77fc
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user