Commit 67a76500 authored by Tim Graham's avatar Tim Graham
Browse files

Removed support for admin validators per deprecation timeline; refs #16905.

parent 5fb582d9
Loading
Loading
Loading
Loading
+2 −43
Original line number Diff line number Diff line
@@ -2,13 +2,11 @@ from collections import OrderedDict
import copy
import operator
from functools import partial, reduce, update_wrapper
import warnings

from django import forms
from django.conf import settings
from django.contrib import messages
from django.contrib.admin import widgets, helpers
from django.contrib.admin import validation
from django.contrib.admin.checks import (BaseModelAdminChecks, ModelAdminChecks,
    InlineModelAdminChecks)
from django.contrib.admin.exceptions import DisallowedModelAdminToField
@@ -18,9 +16,8 @@ from django.contrib.admin.utils import (quote, unquote, flatten_fieldsets,
from django.contrib.admin.templatetags.admin_static import static
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
from django.contrib.auth import get_permission_codename
from django.core import checks
from django.core.exceptions import (PermissionDenied, ValidationError,
    FieldDoesNotExist, FieldError, ImproperlyConfigured)
    FieldDoesNotExist, FieldError)
from django.core.paginator import Paginator
from django.core.urlresolvers import reverse
from django.db import models, transaction, router
@@ -38,7 +35,6 @@ from django.shortcuts import get_object_or_404
from django.template.response import SimpleTemplateResponse, TemplateResponse
from django.utils import six
from django.utils.decorators import method_decorator
from django.utils.deprecation import RemovedInDjango19Warning
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.html import escape, escapejs
from django.utils.http import urlencode
@@ -111,41 +107,10 @@ class BaseModelAdmin(six.with_metaclass(forms.MediaDefiningClass)):
    ordering = None
    view_on_site = True
    show_full_result_count = True

    # Validation of ModelAdmin definitions
    # Old, deprecated style:
    validator_class = None
    default_validator_class = validation.BaseValidator
    # New style:
    checks_class = BaseModelAdminChecks

    @classmethod
    def validate(cls, model):
        warnings.warn(
            'ModelAdmin.validate() is deprecated. Use "check()" instead.',
            RemovedInDjango19Warning)
        if cls.validator_class:
            validator = cls.validator_class()
        else:
            validator = cls.default_validator_class()
        validator.validate(cls, model)

    @classmethod
    def check(cls, model, **kwargs):
        if cls.validator_class:
            warnings.warn(
                'ModelAdmin.validator_class is deprecated. '
                'ModelAdmin validators must be converted to use '
                'the system check framework.',
                RemovedInDjango19Warning)
            validator = cls.validator_class()
            try:
                validator.validate(cls, model)
            except ImproperlyConfigured as e:
                return [checks.Error(e.args[0], hint=None, obj=cls)]
            else:
                return []
        else:
        return cls.checks_class().check(cls, model, **kwargs)

    def __init__(self):
@@ -546,11 +511,6 @@ class ModelAdmin(BaseModelAdmin):
    actions_on_top = True
    actions_on_bottom = False
    actions_selection_counter = True

    # validation
    # Old, deprecated style:
    default_validator_class = validation.ModelAdminValidator
    # New style:
    checks_class = ModelAdminChecks

    def __init__(self, model, admin_site):
@@ -1763,7 +1723,6 @@ class InlineModelAdmin(BaseModelAdmin):
    verbose_name_plural = None
    can_delete = True
    show_change_link = False

    checks_class = InlineModelAdminChecks

    def __init__(self, parent_model, admin_site):
+0 −448

File deleted.

Preview size limit exceeded, changes collapsed.

+1 −22
Original line number Diff line number Diff line
@@ -4,8 +4,7 @@ from django import forms
from django.contrib import admin
from django.contrib.contenttypes.admin import GenericStackedInline
from django.core import checks
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase, ignore_warnings, override_settings
from django.test import TestCase, override_settings

from .models import Song, Book, Album, TwoAlbumFKAndAnE, City, State, Influence

@@ -635,26 +634,6 @@ class SystemChecksTestCase(TestCase):
        errors = FieldsOnFormOnlyAdmin.check(model=Song)
        self.assertEqual(errors, [])

    @ignore_warnings(module='django.contrib.admin.options')
    def test_validator_compatibility(self):
        class MyValidator(object):
            def validate(self, cls, model):
                raise ImproperlyConfigured("error!")

        class MyModelAdmin(admin.ModelAdmin):
            validator_class = MyValidator

        errors = MyModelAdmin.check(model=Song)

        expected = [
            checks.Error(
                'error!',
                hint=None,
                obj=MyModelAdmin,
            )
        ]
        self.assertEqual(errors, expected)

    def test_check_sublists_for_duplicates(self):
        class MyModelAdmin(admin.ModelAdmin):
            fields = ['state', ['state']]
+0 −0

Empty file deleted.

tests/admin_validation/models.py

deleted100644 → 0
+0 −57
Original line number Diff line number Diff line
"""
Tests of ModelAdmin validation logic.
"""

from django.db import models
from django.utils.encoding import python_2_unicode_compatible


class Album(models.Model):
    title = models.CharField(max_length=150)


@python_2_unicode_compatible
class Song(models.Model):
    title = models.CharField(max_length=150)
    album = models.ForeignKey(Album)
    original_release = models.DateField(editable=False)

    class Meta:
        ordering = ('title',)

    def __str__(self):
        return self.title

    def readonly_method_on_model(self):
        # does nothing
        pass


class TwoAlbumFKAndAnE(models.Model):
    album1 = models.ForeignKey(Album, related_name="album1_set")
    album2 = models.ForeignKey(Album, related_name="album2_set")
    e = models.CharField(max_length=1)


class Author(models.Model):
    name = models.CharField(max_length=100)


class Book(models.Model):
    name = models.CharField(max_length=100)
    subtitle = models.CharField(max_length=100)
    price = models.FloatField()
    authors = models.ManyToManyField(Author, through='AuthorsBooks')


class AuthorsBooks(models.Model):
    author = models.ForeignKey(Author)
    book = models.ForeignKey(Book)


class State(models.Model):
    name = models.CharField(max_length=15)


class City(models.Model):
    state = models.ForeignKey(State)
Loading