magic-removal: Restored FileField validation stuff that had been commented out.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2104 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-01-22 06:44:05 +00:00
parent d6b154a888
commit 63b158ecb4
1 changed files with 23 additions and 24 deletions

View File

@ -430,28 +430,27 @@ class FileField(Field):
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):
field_list = Field.get_manipulator_fields(self, opts, manipulator, change, name_prefix, rel, follow)
if not self.blank:
#if rel:
if rel:
# This validator makes sure FileFields work in a related context.
# class RequiredFileField:
# def __init__(self, other_field_names, other_file_field_name):
# self.other_field_names = other_field_names
# self.other_file_field_name = other_file_field_name
# self.always_test = True
# def __call__(self, field_data, all_data):
# if not all_data.get(self.other_file_field_name, False):
# c = validators.RequiredIfOtherFieldsGiven(self.other_field_names, gettext_lazy("This field is required."))
# c(field_data, all_data)
# # First, get the core fields, if any.
# core_field_names = []
# for f in opts.fields:
# if f.core and f != self:
# core_field_names.extend(f.get_manipulator_field_names(name_prefix))
# # Now, if there are any, add the validator to this FormField.
# if core_field_names:
# field_list[0].validator_list.append(RequiredFileField(core_field_names, field_list[1].field_name))
# else:
class RequiredFileField:
def __init__(self, other_field_names, other_file_field_name):
self.other_field_names = other_field_names
self.other_file_field_name = other_file_field_name
self.always_test = True
def __call__(self, field_data, all_data):
if not all_data.get(self.other_file_field_name, False):
c = validators.RequiredIfOtherFieldsGiven(self.other_field_names, gettext_lazy("This field is required."))
c(field_data, all_data)
# First, get the core fields, if any.
core_field_names = []
for f in opts.fields:
if f.core and f != self:
core_field_names.extend(f.get_manipulator_field_names(name_prefix))
# Now, if there are any, add the validator to this FormField.
if core_field_names:
field_list[0].validator_list.append(RequiredFileField(core_field_names, field_list[1].field_name))
else:
v = validators.RequiredIfOtherFieldNotGiven(field_list[1].field_name, gettext_lazy("This field is required."))
v.always_test = True
field_list[0].validator_list.append(v)