Skip to content

Commit

Permalink
Update test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Mar 21, 2024
1 parent a006821 commit 47cb3d0
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 70 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 47 additions & 27 deletions djangocms_frontend/contrib/link/forms.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

{% block extrahead %}
{{ block.super }}
<style> {# Bugfix for Django admin styling #}
@media screen {
.change-form .select2-dropdown {
background: var(--body-bg);
border: 1px solid var(--border-color);
}
}
</style>
<script src="{% static 'djangocms_frontend/js/bundle.link.js' %}"></script>
{% endblock %}

Expand Down
8 changes: 0 additions & 8 deletions djangocms_frontend/static/djangocms_frontend/css/select2.css

This file was deleted.

This file was deleted.

22 changes: 0 additions & 22 deletions private/sass/select2.scss

This file was deleted.

7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"easy-thumbnails",
"djangocms-attributes-field>=1",
"djangocms-text-ckeditor>=3.1.0",
"django-select2",
"django-entangled>=0.5.4",
]

Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions tests/requirements/dj41_cms41.txt
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions tests/requirements/dj42_cms41.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tests/requirements/dj50_cms41.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 47cb3d0

Please sign in to comment.