Fixed #15669 -- Included app label in admin validation messages. Thanks, lamby and Jure Cuhalev.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16462 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2011-06-26 16:52:31 +00:00
parent b9eb94e789
commit e0139910f1
3 changed files with 29 additions and 17 deletions

View File

@ -104,8 +104,8 @@ def validate(cls, model):
field = opts.get_field_by_name(field_name)[0] field = opts.get_field_by_name(field_name)[0]
except models.FieldDoesNotExist: except models.FieldDoesNotExist:
raise ImproperlyConfigured("'%s.list_editable[%d]' refers to a " raise ImproperlyConfigured("'%s.list_editable[%d]' refers to a "
"field, '%s', not defined on %s." "field, '%s', not defined on %s.%s."
% (cls.__name__, idx, field_name, model.__name__)) % (cls.__name__, idx, field_name, model._meta.app_label, model.__name__))
if field_name not in cls.list_display: if field_name not in cls.list_display:
raise ImproperlyConfigured("'%s.list_editable[%d]' refers to " raise ImproperlyConfigured("'%s.list_editable[%d]' refers to "
"'%s' which is not defined in 'list_display'." "'%s' which is not defined in 'list_display'."
@ -215,7 +215,7 @@ def validate_inline(cls, parent, parent_model):
if fk and fk.name in cls.exclude: if fk and fk.name in cls.exclude:
raise ImproperlyConfigured("%s cannot exclude the field " raise ImproperlyConfigured("%s cannot exclude the field "
"'%s' - this is the foreign key to the parent model " "'%s' - this is the foreign key to the parent model "
"%s." % (cls.__name__, fk.name, parent_model.__name__)) "%s.%s." % (cls.__name__, fk.name, parent_model._meta.app_label, parent_model.__name__))
if hasattr(cls, "readonly_fields"): if hasattr(cls, "readonly_fields"):
check_readonly_fields(cls, cls.model, cls.model._meta) check_readonly_fields(cls, cls.model, cls.model._meta)
@ -372,8 +372,8 @@ def get_field(cls, model, opts, label, field):
try: try:
return opts.get_field(field) return opts.get_field(field)
except models.FieldDoesNotExist: except models.FieldDoesNotExist:
raise ImproperlyConfigured("'%s.%s' refers to field '%s' that is missing from model '%s'." raise ImproperlyConfigured("'%s.%s' refers to field '%s' that is missing from model '%s.%s'."
% (cls.__name__, label, field, model.__name__)) % (cls.__name__, label, field, model._meta.app_label, model.__name__))
def check_formfield(cls, model, opts, label, field): def check_formfield(cls, model, opts, label, field):
if getattr(cls.form, 'base_fields', None): if getattr(cls.form, 'base_fields', None):
@ -398,8 +398,8 @@ def fetch_attr(cls, model, opts, label, field):
try: try:
return getattr(model, field) return getattr(model, field)
except AttributeError: except AttributeError:
raise ImproperlyConfigured("'%s.%s' refers to '%s' that is neither a field, method or property of model '%s'." raise ImproperlyConfigured("'%s.%s' refers to '%s' that is neither a field, method or property of model '%s.%s'."
% (cls.__name__, label, field, model.__name__)) % (cls.__name__, label, field, model._meta.app_label, model.__name__))
def check_readonly_fields(cls, model, opts): def check_readonly_fields(cls, model, opts):
check_isseq(cls, "readonly_fields", cls.readonly_fields) check_isseq(cls, "readonly_fields", cls.readonly_fields)

View File

@ -92,10 +92,22 @@ class ValidationTestCase(TestCase):
inlines = [SongInline] inlines = [SongInline]
self.assertRaisesMessage(ImproperlyConfigured, self.assertRaisesMessage(ImproperlyConfigured,
"SongInline cannot exclude the field 'album' - this is the foreign key to the parent model Album.", "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model admin_validation.Album.",
validate, validate,
AlbumAdmin, Album) AlbumAdmin, Album)
def test_app_label_in_admin_validation(self):
"""
Regression test for #15669 - Include app label in admin validation messages
"""
class RawIdNonexistingAdmin(admin.ModelAdmin):
raw_id_fields = ('nonexisting',)
self.assertRaisesMessage(ImproperlyConfigured,
"'RawIdNonexistingAdmin.raw_id_fields' refers to field 'nonexisting' that is missing from model 'admin_validation.Album'.",
validate,
RawIdNonexistingAdmin, Album)
def test_fk_exclusion(self): def test_fk_exclusion(self):
""" """
Regression test for #11709 - when testing for fk excluding (when exclude is Regression test for #11709 - when testing for fk excluding (when exclude is

View File

@ -403,7 +403,7 @@ class ValidationTests(unittest.TestCase):
self.assertRaisesRegexp( self.assertRaisesRegexp(
ImproperlyConfigured, ImproperlyConfigured,
"'ValidationTestModelAdmin.raw_id_fields' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.", "'ValidationTestModelAdmin.raw_id_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate, validate,
ValidationTestModelAdmin, ValidationTestModelAdmin,
ValidationTestModel, ValidationTestModel,
@ -631,7 +631,7 @@ class ValidationTests(unittest.TestCase):
self.assertRaisesRegexp( self.assertRaisesRegexp(
ImproperlyConfigured, ImproperlyConfigured,
"'ValidationTestModelAdmin.filter_vertical' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.", "'ValidationTestModelAdmin.filter_vertical' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate, validate,
ValidationTestModelAdmin, ValidationTestModelAdmin,
ValidationTestModel, ValidationTestModel,
@ -671,7 +671,7 @@ class ValidationTests(unittest.TestCase):
self.assertRaisesRegexp( self.assertRaisesRegexp(
ImproperlyConfigured, ImproperlyConfigured,
"'ValidationTestModelAdmin.filter_horizontal' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.", "'ValidationTestModelAdmin.filter_horizontal' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate, validate,
ValidationTestModelAdmin, ValidationTestModelAdmin,
ValidationTestModel, ValidationTestModel,
@ -711,7 +711,7 @@ class ValidationTests(unittest.TestCase):
self.assertRaisesRegexp( self.assertRaisesRegexp(
ImproperlyConfigured, ImproperlyConfigured,
"'ValidationTestModelAdmin.radio_fields' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.", "'ValidationTestModelAdmin.radio_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate, validate,
ValidationTestModelAdmin, ValidationTestModelAdmin,
ValidationTestModel, ValidationTestModel,
@ -762,7 +762,7 @@ class ValidationTests(unittest.TestCase):
self.assertRaisesRegexp( self.assertRaisesRegexp(
ImproperlyConfigured, ImproperlyConfigured,
"'ValidationTestModelAdmin.prepopulated_fields' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.", "'ValidationTestModelAdmin.prepopulated_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate, validate,
ValidationTestModelAdmin, ValidationTestModelAdmin,
ValidationTestModel, ValidationTestModel,
@ -773,7 +773,7 @@ class ValidationTests(unittest.TestCase):
self.assertRaisesRegexp( self.assertRaisesRegexp(
ImproperlyConfigured, ImproperlyConfigured,
"'ValidationTestModelAdmin.prepopulated_fields\['slug'\]\[0\]' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.", "'ValidationTestModelAdmin.prepopulated_fields\['slug'\]\[0\]' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate, validate,
ValidationTestModelAdmin, ValidationTestModelAdmin,
ValidationTestModel, ValidationTestModel,
@ -1010,7 +1010,7 @@ class ValidationTests(unittest.TestCase):
self.assertRaisesRegexp( self.assertRaisesRegexp(
ImproperlyConfigured, ImproperlyConfigured,
"'ValidationTestModelAdmin.date_hierarchy' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.", "'ValidationTestModelAdmin.date_hierarchy' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate, validate,
ValidationTestModelAdmin, ValidationTestModelAdmin,
ValidationTestModel, ValidationTestModel,
@ -1050,7 +1050,7 @@ class ValidationTests(unittest.TestCase):
self.assertRaisesRegexp( self.assertRaisesRegexp(
ImproperlyConfigured, ImproperlyConfigured,
"'ValidationTestModelAdmin.ordering\[0\]' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.", "'ValidationTestModelAdmin.ordering\[0\]' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate, validate,
ValidationTestModelAdmin, ValidationTestModelAdmin,
ValidationTestModel, ValidationTestModel,
@ -1245,7 +1245,7 @@ class ValidationTests(unittest.TestCase):
self.assertRaisesRegexp( self.assertRaisesRegexp(
ImproperlyConfigured, ImproperlyConfigured,
"'ValidationTestInline.fk_name' refers to field 'non_existent_field' that is missing from model 'ValidationTestInlineModel'.", "'ValidationTestInline.fk_name' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestInlineModel'.",
validate, validate,
ValidationTestModelAdmin, ValidationTestModelAdmin,
ValidationTestModel, ValidationTestModel,