Skip to content

Commit

Permalink
Merge 6dddf0a into a8f2d9f
Browse files Browse the repository at this point in the history
  • Loading branch information
vaquer committed May 18, 2021
2 parents a8f2d9f + 6dddf0a commit 61a7dd4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cms/tests/test_check.py
Expand Up @@ -3,6 +3,7 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase
from django.test.utils import isolate_apps

from cms.api import add_plugin
from cms.models.pluginmodel import CMSPlugin
Expand Down Expand Up @@ -117,6 +118,19 @@ def test_non_numeric_site_id(self):
with self.settings(SITE_ID='broken'):
self.assertCheck(False, warnings=0, errors=1)

@isolate_apps("test_app")
def test_placeholder_field(self):
from django.db import models
from django.contrib import admin
from cms.models.fields import PlaceholderField

class ModelTest(models.Model):
field_a = PlaceholderField(slotname="test")

admin.site.register(ModelTest)
self.assertCheck(False, warnings=0, errors=1)
admin.site.unregister(ModelTest)


class CheckWithDatabaseTests(CheckAssertMixin, TestCase):

Expand Down
25 changes: 25 additions & 0 deletions cms/utils/check.py
Expand Up @@ -339,6 +339,31 @@ def get_class(method_name, model):
'https://django-cms.readthedocs.io/en/latest/extending_cms/extending_page_title.html#handling-relations.') # noqa


@define_check
def check_placeholder_fields(output):
"""
ModelAdmin instances that are using PlaceholderField fields
should be also a subclass of PlaceholderAdminMixin
"""
from django.contrib.admin import site
from cms.models.fields import PlaceholderField
from cms.admin.placeholderadmin import PlaceholderAdminMixin

with output.section("PlaceholderField") as section:
for model, model_admin in site._registry.items():
ph_fields = [field for field in model._meta.get_fields() if isinstance(field, PlaceholderField)]
if len(ph_fields) == 0:
continue

if not isinstance(model_admin, PlaceholderAdminMixin):
section.error(
"%s does not subclass of PlaceholderAdminMixin" % model_admin
)

if section.successful:
section.finish_success("PlaceholderField configuration okay")


def check(output):
"""
Checks the configuration/environment of this django CMS installation.
Expand Down

0 comments on commit 61a7dd4

Please sign in to comment.