Skip to content

Commit

Permalink
remove link plugin if frontend link is used
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Nov 20, 2024
1 parent 5776cd1 commit a6a2025
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
28 changes: 13 additions & 15 deletions djangocms_frontend/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,29 @@ class DjangocmsFrontendConfig(apps.AppConfig):
def ready(self):
from . import plugin_tag

plugin_tag.setup()
checks.register(check_settings)
checks.register(check_installed_apps)
plugin_tag.setup()


def check_settings(*args, **kwargs):
def check_settings(*args, **kwargs): # pragma: no cover
from django.conf import settings

warnings = []

if hasattr(settings, "DJANGOCMS_FRONTEND_MINIMUM_INPUT_LENGTH"): # pragma: no cover
if hasattr(settings, "DJANGOCMS_FRONTEND_MINIMUM_INPUT_LENGTH"):
warnings.append(
checks.Warning(
"The DJANGOCMS_FRONTEND_MINIMUM_INPUT_LENGTH setting was removed in djangocms-frontend 2.\n"
"The DJANGOCMS_FRONTEND_MINIMUM_INPUT_LENGTH setting was removed in djangocms-frontend 2.",
"Use DJANGOCMS_LINK_MINIMUM_INPUT_LENGTH instead.",
"This message disappears after removing the DJANGOCMS_FRONTEND_MINIMUM_INPUT_LENGTH from "
"your project's settings.\n",
id="djangocms_frontend.W001",
obj="settings.DJANGOCMS_FRONTEND_MINIMUM_INPUT_LENGTH",
)
)
if hasattr(settings, "DJANGOCMS_FRONTEND_LINK_MODELS"): # pragma: no cover
if hasattr(settings, "DJANGOCMS_FRONTEND_LINK_MODELS"):
warnings.append(
checks.Warning(
"The DJANGOCMS_FRONTEND_LINK_MODELS setting was removed in djangocms-frontend 2.\n"
"The DJANGOCMS_FRONTEND_LINK_MODELS setting was removed in djangocms-frontend 2. "
"djangocms-frontend 2 uses linkable models from djangocms-link. See "
"https://github.com/django-cms/djangocms-link#django-cms-link for more info.",
"This message disappears after removing the DJANGOCMS_FRONTEND_LINK_MODELS from your "
Expand All @@ -45,7 +43,7 @@ def check_settings(*args, **kwargs):
return warnings


def check_installed_apps(app_configs, **kwargs):
def check_installed_apps(*args, **kwargs): # pragma: no cover
from django.conf import settings

errors = []
Expand All @@ -54,15 +52,15 @@ def check_installed_apps(app_configs, **kwargs):
"djangocms_frontend.contrib.image",
"djangocms_frontend.contrib.link",
]

if any(app in settings.INSTALLED_APPS for app in link_contrib_apps):
if "djangocms_link" not in settings.INSTALLED_APPS: # pragma: no cover
link_apps_used = [app for app in link_contrib_apps if app in settings.INSTALLED_APPS]
if link_apps_used:
if "djangocms_link" not in settings.INSTALLED_APPS:
errors.append(
checks.Error(
"djangocms-frontend requires djangocms-link to be installed for the following plugins: {}.\n"
"Add 'djangocms_link' to your INSTALLED_APPS setting or remove all of the above apps.".format(
", ".join(link_contrib_apps)
"djangocms-frontend requires djangocms-link to be installed for {}.".format(
", ".join(link_apps_used)
),
"Add 'djangocms_link' to your INSTALLED_APPS setting or remove all of the above apps.",
id="djangocms_frontend.E001",
obj="settings.INSTALLED_APPS",
)
Expand Down
5 changes: 5 additions & 0 deletions djangocms_frontend/contrib/link/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,8 @@ def get_render_template(self, context, instance, placeholder):
if "djangocms_frontend.contrib.link" in django_settings.INSTALLED_APPS:
# Only register plugin if in INSTALLED_APPS
plugin_pool.register_plugin(TextLinkPlugin)

if "djangocms_link" in django_settings.INSTALLED_APPS:
from djangocms_link.cms_plugins import LinkPlugin

LinkPlugin.parent_classes = [None] # Remove it from the list of valid plugins

0 comments on commit a6a2025

Please sign in to comment.