Ticket #15669: ticket15669_2.diff

File ticket15669_2.diff, 8.9 KB (added by Jure Cuhalev <gandalf@…>, 13 years ago)

Updated patch so that modeladmin tests also pass. I also tried approach suggested by Alex and abandoned it because unicode() repr of model lowercases the model, making it harder to grep for errors.

  • django/contrib/admin/validation.py

    diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py
    index 58a8490..9a0c948 100644
    a b def validate(cls, model):  
    104104                field = opts.get_field_by_name(field_name)[0]
    105105            except models.FieldDoesNotExist:
    106106                raise ImproperlyConfigured("'%s.list_editable[%d]' refers to a "
    107                     "field, '%s', not defined on %s."
    108                     % (cls.__name__, idx, field_name, model.__name__))
     107                    "field, '%s', not defined on %s.%s."
     108                    % (cls.__name__, idx, field_name, model._meta.app_label, model.__name__))
    109109            if field_name not in cls.list_display:
    110110                raise ImproperlyConfigured("'%s.list_editable[%d]' refers to "
    111111                    "'%s' which is not defined in 'list_display'."
    def validate_inline(cls, parent, parent_model):  
    215215        if fk and fk.name in cls.exclude:
    216216            raise ImproperlyConfigured("%s cannot exclude the field "
    217217                    "'%s' - this is the foreign key to the parent model "
    218                     "%s." % (cls.__name__, fk.name, parent_model.__name__))
     218                    "%s.%s." % (cls.__name__, fk.name, parent_model._meta.app_label, parent_model.__name__))
    219219
    220220    if hasattr(cls, "readonly_fields"):
    221221        check_readonly_fields(cls, cls.model, cls.model._meta)
    def get_field(cls, model, opts, label, field):  
    372372    try:
    373373        return opts.get_field(field)
    374374    except models.FieldDoesNotExist:
    375         raise ImproperlyConfigured("'%s.%s' refers to field '%s' that is missing from model '%s'."
    376                 % (cls.__name__, label, field, model.__name__))
     375        raise ImproperlyConfigured("'%s.%s' refers to field '%s' that is missing from model '%s.%s'."
     376                % (cls.__name__, label, field, model._meta.app_label, model.__name__))
    377377
    378378def check_formfield(cls, model, opts, label, field):
    379379    if getattr(cls.form, 'base_fields', None):
    def fetch_attr(cls, model, opts, label, field):  
    398398    try:
    399399        return getattr(model, field)
    400400    except AttributeError:
    401         raise ImproperlyConfigured("'%s.%s' refers to '%s' that is neither a field, method or property of model '%s'."
    402             % (cls.__name__, label, field, model.__name__))
     401        raise ImproperlyConfigured("'%s.%s' refers to '%s' that is neither a field, method or property of model '%s.%s'."
     402            % (cls.__name__, label, field, model._meta.app_label, model.__name__))
    403403
    404404def check_readonly_fields(cls, model, opts):
    405405    check_isseq(cls, "readonly_fields", cls.readonly_fields)
  • tests/regressiontests/admin_validation/tests.py

    diff --git a/tests/regressiontests/admin_validation/tests.py b/tests/regressiontests/admin_validation/tests.py
    index 2cf3c60..9e50a8b 100644
    a b class ValidationTestCase(TestCase):  
    9292            inlines = [SongInline]
    9393
    9494        self.assertRaisesMessage(ImproperlyConfigured,
    95             "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model Album.",
     95            "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model admin_validation.Album.",
    9696            validate,
    9797            AlbumAdmin, Album)
    9898
     99    def test_app_label_in_admin_validation(self):
     100        """
     101        Regression test for #15669 - Include app label in admin validation messages
     102        """
     103        class RawIdNonexistingAdmin(admin.ModelAdmin):
     104            raw_id_fields = ('nonexisting',)
     105
     106        self.assertRaisesMessage(ImproperlyConfigured,
     107            "'RawIdNonexistingAdmin.raw_id_fields' refers to field 'nonexisting' that is missing from model 'admin_validation.Album'.",
     108            validate,
     109            RawIdNonexistingAdmin, Album)
     110
    99111    def test_fk_exclusion(self):
    100112        """
    101113        Regression test for #11709 - when testing for fk excluding (when exclude is
  • tests/regressiontests/modeladmin/tests.py

    diff --git a/tests/regressiontests/modeladmin/tests.py b/tests/regressiontests/modeladmin/tests.py
    index 7387a95..9de9693 100644
    a b class ValidationTests(unittest.TestCase):  
    346346
    347347        self.assertRaisesRegexp(
    348348            ImproperlyConfigured,
    349             "'ValidationTestModelAdmin.raw_id_fields' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.",
     349            "'ValidationTestModelAdmin.raw_id_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
    350350            validate,
    351351            ValidationTestModelAdmin,
    352352            ValidationTestModel,
    class ValidationTests(unittest.TestCase):  
    574574
    575575        self.assertRaisesRegexp(
    576576            ImproperlyConfigured,
    577             "'ValidationTestModelAdmin.filter_vertical' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.",
     577            "'ValidationTestModelAdmin.filter_vertical' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
    578578            validate,
    579579            ValidationTestModelAdmin,
    580580            ValidationTestModel,
    class ValidationTests(unittest.TestCase):  
    614614
    615615        self.assertRaisesRegexp(
    616616            ImproperlyConfigured,
    617             "'ValidationTestModelAdmin.filter_horizontal' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.",
     617            "'ValidationTestModelAdmin.filter_horizontal' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
    618618            validate,
    619619            ValidationTestModelAdmin,
    620620            ValidationTestModel,
    class ValidationTests(unittest.TestCase):  
    654654
    655655        self.assertRaisesRegexp(
    656656            ImproperlyConfigured,
    657             "'ValidationTestModelAdmin.radio_fields' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.",
     657            "'ValidationTestModelAdmin.radio_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
    658658            validate,
    659659            ValidationTestModelAdmin,
    660660            ValidationTestModel,
    class ValidationTests(unittest.TestCase):  
    705705
    706706        self.assertRaisesRegexp(
    707707            ImproperlyConfigured,
    708             "'ValidationTestModelAdmin.prepopulated_fields' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.",
     708            "'ValidationTestModelAdmin.prepopulated_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
    709709            validate,
    710710            ValidationTestModelAdmin,
    711711            ValidationTestModel,
    class ValidationTests(unittest.TestCase):  
    716716
    717717        self.assertRaisesRegexp(
    718718            ImproperlyConfigured,
    719             "'ValidationTestModelAdmin.prepopulated_fields\['slug'\]\[0\]' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.",
     719            "'ValidationTestModelAdmin.prepopulated_fields\['slug'\]\[0\]' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
    720720            validate,
    721721            ValidationTestModelAdmin,
    722722            ValidationTestModel,
    class ValidationTests(unittest.TestCase):  
    953953
    954954        self.assertRaisesRegexp(
    955955            ImproperlyConfigured,
    956             "'ValidationTestModelAdmin.date_hierarchy' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.",
     956            "'ValidationTestModelAdmin.date_hierarchy' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
    957957            validate,
    958958            ValidationTestModelAdmin,
    959959            ValidationTestModel,
    class ValidationTests(unittest.TestCase):  
    993993
    994994        self.assertRaisesRegexp(
    995995            ImproperlyConfigured,
    996             "'ValidationTestModelAdmin.ordering\[0\]' refers to field 'non_existent_field' that is missing from model 'ValidationTestModel'.",
     996            "'ValidationTestModelAdmin.ordering\[0\]' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
    997997            validate,
    998998            ValidationTestModelAdmin,
    999999            ValidationTestModel,
    class ValidationTests(unittest.TestCase):  
    11881188
    11891189        self.assertRaisesRegexp(
    11901190            ImproperlyConfigured,
    1191             "'ValidationTestInline.fk_name' refers to field 'non_existent_field' that is missing from model 'ValidationTestInlineModel'.",
     1191            "'ValidationTestInline.fk_name' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestInlineModel'.",
    11921192            validate,
    11931193            ValidationTestModelAdmin,
    11941194            ValidationTestModel,
Back to Top