diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 691f720c..5cdc42de 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -7,6 +7,7 @@ Changelog
* feat: Add abstract base model `AbstractFrontendUIItem` by @fsbraun in https://github.com/django-cms/djangocms-frontend/pull/195
* feat: Add icons for selected text-enabled plugins by @fsbraun in https://github.com/django-cms/djangocms-frontend/pull/195
+* fix: Correct site used when using Link plugin within a static placholder in django CMS 3.x by @fsbraun
* fix: removed Nav Container plugin and fixed Navigation Link plugin by @fsbraun in https://github.com/django-cms/djangocms-frontend/pull/192
* fix: Remove `{% spaceless %}` around `{% block "content" %}` by @fsbraun in https://github.com/django-cms/djangocms-frontend/pull/188
* fix: Improved fieldset layout for Django 4.2+ by @fsbraun in https://github.com/django-cms/djangocms-frontend/pull/185
diff --git a/djangocms_frontend/contrib/link/forms.py b/djangocms_frontend/contrib/link/forms.py
index 7a464cec..edafb1f4 100644
--- a/djangocms_frontend/contrib/link/forms.py
+++ b/djangocms_frontend/contrib/link/forms.py
@@ -1,15 +1,17 @@
+import json
+from types import SimpleNamespace
+
from django import apps, forms
from django.conf import settings as django_settings
-from django.contrib.admin.widgets import SELECT2_TRANSLATIONS
+from django.contrib.admin.widgets import AutocompleteMixin
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db import models
from django.db.models.fields.related import ManyToOneRel
+from django.urls import reverse
from django.utils.encoding import force_str
-from django.utils.translation import get_language
from django.utils.translation import gettext as _
-from django_select2.forms import HeavySelect2Widget, Select2Widget
# from djangocms_link.validators import IntranetURLValidator
from entangled.forms import EntangledModelForm
@@ -56,41 +58,59 @@ def __init__(self, *args, **kwargs):
)
-class Select2jqWidget(HeavySelect2Widget if MINIMUM_INPUT_LENGTH else Select2Widget):
- """Make jQuery available to Select2 widget"""
-
+class Select2jqWidget(AutocompleteMixin, forms.Select):
empty_label = _("Select a destination")
- @property
- def media(self):
- extra = ".min"
- i18n_name = SELECT2_TRANSLATIONS.get(get_language())
- i18n_file = (
- ("admin/js/vendor/select2/i18n/%s.js" % i18n_name,) if i18n_name else ()
- )
- return forms.Media(
- js=("admin/js/vendor/select2/select2.full%s.js" % extra,)
- + i18n_file
- + ("djangocms_frontend/js/django_select2.js",),
- css={
- "screen": (
- "admin/css/vendor/select2/select2%s.css" % extra,
- "djangocms_frontend/css/select2.css",
- ),
- },
- )
-
def __init__(self, *args, **kwargs):
- if MINIMUM_INPUT_LENGTH:
+ if MINIMUM_INPUT_LENGTH and False:
if "attrs" in kwargs:
kwargs["attrs"].setdefault(
"data-minimum-input-length", MINIMUM_INPUT_LENGTH
)
else:
kwargs["attrs"] = {"data-minimum-input-length": MINIMUM_INPUT_LENGTH}
- kwargs.setdefault("data_view", "dcf_autocomplete:ac_view")
+ kwargs.setdefault("admin_site", None)
+ kwargs.setdefault("field", SimpleNamespace(name="name", model=SimpleNamespace(
+ _meta=SimpleNamespace(app="app", label="label")
+ )))
super().__init__(*args, **kwargs)
+ def get_url(self):
+ return reverse("dcf_autocomplete:ac_view")
+
+ def build_attrs(self, base_attrs, extra_attrs=None):
+ """
+ Set select2's AJAX attributes.
+
+ Attributes can be set using the html5 data attribute.
+ Nested attributes require a double dash as per
+ https://select2.org/configuration/data-attributes#nested-subkey-options
+ """
+ attrs = super(forms.Select, self).build_attrs(base_attrs, extra_attrs=extra_attrs)
+ attrs.setdefault("class", "")
+ attrs.update(
+ {
+ "data-ajax--cache": "true",
+ "data-ajax--delay": 250,
+ "data-ajax--type": "GET",
+ "data-ajax--url": self.get_url(),
+ "data-theme": "admin-autocomplete",
+ "data-app-label": "app",
+ "data-model-name": "model",
+ "data-field-name": "field",
+ "data-allow-clear": json.dumps(not self.is_required),
+ "data-placeholder": "", # Allows clearing of the input.
+ "lang": self.i18n_name,
+ "class": attrs["class"]
+ + (" " if attrs["class"] else "")
+ + "admin-autocomplete",
+ }
+ )
+ return attrs
+
+ def optgroups(self, name, value, attr=None):
+ return super(forms.Select, self).optgroups(name, value)
+
class SmartLinkField(forms.ChoiceField):
widget = Select2jqWidget
diff --git a/djangocms_frontend/contrib/link/templates/djangocms_frontend/admin/link.html b/djangocms_frontend/contrib/link/templates/djangocms_frontend/admin/link.html
index ae8f899d..d931501c 100644
--- a/djangocms_frontend/contrib/link/templates/djangocms_frontend/admin/link.html
+++ b/djangocms_frontend/contrib/link/templates/djangocms_frontend/admin/link.html
@@ -3,6 +3,14 @@
{% block extrahead %}
{{ block.super }}
+
{% endblock %}
diff --git a/djangocms_frontend/static/djangocms_frontend/css/select2.css b/djangocms_frontend/static/djangocms_frontend/css/select2.css
deleted file mode 100644
index dd7d7530..00000000
--- a/djangocms_frontend/static/djangocms_frontend/css/select2.css
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
- This file is generated.
- Do not edit directly.
- Edit original files in
- /private/sass instead
- */
-
-@media screen{.change-form .select2-container--default .select2-selection--single,.change-form .select2-dropdown{background:var(--dca-white,var(--body-bg,#fff))}.change-form .select2-container--default .select2-results__option[aria-selected=true]{background:var(--dca-gray,var(--body-quiet-color,#666))}.change-form .select2-container--default .select2-selection--single .select2-selection__rendered{color:var(--dca-black,var(--body-fg,#000))}.change-form .popover{background:var(--dca-white,var(--body-bg,#fff))}}
\ No newline at end of file
diff --git a/djangocms_frontend/static/djangocms_frontend/css/select2.css.map b/djangocms_frontend/static/djangocms_frontend/css/select2.css.map
deleted file mode 100644
index 7b2ac8e9..00000000
--- a/djangocms_frontend/static/djangocms_frontend/css/select2.css.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"sourceRoot":"","sources":["../../../../private/sass/select2.scss"],"names":[],"mappings":"AAEA,mCACI,yEACI,qCAEJ,yEACI,oCAEJ,oFACI,6BAEJ,SACI,sCAIR,4BACI","file":"select2.css"}
\ No newline at end of file
diff --git a/private/sass/select2.scss b/private/sass/select2.scss
deleted file mode 100644
index 4b5c6dc9..00000000
--- a/private/sass/select2.scss
+++ /dev/null
@@ -1,22 +0,0 @@
-@import "components/variables";
-
-@media screen {
- .change-form {
- .select2-container--default .select2-selection--single,
- .select2-dropdown {
- background: var(--dca-white, var(--body-bg, white));
- }
-
- .select2-container--default .select2-results__option[aria-selected=true] {
- background: var(--dca-gray, var(--body-quiet-color, #666));
- }
-
- .select2-container--default .select2-selection--single .select2-selection__rendered {
- color: var(--dca-black, var(--body-fg, #000));
- }
-
- .popover {
- background: var(--dca-white, var(--body-bg, white)); // standard django admin
- }
- }
-}
diff --git a/setup.py b/setup.py
index e34f52bc..8c1534ce 100644
--- a/setup.py
+++ b/setup.py
@@ -10,7 +10,6 @@
"easy-thumbnails",
"djangocms-attributes-field>=1",
"djangocms-text-ckeditor>=3.1.0",
- "django-select2",
"django-entangled>=0.5.4",
]
@@ -22,10 +21,10 @@
"djangocms-static-ace",
],
"cms-4": [
- "django-cms>=4.1.0rc4",
+ "django-cms>=4.1.0",
"django-parler",
- "djangocms-versioning>=2.0.0rc1",
- "djangocms-alias>=2.0.0rc1",
+ "djangocms-versioning>=2.0.0",
+ "djangocms-alias>=2.0.0",
],
"cms-3": [
"django-cms<4",
diff --git a/tests/requirements/dj41_cms41.txt b/tests/requirements/dj41_cms41.txt
index fd4cb1e8..1c207cae 100644
--- a/tests/requirements/dj41_cms41.txt
+++ b/tests/requirements/dj41_cms41.txt
@@ -1,7 +1,7 @@
-r base.txt
Django>=4.1,<4.2
-django-cms>=4.1rc2
--e git+https://github.com/fsbraun/djangocms-alias.git@master#egg=djangocms-alias
--e git+https://github.com/fsbraun/djangocms-url-manager.git@master#egg=djangocms-url-manager
-https://github.com/django-cms/djangocms-versioning/tarball/master#egg=djangocms-versioning
+django-cms>=4.1
+djangocms-alias>=2.0.0
+djangocms-versioning>=2.0.0
+git+https://github.com/fsbraun/djangocms-url-manager.git@master#egg=djangocms-url-manager
diff --git a/tests/requirements/dj42_cms41.txt b/tests/requirements/dj42_cms41.txt
index 861ab22f..381aa811 100644
--- a/tests/requirements/dj42_cms41.txt
+++ b/tests/requirements/dj42_cms41.txt
@@ -2,6 +2,6 @@
Django>=4.2,<4.3
django-cms>=4.1rc2
-git+https://github.com/fsbraun/djangocms-alias.git@master#egg=djangocms-alias
+djangocms-alias>=2.0.0
+djangocms-versioning>=2.0.0
git+https://github.com/fsbraun/djangocms-url-manager.git@master#egg=djangocms-url-manager
-https://github.com/django-cms/djangocms-versioning/tarball/master#egg=djangocms-versioning
diff --git a/tests/requirements/dj50_cms41.txt b/tests/requirements/dj50_cms41.txt
index 002f7efb..ef612d80 100644
--- a/tests/requirements/dj50_cms41.txt
+++ b/tests/requirements/dj50_cms41.txt
@@ -2,6 +2,6 @@
Django>=5.0,<5.1
django-cms>=4.1rc5
-git+https://github.com/fsbraun/djangocms-alias.git@master#egg=djangocms-alias
+djangocms-alias>=2.0.0
+djangocms-versioning>=2.0.0
git+https://github.com/fsbraun/djangocms-url-manager.git@master#egg=djangocms-url-manager
-https://github.com/django-cms/djangocms-versioning/tarball/master#egg=djangocms-versioning