Skip to content

Commit

Permalink
fix: Link template choices from correct setting (#98)
Browse files Browse the repository at this point in the history
* fix: Link template choices from correct setting

Template choices in LinkForm were being computed from
the setting DJANGOCMS_LINK_TEMPLATES instead of
LINK_TEMPLATE_CHOICES, that is the setting that exists
on djangocms_frontend.settings

* Add fix link template choices setting to changelog

* fix dcf_setting in Link data migration
  • Loading branch information
Biel Frontera authored Feb 21, 2023
1 parent e50fb61 commit 0549116
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ unpublished
===========

* Add missing form mixin for link plugin (allowing it to be extended)
* Fix Link template choices from correct setting

1.0.1
=====
Expand Down
16 changes: 2 additions & 14 deletions djangocms_frontend/contrib/link/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)


def get_templates():
choices = [
("default", _("Default")),
]
choices += getattr(
settings,
"DJANGOCMS_LINK_TEMPLATES",
[],
)
return choices


HOSTNAME = getattr(settings, "DJANGOCMS_LINK_INTRANET_HOSTNAME_PATTERN", None)
LINK_MODELS = getattr(django_settings, "DJANGOCMS_FRONTEND_LINK_MODELS", [])
MINIMUM_INPUT_LENGTH = getattr(
Expand Down Expand Up @@ -327,8 +315,8 @@ class Meta:
)
template = forms.ChoiceField(
label=_("Template"),
choices=get_templates(),
initial=first_choice(get_templates()),
choices=settings.LINK_TEMPLATE_CHOICES,
initial=first_choice(settings.LINK_TEMPLATE_CHOICES),
)
link_stretched = forms.BooleanField(
label=_("Stretch link"),
Expand Down
2 changes: 1 addition & 1 deletion djangocms_frontend/management/bootstrap4_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def t001_template(obj, new_obj, bs4_setting, dcf_setting):
x, y, "DJANGOCMS_PICTURE_TEMPLATES", "DJANGOCMS_PICTURE_TEMPLATES"
),
"T001_LINK": lambda x, y: t001_template(
x, y, "DJANGOCMS_LINK_TEMPLATES", "DJANGOCMS_LINK_TEMPLATES"
x, y, "DJANGOCMS_LINK_TEMPLATES", "DJANGOCMS_FRONTEND_LINK_TEMPLATE_CHOICES"
),
"T001_TABS": lambda x, y: t001_template(
x, y, "DJANGOCMS_BOOTSTRAP4_TAB_TEMPLATES", "DJANGOCMS_FRONTEND_TAB_TEMPLATES"
Expand Down
9 changes: 3 additions & 6 deletions tests/link/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
from cms.test_utils.testcases import CMSTestCase
from django.http import HttpRequest

from djangocms_frontend import settings
from djangocms_frontend.contrib.link.cms_plugins import LinkPlugin
from djangocms_frontend.contrib.link.forms import (
LinkForm,
SmartLinkField,
get_templates,
)
from djangocms_frontend.contrib.link.forms import LinkForm, SmartLinkField
from djangocms_frontend.contrib.link.helpers import get_choices

from ..fixtures import DJANGO_CMS4, TestFixture
Expand Down Expand Up @@ -135,7 +132,7 @@ def test_smart_link_field(self):
def test_link_form(self):
request = HttpRequest()
request.POST = {
"template": get_templates()[0][0],
"template": settings.LINK_TEMPLATE_CHOICES[0][0],
"link_type": "link",
}
form = LinkForm(request.POST)
Expand Down

0 comments on commit 0549116

Please sign in to comment.