kopia lustrzana https://github.com/wagtail/wagtail
Merge 0f075c01cb
into 7c6187f06c
commit
9b7b6b7d92
|
@ -4,6 +4,7 @@ from contextlib import contextmanager
|
|||
from mimetypes import guess_type
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import FileExtensionValidator
|
||||
from django.db import models
|
||||
from django.dispatch import Signal
|
||||
|
@ -71,7 +72,10 @@ class AbstractDocument(CollectionMember, index.Indexed, models.Model):
|
|||
allowed_extensions = getattr(settings, "WAGTAILDOCS_EXTENSIONS", None)
|
||||
if allowed_extensions:
|
||||
validate = FileExtensionValidator(allowed_extensions)
|
||||
validate(self.file)
|
||||
try:
|
||||
validate(self.file)
|
||||
except ValidationError as e:
|
||||
raise ValidationError({"file": e.messages[0]})
|
||||
|
||||
def is_stored_locally(self):
|
||||
"""
|
||||
|
|
|
@ -217,8 +217,12 @@ class TestDocumentValidateExtensions(TestCase):
|
|||
creation when called full_clean. This specific testcase invalid
|
||||
file extension is passed
|
||||
"""
|
||||
with self.assertRaises(ValidationError):
|
||||
with self.assertRaises(ValidationError) as cm:
|
||||
self.document_invalid.full_clean()
|
||||
expected_message = (
|
||||
"File extension “doc” is not allowed. Allowed extensions are: pdf."
|
||||
)
|
||||
self.assertEqual(cm.exception.message_dict["file"][0], expected_message)
|
||||
|
||||
def test_create_doc_valid_extension(self):
|
||||
"""
|
||||
|
|
Ładowanie…
Reference in New Issue