Edited contrib.admin check messages for grammar and consistency.

This commit is contained in:
Russell Keith-Magee 2014-03-03 13:27:17 +08:00
parent 90577c0eb4
commit 3c5fc708f1
4 changed files with 203 additions and 182 deletions

View File

@ -78,7 +78,7 @@ class BaseModelAdminChecks(object):
elif cls.fieldsets:
return [
checks.Error(
'Both "fieldsets" and "fields" are specified.',
"Both 'fieldsets' and 'fields' are specified.",
hint=None,
obj=cls,
id='admin.E005',
@ -88,7 +88,7 @@ class BaseModelAdminChecks(object):
if len(fields) != len(set(fields)):
return [
checks.Error(
'There are duplicate field(s) in "fields".',
"The value of 'fields' contains duplicate field(s).",
hint=None,
obj=cls,
id='admin.E006',
@ -121,13 +121,13 @@ class BaseModelAdminChecks(object):
if not isinstance(fieldset, (list, tuple)):
return must_be('a list or tuple', option=label, obj=cls, id='admin.E008')
elif len(fieldset) != 2:
return must_be('a pair', option=label, obj=cls, id='admin.E009')
return must_be('of length 2', option=label, obj=cls, id='admin.E009')
elif not isinstance(fieldset[1], dict):
return must_be('a dictionary', option='%s[1]' % label, obj=cls, id='admin.E010')
elif 'fields' not in fieldset[1]:
return [
checks.Error(
'"%s[1]" must contain "fields" key.' % label,
"The value of '%s[1]' must contain the key 'fields'." % label,
hint=None,
obj=cls,
id='admin.E011',
@ -138,14 +138,14 @@ class BaseModelAdminChecks(object):
if len(fields) != len(set(fields)):
return [
checks.Error(
'There are duplicate field(s) in "%s[1]".' % label,
"There are duplicate field(s) in '%s[1]'." % label,
hint=None,
obj=cls,
id='admin.E012',
)
]
return list(chain(*[
self._check_field_spec(cls, model, fieldset_fields, '%s[1][\'fields\']' % label)
self._check_field_spec(cls, model, fieldset_fields, '%s[1]["fields"]' % label)
for fieldset_fields in fieldset[1]['fields']
]))
@ -180,9 +180,9 @@ class BaseModelAdminChecks(object):
not field.rel.through._meta.auto_created):
return [
checks.Error(
'"%s" cannot include the ManyToManyField "%s", '
'because "%s" manually specifies relationship model.'
% (label, field_name, field_name),
("The value of '%s' cannot include the ManyToManyField '%s', "
"because that field manually specifies a relationship model.")
% (label, field_name),
hint=None,
obj=cls,
id='admin.E013',
@ -201,7 +201,7 @@ class BaseModelAdminChecks(object):
elif len(cls.exclude) > len(set(cls.exclude)):
return [
checks.Error(
'"exclude" contains duplicate field(s).',
"The value of 'exclude' contains duplicate field(s).",
hint=None,
obj=cls,
id='admin.E015',
@ -270,7 +270,7 @@ class BaseModelAdminChecks(object):
else:
return list(chain(*[
self._check_radio_fields_key(cls, model, field_name, 'radio_fields') +
self._check_radio_fields_value(cls, model, val, 'radio_fields[\'%s\']' % field_name)
self._check_radio_fields_value(cls, model, val, 'radio_fields["%s"]' % field_name)
for field_name, val in cls.radio_fields.items()
]))
@ -287,7 +287,7 @@ class BaseModelAdminChecks(object):
if not (isinstance(field, models.ForeignKey) or field.choices):
return [
checks.Error(
'"%s" refers to "%s", which is neither an instance of ForeignKey nor does have choices set.' % (
"The value of '%s' refers to '%s', which is not an instance of ForeignKey, and does not have a 'choices' definition." % (
label, field_name
),
hint=None,
@ -306,7 +306,7 @@ class BaseModelAdminChecks(object):
if val not in (HORIZONTAL, VERTICAL):
return [
checks.Error(
'"%s" is neither admin.HORIZONTAL nor admin.VERTICAL.' % label,
"The value of '%s' must be either admin.HORIZONTAL or admin.VERTICAL." % label,
hint=None,
obj=cls,
id='admin.E024',
@ -320,7 +320,7 @@ class BaseModelAdminChecks(object):
if not callable(cls.view_on_site) and not isinstance(cls.view_on_site, bool):
return [
checks.Error(
'"view_on_site" is not a callable or a boolean value.',
"The value of 'view_on_site' must be a callable or a boolean value.",
hint=None,
obj=cls,
id='admin.E025',
@ -342,7 +342,7 @@ class BaseModelAdminChecks(object):
else:
return list(chain(*[
self._check_prepopulated_fields_key(cls, model, field_name, 'prepopulated_fields') +
self._check_prepopulated_fields_value(cls, model, val, 'prepopulated_fields[\'%s\']' % field_name)
self._check_prepopulated_fields_value(cls, model, val, 'prepopulated_fields["%s"]' % field_name)
for field_name, val in cls.prepopulated_fields.items()
]))
@ -366,8 +366,8 @@ class BaseModelAdminChecks(object):
if isinstance(field, forbidden_field_types):
return [
checks.Error(
'"%s" refers to "%s", which must not be a DateTimeField, '
'ForeignKey or ManyToManyField.' % (
"The value of '%s' refers to '%s', which must not be a DateTimeField, "
"ForeignKey or ManyToManyField." % (
label, field_name
),
hint=None,
@ -422,8 +422,8 @@ class BaseModelAdminChecks(object):
if field_name == '?' and len(cls.ordering) != 1:
return [
checks.Error(
'"ordering" has the random ordering marker "?", '
'but contains other fields as well.',
("The value of 'ordering' has the random ordering marker '?', "
"but contains other fields as well."),
hint='Either remove the "?", or remove the other fields.',
obj=cls,
id='admin.E032',
@ -473,7 +473,7 @@ class BaseModelAdminChecks(object):
except models.FieldDoesNotExist:
return [
checks.Error(
'"%s" is neither a callable nor an attribute of "%s" nor found in the model %s.%s.' % (
"The value of '%s' is not a callable, an attribute of '%s', or an attribute of '%s.%s'." % (
label, cls.__name__, model._meta.app_label, model._meta.object_name
),
hint=None,
@ -534,23 +534,33 @@ class ModelAdminChecks(BaseModelAdminChecks):
def _check_inlines_item(self, cls, model, inline, label):
""" Check one inline model admin. """
# HACK: This is a nasty hack, but because inlines use the
# RenameBaseModelAdminMethod metaclass, it's almost impossible
# to get the *actual* class name for output purposes.
inline_label = repr(inline)[8:-2]
from django.contrib.admin.options import BaseModelAdmin
if not issubclass(inline, BaseModelAdmin):
return must_inherit_from(parent='BaseModelAdmin', option=label,
obj=cls, id='admin.E104')
return [
checks.Error(
"'%s' must inherit from 'BaseModelAdmin'." % inline_label,
hint=None,
obj=cls,
id='admin.E104',
)
]
elif not inline.model:
return [
checks.Error(
'"model" is a required attribute of "%s".' % label,
"'%s' must have a 'model' attribute." % inline_label,
hint=None,
obj=cls,
id='admin.E105',
)
]
elif not issubclass(inline.model, models.Model):
return must_be('a Model', option='%s.model' % label,
return must_be('a Model', option='%s.model' % inline_label,
obj=cls, id='admin.E106')
else:
return inline.check(model)
@ -585,8 +595,8 @@ class ModelAdminChecks(BaseModelAdminChecks):
if field is None:
return [
checks.Error(
'"%s" refers to "%s" that is neither a field, method nor a property of model %s.%s.' % (
label, item, model._meta.app_label, model._meta.object_name
"The value of '%s' refers to '%s', which is not a callable, an attribute of '%s', or an attribute or method on '%s.%s'." % (
label, item, cls.__name__, model._meta.app_label, model._meta.object_name
),
hint=None,
obj=cls,
@ -596,7 +606,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
elif isinstance(field, models.ManyToManyField):
return [
checks.Error(
'"%s" must not be a ManyToManyField.' % label,
"The value of '%s' must not be a ManyToManyField." % label,
hint=None,
obj=cls,
id='admin.E109',
@ -609,13 +619,15 @@ class ModelAdminChecks(BaseModelAdminChecks):
model._meta.get_field(item)
except models.FieldDoesNotExist:
return [
# This is a deliberate repeat of E108; there's more than one path
# required to test this condition.
checks.Error(
'"%s" is neither a callable nor an attribute of "%s" nor found in model %s.%s.' % (
label, cls.__name__, model._meta.app_label, model._meta.object_name
"The value of '%s' refers to '%s', which is not a callable, an attribute of '%s', or an attribute or method on '%s.%s'." % (
label, item, cls.__name__, model._meta.app_label, model._meta.object_name
),
hint=None,
obj=cls,
id='admin.E110',
id='admin.E108',
)
]
else:
@ -628,7 +640,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
if cls.list_display_links is None:
return []
elif not isinstance(cls.list_display_links, (list, tuple)):
return must_be('a list or tuple or None', option='list_display_links', obj=cls, id='admin.E111')
return must_be('a list, a tuple, or None', option='list_display_links', obj=cls, id='admin.E110')
else:
return list(chain(*[
self._check_list_display_links_item(cls, model, field_name, "list_display_links[%d]" % index)
@ -639,12 +651,12 @@ class ModelAdminChecks(BaseModelAdminChecks):
if field_name not in cls.list_display:
return [
checks.Error(
'"%s" refers to "%s", which is not defined in "list_display".' % (
"The value of '%s' refers to '%s', which is not defined in 'list_display'." % (
label, field_name
),
hint=None,
obj=cls,
id='admin.E112',
id='admin.E111',
)
]
else:
@ -652,7 +664,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
def _check_list_filter(self, cls, model):
if not isinstance(cls.list_filter, (list, tuple)):
return must_be('a list or tuple', option='list_filter', obj=cls, id='admin.E113')
return must_be('a list or tuple', option='list_filter', obj=cls, id='admin.E112')
else:
return list(chain(*[
self._check_list_filter_item(cls, model, item, "list_filter[%d]" % index)
@ -674,15 +686,15 @@ class ModelAdminChecks(BaseModelAdminChecks):
# If item is option 3, it should be a ListFilter...
if not issubclass(item, ListFilter):
return must_inherit_from(parent='ListFilter', option=label,
obj=cls, id='admin.E114')
obj=cls, id='admin.E113')
# ... but not a FieldListFilter.
elif issubclass(item, FieldListFilter):
return [
checks.Error(
'"%s" must not inherit from FieldListFilter.' % label,
"The value of '%s' must not inherit from 'FieldListFilter'." % label,
hint=None,
obj=cls,
id='admin.E115',
id='admin.E114',
)
]
else:
@ -692,7 +704,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
field, list_filter_class = item
if not issubclass(list_filter_class, FieldListFilter):
return must_inherit_from(parent='FieldListFilter', option='%s[1]' % label,
obj=cls, id='admin.E116')
obj=cls, id='admin.E115')
else:
return []
else:
@ -705,10 +717,10 @@ class ModelAdminChecks(BaseModelAdminChecks):
except (NotRelationField, FieldDoesNotExist):
return [
checks.Error(
'"%s" refers to "%s", which does not refer to a Field.' % (label, field),
"The value of '%s' refers to '%s', which does not refer to a Field." % (label, field),
hint=None,
obj=cls,
id='admin.E117',
id='admin.E116',
)
]
else:
@ -719,7 +731,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
if not isinstance(cls.list_select_related, (bool, list, tuple)):
return must_be('a boolean, tuple or list', option='list_select_related',
obj=cls, id='admin.E118')
obj=cls, id='admin.E117')
else:
return []
@ -727,7 +739,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
""" Check that list_per_page is an integer. """
if not isinstance(cls.list_per_page, int):
return must_be('an integer', option='list_per_page', obj=cls, id='admin.E119')
return must_be('an integer', option='list_per_page', obj=cls, id='admin.E118')
else:
return []
@ -735,7 +747,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
""" Check that list_max_show_all is an integer. """
if not isinstance(cls.list_max_show_all, int):
return must_be('an integer', option='list_max_show_all', obj=cls, id='admin.E120')
return must_be('an integer', option='list_max_show_all', obj=cls, id='admin.E119')
else:
return []
@ -744,7 +756,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
list_display without first element. """
if not isinstance(cls.list_editable, (list, tuple)):
return must_be('a list or tuple', option='list_editable', obj=cls, id='admin.E121')
return must_be('a list or tuple', option='list_editable', obj=cls, id='admin.E120')
else:
return list(chain(*[
self._check_list_editable_item(cls, model, item, "list_editable[%d]" % index)
@ -756,41 +768,50 @@ class ModelAdminChecks(BaseModelAdminChecks):
field = model._meta.get_field_by_name(field_name)[0]
except models.FieldDoesNotExist:
return refer_to_missing_field(field=field_name, option=label,
model=model, obj=cls, id='admin.E122')
model=model, obj=cls, id='admin.E121')
else:
if field_name not in cls.list_display:
return refer_to_missing_field(field=field_name, option=label,
model=model, obj=cls, id='admin.E123')
model=model, obj=cls, id='admin.E122')
checks.Error(
"The value of '%s' refers to '%s', which is not contained in 'list_display'." % (
label, field_name
),
hint=None,
obj=cls,
id='admin.E122',
),
elif field_name in cls.list_display_links:
return [
checks.Error(
'"%s" cannot be in both "list_editable" and "list_display_links".' % field_name,
"The value of '%s' cannot be in both 'list_editable' and 'list_display_links'." % field_name,
hint=None,
obj=cls,
id='admin.E124',
id='admin.E123',
)
]
elif not cls.list_display_links and cls.list_display[0] in cls.list_editable:
return [
checks.Error(
'"%s" refers to the first field in list_display ("%s"), '
'which cannot be used unless list_display_links is set.' % (
"The value of '%s' refers to the first field in 'list_display' ('%s'), "
"which cannot be used unless 'list_display_links' is set." % (
label, cls.list_display[0]
),
hint=None,
obj=cls,
id='admin.E125',
id='admin.E124',
)
]
elif not field.editable:
return [
checks.Error(
'"%s" refers to field "%s", which is not editable through the admin.' % (
"The value of '%s' refers to '%s', which is not editable through the admin." % (
label, field_name
),
hint=None,
obj=cls,
id='admin.E126',
id='admin.E125',
)
]
else:
@ -800,7 +821,7 @@ class ModelAdminChecks(BaseModelAdminChecks):
""" Check search_fields is a sequence. """
if not isinstance(cls.search_fields, (list, tuple)):
return must_be('a list or tuple', option='search_fields', obj=cls, id='admin.E127')
return must_be('a list or tuple', option='search_fields', obj=cls, id='admin.E126')
else:
return []
@ -815,11 +836,11 @@ class ModelAdminChecks(BaseModelAdminChecks):
except models.FieldDoesNotExist:
return refer_to_missing_field(option='date_hierarchy',
field=cls.date_hierarchy,
model=model, obj=cls, id='admin.E128')
model=model, obj=cls, id='admin.E127')
else:
if not isinstance(field, (models.DateField, models.DateTimeField)):
return must_be('a DateField or DateTimeField', option='date_hierarchy',
obj=cls, id='admin.E129')
obj=cls, id='admin.E128')
else:
return []
@ -853,8 +874,8 @@ class InlineModelAdminChecks(BaseModelAdminChecks):
if fk.name in cls.exclude:
return [
checks.Error(
'Cannot exclude the field "%s", because it is the foreign key '
'to the parent model %s.%s.' % (
"Cannot exclude the field '%s', because it is the foreign key "
"to the parent model '%s.%s'." % (
fk.name, parent_model._meta.app_label, parent_model._meta.object_name
),
hint=None,
@ -904,7 +925,7 @@ class InlineModelAdminChecks(BaseModelAdminChecks):
def must_be(type, option, obj, id):
return [
checks.Error(
'"%s" must be %s.' % (option, type),
"The value of '%s' must be %s." % (option, type),
hint=None,
obj=obj,
id=id,
@ -915,7 +936,7 @@ def must_be(type, option, obj, id):
def must_inherit_from(parent, option, obj, id):
return [
checks.Error(
'"%s" must inherit from %s.' % (option, parent),
"The value of '%s' must inherit from '%s'." % (option, parent),
hint=None,
obj=obj,
id=id,
@ -926,7 +947,7 @@ def must_inherit_from(parent, option, obj, id):
def refer_to_missing_field(field, option, model, obj, id):
return [
checks.Error(
'"%s" refers to field "%s", which is missing from model %s.%s.' % (
"The value of '%s' refers to '%s', which is not an attribute of '%s.%s'." % (
option, field, model._meta.app_label, model._meta.object_name
),
hint=None,

View File

@ -63,11 +63,11 @@ class SystemChecksTestCase(TestCase):
errors = SongAdmin.check(model=Song)
expected = [
checks.Error(
('"list_editable[0]" refers to field "original_release", '
'which is not editable through the admin.'),
("The value of 'list_editable[0]' refers to 'original_release', "
"which is not editable through the admin."),
hint=None,
obj=SongAdmin,
id='admin.E126',
id='admin.E125',
)
]
self.assertEqual(errors, expected)
@ -114,7 +114,7 @@ class SystemChecksTestCase(TestCase):
errors = ExcludedFields1.check(model=Book)
expected = [
checks.Error(
'"exclude" must be a list or tuple.',
"The value of 'exclude' must be a list or tuple.",
hint=None,
obj=ExcludedFields1,
id='admin.E014',
@ -129,7 +129,7 @@ class SystemChecksTestCase(TestCase):
errors = ExcludedFields2.check(model=Book)
expected = [
checks.Error(
'"exclude" contains duplicate field(s).',
"The value of 'exclude' contains duplicate field(s).",
hint=None,
obj=ExcludedFields2,
id='admin.E015',
@ -149,7 +149,7 @@ class SystemChecksTestCase(TestCase):
errors = ExcludedFieldsAlbumAdmin.check(model=Album)
expected = [
checks.Error(
'"exclude" must be a list or tuple.',
"The value of 'exclude' must be a list or tuple.",
hint=None,
obj=ExcludedFieldsInline,
id='admin.E014',
@ -174,8 +174,8 @@ class SystemChecksTestCase(TestCase):
errors = AlbumAdmin.check(model=Album)
expected = [
checks.Error(
('Cannot exclude the field "album", because it is the foreign key '
'to the parent model admin_checks.Album.'),
("Cannot exclude the field 'album', because it is the foreign key "
"to the parent model 'admin_checks.Album'."),
hint=None,
obj=SongInline,
id='admin.E201',
@ -194,8 +194,8 @@ class SystemChecksTestCase(TestCase):
errors = RawIdNonexistingAdmin.check(model=Album)
expected = [
checks.Error(
('"raw_id_fields[0]" refers to field "nonexisting", which is '
'missing from model admin_checks.Album.'),
("The value of 'raw_id_fields[0]' refers to 'nonexisting', which is "
"not an attribute of 'admin_checks.Album'."),
hint=None,
obj=RawIdNonexistingAdmin,
id='admin.E002',
@ -291,8 +291,8 @@ class SystemChecksTestCase(TestCase):
errors = SongAdmin.check(model=Song)
expected = [
checks.Error(
('"readonly_fields[1]" is neither a callable nor an attribute '
'of "SongAdmin" nor found in the model admin_checks.Song.'),
("The value of 'readonly_fields[1]' is not a callable, an attribute "
"of 'SongAdmin', or an attribute of 'admin_checks.Song'."),
hint=None,
obj=SongAdmin,
id='admin.E035',
@ -308,8 +308,8 @@ class SystemChecksTestCase(TestCase):
errors = CityInline.check(State)
expected = [
checks.Error(
('"readonly_fields[0]" is neither a callable nor an attribute '
'of "CityInline" nor found in the model admin_checks.City.'),
("The value of 'readonly_fields[0]' is not a callable, an attribute "
"of 'CityInline', or an attribute of 'admin_checks.City'."),
hint=None,
obj=CityInline,
id='admin.E035',
@ -347,8 +347,8 @@ class SystemChecksTestCase(TestCase):
errors = BookAdmin.check(model=Book)
expected = [
checks.Error(
('"fields" cannot include the ManyToManyField "authors", '
'because "authors" manually specifies relationship model.'),
("The value of 'fields' cannot include the ManyToManyField 'authors', "
"because that field manually specifies a relationship model."),
hint=None,
obj=BookAdmin,
id='admin.E013',
@ -366,8 +366,8 @@ class SystemChecksTestCase(TestCase):
errors = FieldsetBookAdmin.check(model=Book)
expected = [
checks.Error(
('"fieldsets[1][1][\'fields\']" cannot include the ManyToManyField '
'"authors", because "authors" manually specifies relationship model.'),
("The value of 'fieldsets[1][1][\"fields\"]' cannot include the ManyToManyField "
"'authors', because that field manually specifies a relationship model."),
hint=None,
obj=FieldsetBookAdmin,
id='admin.E013',
@ -471,7 +471,7 @@ class SystemChecksTestCase(TestCase):
errors = MyModelAdmin.check(model=Song)
expected = [
checks.Error(
'There are duplicate field(s) in "fields".',
"The value of 'fields' contains duplicate field(s).",
hint=None,
obj=MyModelAdmin,
id='admin.E006'
@ -490,7 +490,7 @@ class SystemChecksTestCase(TestCase):
errors = MyModelAdmin.check(model=Song)
expected = [
checks.Error(
'There are duplicate field(s) in "fieldsets[0][1]".',
"There are duplicate field(s) in 'fieldsets[0][1]'.",
hint=None,
obj=MyModelAdmin,
id='admin.E012'

View File

@ -4687,7 +4687,7 @@ class AdminViewOnSiteTests(TestCase):
CityAdmin.view_on_site = []
self.assertEqual(CityAdmin.check(City), [
Error(
'"view_on_site" is not a callable or a boolean value.',
"The value of 'view_on_site' must be a callable or a boolean value.",
hint=None,
obj=CityAdmin,
id='admin.E025',

View File

@ -566,7 +566,7 @@ class RawIdCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"raw_id_fields" must be a list or tuple.',
"The value of 'raw_id_fields' must be a list or tuple.",
'admin.E001')
def test_missing_field(self):
@ -575,8 +575,8 @@ class RawIdCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
('"raw_id_fields[0]" refers to field "non_existent_field", '
'which is missing from model modeladmin.ValidationTestModel.'),
("The value of 'raw_id_fields[0]' refers to 'non_existent_field', "
"which is not an attribute of 'modeladmin.ValidationTestModel'."),
'admin.E002')
def test_invalid_field_type(self):
@ -585,7 +585,7 @@ class RawIdCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"raw_id_fields[0]" must be a ForeignKey or ManyToManyField.',
"The value of 'raw_id_fields[0]' must be a ForeignKey or ManyToManyField.",
'admin.E003')
def test_valid_case(self):
@ -599,7 +599,7 @@ class FieldsetsCheckTests(CheckTestCase):
def test_valid_case(self):
class ValidationTestModelAdmin(ModelAdmin):
fieldsets = (("General", {"fields": ("name",)}),)
fieldsets = (("General", {'fields': ('name',)}),)
self.assertIsValid(ValidationTestModelAdmin, ValidationTestModel)
@ -610,7 +610,7 @@ class FieldsetsCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"fieldsets" must be a list or tuple.',
"The value of 'fieldsets' must be a list or tuple.",
'admin.E007')
def test_non_iterable_item(self):
@ -619,7 +619,7 @@ class FieldsetsCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"fieldsets[0]" must be a list or tuple.',
"The value of 'fieldsets[0]' must be a list or tuple.",
'admin.E008')
def test_item_not_a_pair(self):
@ -628,7 +628,7 @@ class FieldsetsCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"fieldsets[0]" must be a pair.',
"The value of 'fieldsets[0]' must be of length 2.",
'admin.E009')
def test_second_element_of_item_not_a_dict(self):
@ -637,7 +637,7 @@ class FieldsetsCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"fieldsets[0][1]" must be a dictionary.',
"The value of 'fieldsets[0][1]' must be a dictionary.",
'admin.E010')
def test_missing_fields_key(self):
@ -646,22 +646,22 @@ class FieldsetsCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"fieldsets[0][1]" must contain "fields" key.',
"The value of 'fieldsets[0][1]' must contain the key 'fields'.",
'admin.E011')
class ValidationTestModelAdmin(ModelAdmin):
fieldsets = (("General", {"fields": ("name",)}),)
fieldsets = (("General", {'fields': ('name',)}),)
self.assertIsValid(ValidationTestModelAdmin, ValidationTestModel)
def test_specified_both_fields_and_fieldsets(self):
class ValidationTestModelAdmin(ModelAdmin):
fieldsets = (("General", {"fields": ("name",)}),)
fields = ["name"]
fieldsets = (("General", {'fields': ('name',)}),)
fields = ['name']
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'Both "fieldsets" and "fields" are specified.',
"Both 'fieldsets' and 'fields' are specified.",
'admin.E005')
def test_duplicate_fields(self):
@ -670,7 +670,7 @@ class FieldsetsCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'There are duplicate field(s) in "fieldsets[0][1]".',
"There are duplicate field(s) in 'fieldsets[0][1]'.",
'admin.E012')
def test_fieldsets_with_custom_form_validation(self):
@ -688,11 +688,11 @@ class FieldsCheckTests(CheckTestCase):
def test_duplicate_fields_in_fields(self):
class ValidationTestModelAdmin(ModelAdmin):
fields = ["name", "name"]
fields = ['name', 'name']
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'There are duplicate field(s) in "fields".',
"The value of 'fields' contains duplicate field(s).",
'admin.E006')
def test_inline(self):
@ -705,7 +705,7 @@ class FieldsCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"fields" must be a list or tuple.',
"The value of 'fields' must be a list or tuple.",
'admin.E004',
invalid_obj=ValidationTestInline)
@ -721,7 +721,7 @@ class FormCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"form" must inherit from BaseModelForm.',
"The value of 'form' must inherit from 'BaseModelForm'.",
'admin.E016')
def test_fieldsets_with_custom_form_validation(self):
@ -759,26 +759,26 @@ class FilterVerticalCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"filter_vertical" must be a list or tuple.',
"The value of 'filter_vertical' must be a list or tuple.",
'admin.E017')
def test_missing_field(self):
class ValidationTestModelAdmin(ModelAdmin):
filter_vertical = ("non_existent_field",)
filter_vertical = ('non_existent_field',)
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
('"filter_vertical[0]" refers to field "non_existent_field", '
'which is missing from model modeladmin.ValidationTestModel.'),
("The value of 'filter_vertical[0]' refers to 'non_existent_field', "
"which is not an attribute of 'modeladmin.ValidationTestModel'."),
'admin.E019')
def test_invalid_field_type(self):
class ValidationTestModelAdmin(ModelAdmin):
filter_vertical = ("name",)
filter_vertical = ('name',)
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"filter_vertical[0]" must be a ManyToManyField.',
"The value of 'filter_vertical[0]' must be a ManyToManyField.",
'admin.E020')
def test_valid_case(self):
@ -796,26 +796,26 @@ class FilterHorizontalCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"filter_horizontal" must be a list or tuple.',
"The value of 'filter_horizontal' must be a list or tuple.",
'admin.E018')
def test_missing_field(self):
class ValidationTestModelAdmin(ModelAdmin):
filter_horizontal = ("non_existent_field",)
filter_horizontal = ('non_existent_field',)
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
('"filter_horizontal[0]" refers to field "non_existent_field", '
'which is missing from model modeladmin.ValidationTestModel.'),
("The value of 'filter_horizontal[0]' refers to 'non_existent_field', "
"which is not an attribute of 'modeladmin.ValidationTestModel'."),
'admin.E019')
def test_invalid_field_type(self):
class ValidationTestModelAdmin(ModelAdmin):
filter_horizontal = ("name",)
filter_horizontal = ('name',)
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"filter_horizontal[0]" must be a ManyToManyField.',
"The value of 'filter_horizontal[0]' must be a ManyToManyField.",
'admin.E020')
def test_valid_case(self):
@ -834,27 +834,27 @@ class RadioFieldsCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"radio_fields" must be a dictionary.',
"The value of 'radio_fields' must be a dictionary.",
'admin.E021')
def test_missing_field(self):
class ValidationTestModelAdmin(ModelAdmin):
radio_fields = {"non_existent_field": VERTICAL}
radio_fields = {'non_existent_field': VERTICAL}
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
('"radio_fields" refers to field "non_existent_field", '
'which is missing from model modeladmin.ValidationTestModel.'),
("The value of 'radio_fields' refers to 'non_existent_field', "
"which is not an attribute of 'modeladmin.ValidationTestModel'."),
'admin.E022')
def test_invalid_field_type(self):
class ValidationTestModelAdmin(ModelAdmin):
radio_fields = {"name": VERTICAL}
radio_fields = {'name': VERTICAL}
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
('"radio_fields" refers to "name", which is neither an instance '
'of ForeignKey nor does have choices set.'),
("The value of 'radio_fields' refers to 'name', which is not an instance "
"of ForeignKey, and does not have a 'choices' definition."),
'admin.E023')
def test_invalid_value(self):
@ -863,7 +863,7 @@ class RadioFieldsCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"radio_fields[\'state\']" is neither admin.HORIZONTAL nor admin.VERTICAL.',
"The value of 'radio_fields[\"state\"]' must be either admin.HORIZONTAL or admin.VERTICAL.",
'admin.E024')
def test_valid_case(self):
@ -882,42 +882,42 @@ class PrepopulatedFieldsCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"prepopulated_fields" must be a dictionary.',
"The value of 'prepopulated_fields' must be a dictionary.",
'admin.E026')
def test_missing_field(self):
class ValidationTestModelAdmin(ModelAdmin):
prepopulated_fields = {"non_existent_field": ("slug",)}
prepopulated_fields = {'non_existent_field': ("slug",)}
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
('"prepopulated_fields" refers to field "non_existent_field", '
'which is missing from model modeladmin.ValidationTestModel.'),
("The value of 'prepopulated_fields' refers to 'non_existent_field', "
"which is not an attribute of 'modeladmin.ValidationTestModel'."),
'admin.E027')
def test_missing_field_again(self):
class ValidationTestModelAdmin(ModelAdmin):
prepopulated_fields = {"slug": ("non_existent_field",)}
prepopulated_fields = {"slug": ('non_existent_field',)}
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
('"prepopulated_fields[\'slug\'][0]" refers to field "non_existent_field", '
'which is missing from model modeladmin.ValidationTestModel.'),
("The value of 'prepopulated_fields[\"slug\"][0]' refers to 'non_existent_field', "
"which is not an attribute of 'modeladmin.ValidationTestModel'."),
'admin.E030')
def test_invalid_field_type(self):
class ValidationTestModelAdmin(ModelAdmin):
prepopulated_fields = {"users": ("name",)}
prepopulated_fields = {"users": ('name',)}
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
('"prepopulated_fields" refers to "users", which must not be '
'a DateTimeField, ForeignKey or ManyToManyField.'),
("The value of 'prepopulated_fields' refers to 'users', which must not be "
"a DateTimeField, ForeignKey or ManyToManyField."),
'admin.E028')
def test_valid_case(self):
class ValidationTestModelAdmin(ModelAdmin):
prepopulated_fields = {"slug": ("name",)}
prepopulated_fields = {"slug": ('name',)}
self.assertIsValid(ValidationTestModelAdmin, ValidationTestModel)
@ -931,7 +931,7 @@ class ListDisplayTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"list_display" must be a list or tuple.',
"The value of 'list_display' must be a list or tuple.",
'admin.E107')
def test_missing_field(self):
@ -940,9 +940,9 @@ class ListDisplayTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
('"list_display[0]" is neither a callable nor an attribute '
'of "ValidationTestModelAdmin" nor found in model modeladmin.ValidationTestModel.'),
'admin.E110')
("The value of 'list_display[0]' refers to 'non_existent_field', which is not a callable, an attribute "
"of 'ValidationTestModelAdmin', or an attribute or method on 'modeladmin.ValidationTestModel'."),
'admin.E108')
def test_invalid_field_type(self):
class ValidationTestModelAdmin(ModelAdmin):
@ -950,7 +950,7 @@ class ListDisplayTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"list_display[0]" must not be a ManyToManyField.',
"The value of 'list_display[0]' must not be a ManyToManyField.",
'admin.E109')
def test_valid_case(self):
@ -973,8 +973,8 @@ class ListDisplayLinksCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"list_display_links" must be a list or tuple or None.',
'admin.E111')
"The value of 'list_display_links' must be a list, a tuple, or None.",
'admin.E110')
def test_missing_field(self):
class ValidationTestModelAdmin(ModelAdmin):
@ -982,8 +982,8 @@ class ListDisplayLinksCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"list_display_links[0]" refers to "non_existent_field", which is not defined in "list_display".',
'admin.E112')
"The value of 'list_display_links[0]' refers to 'non_existent_field', which is not defined in 'list_display'.",
'admin.E111')
def test_missing_in_list_display(self):
class ValidationTestModelAdmin(ModelAdmin):
@ -991,8 +991,8 @@ class ListDisplayLinksCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"list_display_links[0]" refers to "name", which is not defined in "list_display".',
'admin.E112')
"The value of 'list_display_links[0]' refers to 'name', which is not defined in 'list_display'.",
'admin.E111')
def test_valid_case(self):
def a_callable(obj):
@ -1021,8 +1021,8 @@ class ListFilterTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"list_filter" must be a list or tuple.',
'admin.E113')
"The value of 'list_filter' must be a list or tuple.",
'admin.E112')
def test_missing_field(self):
class ValidationTestModelAdmin(ModelAdmin):
@ -1030,8 +1030,8 @@ class ListFilterTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"list_filter[0]" refers to "non_existent_field", which does not refer to a Field.',
'admin.E117')
"The value of 'list_filter[0]' refers to 'non_existent_field', which does not refer to a Field.",
'admin.E116')
def test_not_filter(self):
class RandomClass(object):
@ -1042,8 +1042,8 @@ class ListFilterTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"list_filter[0]" must inherit from ListFilter.',
'admin.E114')
"The value of 'list_filter[0]' must inherit from 'ListFilter'.",
'admin.E113')
def test_not_filter_again(self):
class RandomClass(object):
@ -1054,8 +1054,8 @@ class ListFilterTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"list_filter[0][1]" must inherit from FieldListFilter.',
'admin.E116')
"The value of 'list_filter[0][1]' must inherit from 'FieldListFilter'.",
'admin.E115')
def test_not_filter_again_again(self):
class AwesomeFilter(SimpleListFilter):
@ -1073,8 +1073,8 @@ class ListFilterTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"list_filter[0][1]" must inherit from FieldListFilter.',
'admin.E116')
"The value of 'list_filter[0][1]' must inherit from 'FieldListFilter'.",
'admin.E115')
def test_not_associated_with_field_name(self):
class ValidationTestModelAdmin(ModelAdmin):
@ -1082,8 +1082,8 @@ class ListFilterTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"list_filter[0]" must not inherit from FieldListFilter.',
'admin.E115')
"The value of 'list_filter[0]' must not inherit from 'FieldListFilter'.",
'admin.E114')
def test_valid_case(self):
class AwesomeFilter(SimpleListFilter):
@ -1110,8 +1110,8 @@ class ListPerPageCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"list_per_page" must be an integer.',
'admin.E119')
"The value of 'list_per_page' must be an integer.",
'admin.E118')
def test_valid_case(self):
class ValidationTestModelAdmin(ModelAdmin):
@ -1128,8 +1128,8 @@ class ListMaxShowAllCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"list_max_show_all" must be an integer.',
'admin.E120')
"The value of 'list_max_show_all' must be an integer.",
'admin.E119')
def test_valid_case(self):
class ValidationTestModelAdmin(ModelAdmin):
@ -1147,8 +1147,8 @@ class SearchFieldsCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"search_fields" must be a list or tuple.',
'admin.E127')
"The value of 'search_fields' must be a list or tuple.",
'admin.E126')
class DateHierarchyCheckTests(CheckTestCase):
@ -1160,9 +1160,9 @@ class DateHierarchyCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
('"date_hierarchy" refers to field "non_existent_field", which '
'is missing from model modeladmin.ValidationTestModel.'),
'admin.E128')
("The value of 'date_hierarchy' refers to 'non_existent_field', which "
"is not an attribute of 'modeladmin.ValidationTestModel'."),
'admin.E127')
def test_invalid_field_type(self):
class ValidationTestModelAdmin(ModelAdmin):
@ -1170,8 +1170,8 @@ class DateHierarchyCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"date_hierarchy" must be a DateField or DateTimeField.',
'admin.E129')
"The value of 'date_hierarchy' must be a DateField or DateTimeField.",
'admin.E128')
def test_valid_case(self):
class ValidationTestModelAdmin(ModelAdmin):
@ -1188,7 +1188,7 @@ class OrderingCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"ordering" must be a list or tuple.',
"The value of 'ordering' must be a list or tuple.",
'admin.E031')
class ValidationTestModelAdmin(ModelAdmin):
@ -1197,7 +1197,7 @@ class OrderingCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin,
ValidationTestModel,
'"ordering[0]" refers to field "non_existent_field", which is missing from model modeladmin.ValidationTestModel.',
"The value of 'ordering[0]' refers to 'non_existent_field', which is not an attribute of 'modeladmin.ValidationTestModel'.",
'admin.E033',
)
@ -1207,8 +1207,8 @@ class OrderingCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
('"ordering" has the random ordering marker "?", but contains '
'other fields as well.'),
("The value of 'ordering' has the random ordering marker '?', but contains "
"other fields as well."),
'admin.E032',
hint='Either remove the "?", or remove the other fields.')
@ -1238,8 +1238,8 @@ class ListSelectRelatedCheckTests(CheckTestCase):
list_select_related = 1
self.assertIsInvalid(ValidationTestModelAdmin, ValidationTestModel,
'"list_select_related" must be a boolean, tuple or list.',
'admin.E118')
"The value of 'list_select_related' must be a boolean, tuple or list.",
'admin.E117')
def test_valid_case(self):
class ValidationTestModelAdmin(ModelAdmin):
@ -1256,7 +1256,7 @@ class SaveAsCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"save_as" must be a boolean.',
"The value of 'save_as' must be a boolean.",
'admin.E101')
def test_valid_case(self):
@ -1274,7 +1274,7 @@ class SaveOnTopCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"save_on_top" must be a boolean.',
"The value of 'save_on_top' must be a boolean.",
'admin.E102')
def test_valid_case(self):
@ -1292,7 +1292,7 @@ class InlinesCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"inlines" must be a list or tuple.',
"The value of 'inlines' must be a list or tuple.",
'admin.E103')
def test_not_model_admin(self):
@ -1304,7 +1304,7 @@ class InlinesCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"inlines[0]" must inherit from BaseModelAdmin.',
"'modeladmin.tests.ValidationTestInline' must inherit from 'BaseModelAdmin'.",
'admin.E104')
def test_missing_model_field(self):
@ -1316,7 +1316,7 @@ class InlinesCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"model" is a required attribute of "inlines[0]".',
"'modeladmin.tests.ValidationTestInline' must have a 'model' attribute.",
'admin.E105')
def test_invalid_model_type(self):
@ -1334,7 +1334,7 @@ class InlinesCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"inlines[0].model" must be a Model.',
"The value of 'modeladmin.tests.ValidationTestInline.model' must be a Model.",
'admin.E106')
def test_valid_case(self):
@ -1352,7 +1352,7 @@ class FkNameCheckTests(CheckTestCase):
def test_missing_field(self):
class ValidationTestInline(TabularInline):
model = ValidationTestInlineModel
fk_name = "non_existent_field"
fk_name = 'non_existent_field'
class ValidationTestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
@ -1386,7 +1386,7 @@ class ExtraCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"extra" must be an integer.',
"The value of 'extra' must be an integer.",
'admin.E203',
invalid_obj=ValidationTestInline)
@ -1413,7 +1413,7 @@ class MaxNumCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"max_num" must be an integer.',
"The value of 'max_num' must be an integer.",
'admin.E204',
invalid_obj=ValidationTestInline)
@ -1443,7 +1443,7 @@ class FormsetCheckTests(CheckTestCase):
self.assertIsInvalid(
ValidationTestModelAdmin, ValidationTestModel,
'"formset" must inherit from BaseModelFormSet.',
"The value of 'formset' must inherit from 'BaseModelFormSet'.",
'admin.E205',
invalid_obj=ValidationTestInline)