mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
Fixed #19525 -- Reverted dcd4383107
and 05d333ba3b
.
Refs #9893, #18515. Thanks Russell for the report.
This commit is contained in:
parent
b3a8c9dab8
commit
db278c3bf9
3 changed files with 1 additions and 44 deletions
|
@ -3,7 +3,6 @@ import os
|
|||
|
||||
from django import forms
|
||||
from django.db.models.fields import Field
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.files.base import File
|
||||
from django.core.files.storage import default_storage
|
||||
from django.core.files.images import ImageFile
|
||||
|
@ -207,10 +206,6 @@ class FileDescriptor(object):
|
|||
|
||||
class FileField(Field):
|
||||
|
||||
default_error_messages = {
|
||||
'max_length': _('Filename is %(extra)d characters too long.')
|
||||
}
|
||||
|
||||
# The class to wrap instance attributes in. Accessing the file object off
|
||||
# the instance will always return an instance of attr_class.
|
||||
attr_class = FieldFile
|
||||
|
@ -233,25 +228,6 @@ class FileField(Field):
|
|||
kwargs['max_length'] = kwargs.get('max_length', 100)
|
||||
super(FileField, self).__init__(verbose_name, name, **kwargs)
|
||||
|
||||
def validate(self, value, model_instance):
|
||||
"""
|
||||
Validates that the generated file name still fits within max_length.
|
||||
"""
|
||||
# The generated file name stored in the database is generally longer
|
||||
# than the uploaded file name. Using the length of generated name in
|
||||
# the error message would be confusing. However, in the common case
|
||||
# (ie. upload_to='path/to/upload/dir'), the length of the generated
|
||||
# name equals the length of the uploaded name plus a constant. Thus
|
||||
# we can tell the user how much shorter the name should be (roughly).
|
||||
if value and value._committed:
|
||||
filename = value.name
|
||||
else:
|
||||
filename = self.generate_filename(model_instance, value.name)
|
||||
length = len(filename)
|
||||
if self.max_length and length > self.max_length:
|
||||
error_values = {'extra': length - self.max_length}
|
||||
raise ValidationError(self.error_messages['max_length'] % error_values)
|
||||
|
||||
def get_internal_type(self):
|
||||
return "FileField"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue