Skip to content

Commit 4476127

Browse files
committed
fix attributes mixin
1 parent a6a2025 commit 4476127

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

djangocms_frontend/common/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from djangocms_frontend import settings
44

5-
from .attributes import AttributesMixin
5+
from .attributes import AttributesMixin, AttributesFormMixin
66
from .title import TitleFormMixin, TitleMixin
77

88
__common = {
@@ -32,6 +32,7 @@
3232
"TitleMixin",
3333
"TitleFormMixin",
3434
"AttributesMixin",
35+
"AttributesFormMixin",
3536
"BackgroundFormMixin",
3637
"BackgroundMixin",
3738
"ResponsiveFormMixin",

djangocms_frontend/common/attributes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from django.utils.translation import gettext_lazy as _
2+
from entangled.forms import EntangledModelFormMixin
23

4+
from djangocms_frontend.fields import AttributesFormField
35
from djangocms_frontend.helpers import insert_fields
46

57

@@ -25,3 +27,13 @@ def get_fieldsets(self, request, obj=None):
2527
blockattrs=self.block_attr,
2628
position=-1, # Always last
2729
)
30+
31+
32+
class AttributesFormMixin(EntangledModelFormMixin):
33+
class Meta:
34+
entangled_fields = {
35+
"config": [
36+
"attributes",
37+
]
38+
}
39+
attributes = AttributesFormField()

djangocms_frontend/component_base.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
from .ui_plugin_base import CMSUIPluginBase
1313

1414

15+
def _import_or_empty(module, name):
16+
try:
17+
return importlib.import_module(module).__dict__[name]
18+
except (ImportError, KeyError):
19+
return type(name, (), {})
20+
21+
1522
def _get_mixin_classes(mixins: list, suffix: str = "") -> list[type]:
1623
"""Find and import mixin classes from a list of mixin strings"""
1724
mixins = [
@@ -20,7 +27,8 @@ def _get_mixin_classes(mixins: list, suffix: str = "") -> list[type]:
2027
else ("djangocms_frontend.common", f"{mixin}{suffix}Mixin")
2128
for mixin in mixins
2229
]
23-
return [importlib.import_module(module).__dict__[name] for module, name in mixins]
30+
31+
return [_import_or_empty(module, name) for module, name in mixins]
2432

2533

2634
class Slot:

0 commit comments

Comments
 (0)