Skip to content

Commit

Permalink
fix: Move autocomplete view for links to admin (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun authored Apr 24, 2024
1 parent 74dd2de commit fbed89f
Show file tree
Hide file tree
Showing 63 changed files with 217 additions and 570 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Changelog
=========

1.3.2 (2024-04-25)
==================

* fix: make grid layout (rows/columns) compatible with flex box-based Django admin by @fsbraun in https://github.com/django-cms/djangocms-frontend/pull/208
* fix: Improved handling of optional smart link field by @fsbraun in https://github.com/django-cms/djangocms-frontend/pull/210


1.3.1 (2024-04-12)
==================

Expand Down
2 changes: 1 addition & 1 deletion djangocms_frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
13. Github actions will publish the new package to pypi
"""

__version__ = "1.3.1"
__version__ = "1.3.2"
4 changes: 1 addition & 3 deletions djangocms_frontend/common/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class AttributesMixin:

def get_fieldsets(self, request, obj=None):
meta = self.form._meta
fields = (
["tag_type"] if "tag_type" in getattr(meta, "untangled_fields", ()) else []
)
fields = ["tag_type"] if "tag_type" in getattr(meta, "untangled_fields", ()) else []
fields.append("attributes")
return insert_fields(
super().get_fieldsets(request, obj),
Expand Down
4 changes: 1 addition & 3 deletions djangocms_frontend/common/bootstrap5/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ class Meta:
background_context = forms.ChoiceField(
label=_("Background context"),
required=False,
choices=settings.EMPTY_CHOICE
+ settings.COLOR_STYLE_CHOICES
+ (("transparent", _("Transparent")),),
choices=settings.EMPTY_CHOICE + settings.COLOR_STYLE_CHOICES + (("transparent", _("Transparent")),),
initial=settings.EMPTY_CHOICE[0][0],
widget=ColoredButtonGroup(),
)
Expand Down
8 changes: 2 additions & 6 deletions djangocms_frontend/common/bootstrap5/sizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,13 @@ class Meta:
initial=settings.EMPTY_CHOICE[0][0],
choices=settings.EMPTY_CHOICE + settings.SIZE_X_CHOICES,
# widget=ButtonGroup(attrs=dict(property="text")),
help_text=_(
"Sets the horizontal size relative to the surrounding container or the viewport."
),
help_text=_("Sets the horizontal size relative to the surrounding container or the viewport."),
)
size_y = forms.ChoiceField(
label=_("Vertical size"),
required=False,
initial=settings.EMPTY_CHOICE[0][0],
choices=settings.EMPTY_CHOICE + settings.SIZE_Y_CHOICES,
# widget=ButtonGroup(attrs=dict(property="text")),
help_text=_(
"Sets the vertical size relative to the surrounding container or the viewport."
),
help_text=_("Sets the vertical size relative to the surrounding container or the viewport."),
)
7 changes: 1 addition & 6 deletions djangocms_frontend/common/spacing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ def __init__(self, **kwargs):
self.side_choices = kwargs.pop("side_choices")
super().__init__(
[
IconGroup(
choices=[
(self.property + side, verbose)
for side, verbose in self.side_choices
]
),
IconGroup(choices=[(self.property + side, verbose) for side, verbose in self.side_choices]),
DivSelectWidget(choices=kwargs.pop("size_choices")),
],
**kwargs,
Expand Down
4 changes: 1 addition & 3 deletions djangocms_frontend/common/title.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def __init__(self, *args, **kwargs):

def clean(self, value):
if value[0] and not value[1]:
raise ValidationError(
_("Please add a title if you want to publish it."), code="incomplete"
)
raise ValidationError(_("Please add a title if you want to publish it."), code="incomplete")
return super().clean(value)

def compress(self, data_list):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,5 @@ def render(self, context, instance, placeholder):
instance.add_classes("accordion-collapse collapse")
if instance.accordion_item_open:
instance.add_classes("show")
instance.font_size = (
context["parent"]
.config.get("accordion_header_type", "")
.replace("h", "fs-")
)
instance.font_size = context["parent"].config.get("accordion_header_type", "").replace("h", "fs-")
return super().render(context, instance, placeholder)
4 changes: 1 addition & 3 deletions djangocms_frontend/contrib/alert/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@


@plugin_pool.register_plugin
class AlertPlugin(
mixin_factory("Alert"), AttributesMixin, ResponsiveMixin, SpacingMixin, CMSUIPlugin
):
class AlertPlugin(mixin_factory("Alert"), AttributesMixin, ResponsiveMixin, SpacingMixin, CMSUIPlugin):
"""
Components > "Alerts" Plugin
https://getbootstrap.com/docs/5.0/components/alerts/
Expand Down
4 changes: 1 addition & 3 deletions djangocms_frontend/contrib/alert/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
mixin_factory = settings.get_forms(alert)


class AlertForm(
mixin_factory("Alert"), ResponsiveFormMixin, SpacingFormMixin, EntangledModelForm
):
class AlertForm(mixin_factory("Alert"), ResponsiveFormMixin, SpacingFormMixin, EntangledModelForm):
"""
Components > "Alerts" Plugin
https://getbootstrap.com/docs/5.0/components/alerts/
Expand Down
16 changes: 4 additions & 12 deletions djangocms_frontend/contrib/card/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
)

# card allow for a transparent color
CARD_COLOR_STYLE_CHOICES = settings.COLOR_STYLE_CHOICES + (
("transparent", _("Transparent")),
)
CARD_COLOR_STYLE_CHOICES = settings.COLOR_STYLE_CHOICES + (("transparent", _("Transparent")),)

CARD_TEXT_STYLES = COLOR_STYLE_CHOICES + (("white", _("White")),)

Expand Down Expand Up @@ -132,9 +130,7 @@ class Meta:
label=_("Alignment"),
choices=settings.EMPTY_CHOICE + CARD_ALIGNMENT_CHOICES,
required=False,
widget=forms.HiddenInput()
if "card_alignment" in getattr(settings, "EXCL_CARD_PROP", ())
else IconGroup(),
widget=forms.HiddenInput() if "card_alignment" in getattr(settings, "EXCL_CARD_PROP", ()) else IconGroup(),
)
card_text_color = forms.ChoiceField(
label=_("Text context"),
Expand All @@ -148,9 +144,7 @@ class Meta:
label=_("Full height"),
initial=False,
required=False,
help_text=_(
"If checked cards in one row will automatically extend to the full row height."
),
help_text=_("If checked cards in one row will automatically extend to the full row height."),
widget=forms.HiddenInput()
if "card_full_height" in getattr(settings, "EXCL_CARD_PROP", ())
else forms.CheckboxInput,
Expand Down Expand Up @@ -193,9 +187,7 @@ class Meta:
label=_("Content alignment"),
choices=settings.EMPTY_CHOICE + settings.ALIGN_CHOICES,
required=False,
widget=forms.HiddenInput()
if "text_alignment" in getattr(settings, "EXCL_CARD_PROP", ())
else IconGroup(),
widget=forms.HiddenInput() if "text_alignment" in getattr(settings, "EXCL_CARD_PROP", ()) else IconGroup(),
)
attributes = AttributesFormField()
tag_type = TagTypeFormField()
Expand Down
4 changes: 1 addition & 3 deletions djangocms_frontend/contrib/carousel/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ class CarouselPlugin(mixin_factory("Carousel"), AttributesMixin, CMSUIPlugin):
]

def get_render_template(self, context, instance, placeholder):
return get_plugin_template(
instance, "carousel", "carousel", CAROUSEL_TEMPLATE_CHOICES
)
return get_plugin_template(instance, "carousel", "carousel", CAROUSEL_TEMPLATE_CHOICES)


@plugin_pool.register_plugin
Expand Down
4 changes: 1 addition & 3 deletions djangocms_frontend/contrib/carousel/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
(18, 9),
) + tuple(getattr(settings, "DJANGOCMS_FRONTEND_CAROUSEL_ASPECT_RATIOS", tuple()))

CAROUSEL_ASPECT_RATIO_CHOICES = tuple(
(f"{x}x{y}", f"{x}x{y}") for x, y in CAROUSEL_ASPECT_RATIOS
)
CAROUSEL_ASPECT_RATIO_CHOICES = tuple((f"{x}x{y}", f"{x}x{y}") for x, y in CAROUSEL_ASPECT_RATIOS)

CAROUSEL_TRANSITION_CHOICES = (
("", _("Slide")),
Expand Down
9 changes: 2 additions & 7 deletions djangocms_frontend/contrib/carousel/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,14 @@ class Meta:
label=_("Wrap"),
initial=True,
required=False,
help_text=_(
"Whether the carousel should cycle continuously or have " "hard stops."
),
help_text=_("Whether the carousel should cycle continuously or have " "hard stops."),
)
carousel_aspect_ratio = forms.ChoiceField(
label=_("Aspect ratio"),
choices=settings.EMPTY_CHOICE + CAROUSEL_ASPECT_RATIO_CHOICES,
required=False,
initial=settings.EMPTY_CHOICE[0][0],
help_text=_(
"Determines width and height of the image "
"according to the selected ratio."
),
help_text=_("Determines width and height of the image " "according to the selected ratio."),
)
carousel_transition = forms.ChoiceField(
label=_("Transition"),
Expand Down
4 changes: 1 addition & 3 deletions djangocms_frontend/contrib/carousel/frameworks/bootstrap5.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def render(self, context, instance, placeholder):
height = float(context.get("height") or CAROUSEL_DEFAULT_SIZE[1])

if parent.carousel_aspect_ratio:
aspect_width, aspect_height = tuple(
int(i) for i in parent.carousel_aspect_ratio.split("x")
)
aspect_width, aspect_height = tuple(int(i) for i in parent.carousel_aspect_ratio.split("x"))
height = width * aspect_height / aspect_width

instance.add_classes("carousel-item")
Expand Down
5 changes: 1 addition & 4 deletions djangocms_frontend/contrib/carousel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ def get_short_description(self):
image_text = _("<file is missing>")
elif self.rel_image.name:
image_text = self.rel_image.name
elif (
self.rel_image.original_filename
and os.path.split(self.rel_image.original_filename)[1]
):
elif self.rel_image.original_filename and os.path.split(self.rel_image.original_filename)[1]:
image_text = os.path.split(self.rel_image.original_filename)[1]
else:
image_text = "Image"
Expand Down
8 changes: 2 additions & 6 deletions djangocms_frontend/contrib/collapse/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ class CollapsePlugin(mixin_factory("Collapse"), AttributesMixin, CMSUIPlugin):


@plugin_pool.register_plugin
class CollapseTriggerPlugin(
mixin_factory("CollapseTrigger"), AttributesMixin, CMSUIPlugin
):
class CollapseTriggerPlugin(mixin_factory("CollapseTrigger"), AttributesMixin, CMSUIPlugin):
"""
Component > "Collapse" Plugin
https://getbootstrap.com/docs/5.0/components/collapse/
Expand All @@ -64,9 +62,7 @@ class CollapseTriggerPlugin(


@plugin_pool.register_plugin
class CollapseContainerPlugin(
mixin_factory("CollapseContainer"), AttributesMixin, CMSUIPlugin
):
class CollapseContainerPlugin(mixin_factory("CollapseContainer"), AttributesMixin, CMSUIPlugin):
"""
Component > "Collapse Container" Plugin
https://getbootstrap.com/docs/5.0/components/collapse/
Expand Down
22 changes: 5 additions & 17 deletions djangocms_frontend/contrib/grid/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,11 @@ def clean(self):
super().clean()
for size in settings.DEVICE_SIZES:
if f"{size}_col" in self.cleaned_data:
if (
isinstance(self.cleaned_data[f"{size}_col"], str)
and self.cleaned_data[f"{size}_col"].isnumeric()
):
self.cleaned_data[f"{size}_col"] = int(
self.cleaned_data[f"{size}_col"]
)
if isinstance(self.cleaned_data[f"{size}_col"], str) and self.cleaned_data[f"{size}_col"].isnumeric():
self.cleaned_data[f"{size}_col"] = int(self.cleaned_data[f"{size}_col"])
else:
raise ValidationError(
_(
'Column size needs to be empty, "auto", or a '
"number between 1 and %(cols)d"
),
_('Column size needs to be empty, "auto", or a ' "number between 1 and %(cols)d"),
params=dict(cols=GRID_SIZE),
code="invalid_column",
)
Expand Down Expand Up @@ -233,16 +225,12 @@ def clean(self):
extra_fields_column[f"{size}_ms"] = forms.BooleanField(
label="ms-auto" if size == "xs" else f"ms-{size}-auto",
required=False,
widget=forms.HiddenInput()
if "{size}_ms" in getattr(settings, "EXCL_COL_PROP", ())
else forms.CheckboxInput(),
widget=forms.HiddenInput() if "{size}_ms" in getattr(settings, "EXCL_COL_PROP", ()) else forms.CheckboxInput(),
)
extra_fields_column[f"{size}_me"] = forms.BooleanField(
label="me-auto" if size == "xs" else f"me-{size}-auto",
required=False,
widget=forms.HiddenInput()
if "{size}_me" in getattr(settings, "EXCL_COL_PROP", ())
else forms.CheckboxInput(),
widget=forms.HiddenInput() if "{size}_me" in getattr(settings, "EXCL_COL_PROP", ()) else forms.CheckboxInput(),
)

GridColumnForm = type(
Expand Down
8 changes: 2 additions & 6 deletions djangocms_frontend/contrib/grid/frameworks/bootstrap5.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def get_grid_values(self):
for device in settings.DEVICE_SIZES:
for element in ("col", "order", "offset", "ms", "me"):
size = getattr(self, f"{device}_{element}", None)
if isinstance(size, int) and (
element == "col" or element == "order" or element == "offset"
):
if isinstance(size, int) and (element == "col" or element == "order" or element == "offset"):
if size == 0 and element == "col": # 0 represents auto
size = "auto"
if device == "xs":
Expand All @@ -62,9 +60,7 @@ def get_grid_values(self):
class GridColumnRenderMixin:
def render(self, context, instance, placeholder):
instance.add_classes(
f"col text-{instance.text_alignment}"
if instance.config.get("text_alignment", None)
else "col"
f"col text-{instance.text_alignment}" if instance.config.get("text_alignment", None) else "col"
)
instance.add_classes(instance.column_alignment)
instance.add_classes(get_grid_values(instance))
Expand Down
4 changes: 1 addition & 3 deletions djangocms_frontend/contrib/grid/frameworks/foundation6.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def get_grid_values(self):
else:
classes.append(f"{foundation_sizes.get(device, device)}-{size}")
else:
classes.append(
f"{foundation_sizes.get(device, device)}-{element}-{size}"
)
classes.append(f"{foundation_sizes.get(device, device)}-{element}-{size}")

return classes

Expand Down
16 changes: 4 additions & 12 deletions djangocms_frontend/contrib/grid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ class Meta:
_("GridContainer")

def get_short_description(self):
text = self.config.get("plugin_title", {}).get("title", "") or self.config.get(
"attributes", {}
).get("id", "")
text = self.config.get("plugin_title", {}).get("title", "") or self.config.get("attributes", {}).get("id", "")
for item in GRID_CONTAINER_CHOICES[1:]:
if item[0] == self.container_type:
text += f" ({item[1]})"
Expand All @@ -56,13 +54,9 @@ class Meta:
_("GridRow")

def get_short_description(self):
descr = self.config.get("plugin_title", {}).get("title", "") or self.config.get(
"attributes", {}
).get("id", "")
descr = self.config.get("plugin_title", {}).get("title", "") or self.config.get("attributes", {}).get("id", "")
column_count = len(self.child_plugin_instances or [])
column_count_str = ngettext(
"(1 column)", "(%(count)i columns)", column_count
) % {"count": column_count}
column_count_str = ngettext("(1 column)", "(%(count)i columns)", column_count) % {"count": column_count}
if descr:
column_count_str = f"{descr} {column_count_str}"
return column_count_str
Expand All @@ -80,9 +74,7 @@ class Meta:
_("GridColumn")

def get_short_description(self):
text = self.config.get("plugin_title", {}).get("title", "") or self.config.get(
"attributes", {}
).get("id", "")
text = self.config.get("plugin_title", {}).get("title", "") or self.config.get("attributes", {}).get("id", "")

if self.xs_col:
text += f" (col-{self.xs_col}) "
Expand Down
6 changes: 3 additions & 3 deletions djangocms_frontend/contrib/icon/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class IconPlugin(
text_icon = (
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" '
'class="bi bi-emoji-sunglasses" viewBox="0 0 16 16"><path d="M4.968 9.75a.5.5 0 1 0-.866.5A4.5 4.5 '
'0 0 0 8 12.5a4.5 4.5 0 0 0 3.898-2.25.5.5 0 1 0-.866-.5A3.5 3.5 0 0 1 8 11.5a3.5 3.5 0 0 1-3.032-1.75M7 '
'5.116V5a1 1 0 0 0-1-1H3.28a1 1 0 0 0-.97 1.243l.311 1.242A2 2 0 0 0 4.561 8H5a2 2 0 0 0 1.994-1.839A3 '
'3 0 0 1 8 6c.393 0 .74.064 1.006.161A2 2 0 0 0 11 8h.438a2 2 0 0 0 1.94-1.515l.311-1.242A1 1 0 0 0 '
"0 0 0 8 12.5a4.5 4.5 0 0 0 3.898-2.25.5.5 0 1 0-.866-.5A3.5 3.5 0 0 1 8 11.5a3.5 3.5 0 0 1-3.032-1.75M7 "
"5.116V5a1 1 0 0 0-1-1H3.28a1 1 0 0 0-.97 1.243l.311 1.242A2 2 0 0 0 4.561 8H5a2 2 0 0 0 1.994-1.839A3 "
"3 0 0 1 8 6c.393 0 .74.064 1.006.161A2 2 0 0 0 11 8h.438a2 2 0 0 0 1.94-1.515l.311-1.242A1 1 0 0 0 "
'12.72 4H10a1 1 0 0 0-1 1v.116A4.2 4.2 0 0 0 8 5c-.35 0-.69.04-1 .116"/><path d="M16 8A8 8 0 1 1 0 8a8 8 '
'0 0 1 16 0m-1 0A7 7 0 1 0 1 8a7 7 0 0 0 14 0"/></svg>'
)
Expand Down
Loading

0 comments on commit fbed89f

Please sign in to comment.