Skip to content

Commit 17278bc

Browse files
committed
Rename LinkPlugin
1 parent 83e99f0 commit 17278bc

File tree

5 files changed

+43
-14
lines changed

5 files changed

+43
-14
lines changed

djangocms_frontend/contrib/carousel/templates/djangocms_frontend/bootstrap5/carousel/default/image.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{% load cms_tags easy_thumbnails_tags %}
22
{% if instance.rel_image %}
3-
{% thumbnail instance.rel_image options.size crop=options.crop upscale=options.upscale subject_location=instance.rel_image.subject_location as thumbnail %}
4-
5-
<img class="d-block w-100" src="{{ thumbnail.url }}" alt="{{ instance.rel_image.default_alt_text|default:'' }}" />
3+
<img class="d-block mx-auto" style="height: 40vh;" src="{{ instance.rel_image.url }}" alt="{{ instance.rel_image.default_alt_text|default:'' }}" />
64
{% else %}
75
<div class="d-block w-100"
86
style="aspect-ratio: {{ aspect_ratio }}">

djangocms_frontend/contrib/link/cms_plugins.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def get_fieldsets(self, request, obj=None):
8181
return fieldsets
8282

8383

84-
class LinkPlugin(mixin_factory("Link"), AttributesMixin, SpacingMixin, LinkPluginMixin, CMSUIPlugin):
84+
class TextLinkPlugin(mixin_factory("Link"), AttributesMixin, SpacingMixin, LinkPluginMixin, CMSUIPlugin):
8585
"""
8686
Components > "Button" Plugin
8787
https://getbootstrap.com/docs/5.0/components/buttons/
@@ -113,7 +113,6 @@ def get_plugin_urls(self):
113113
]
114114

115115

116-
if "djangocms_frontend.contrib.link" in django_settings.INSTALLED_APPS and "LinkPlugin" not in plugin_pool.plugins:
116+
if "djangocms_frontend.contrib.link" in django_settings.INSTALLED_APPS:
117117
# Only register plugin if in INSTALLED_APPS
118-
119-
plugin_pool.register_plugin(LinkPlugin)
118+
plugin_pool.register_plugin(TextLinkPlugin)

djangocms_frontend/contrib/link/helpers.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
from django.contrib.contenttypes.models import ContentType
88
from django.core.exceptions import FieldError, ObjectDoesNotExist
99
from django.utils.encoding import force_str
10-
from django.utils.html import mark_safe
11-
12-
from djangocms_frontend.settings import EMPTY_CHOICE
1310

1411
LINK_MODELS = getattr(django_settings, "DJANGOCMS_FRONTEND_LINK_MODELS", [])
1512

@@ -62,12 +59,21 @@ def get_object_for_value(value):
6259
return None
6360

6461

62+
def unescape(text, nbsp):
63+
return (text.replace("&nbsp;", nbsp)
64+
.replace("&amp;", "&")
65+
.replace("&lt;", "<")
66+
.replace("&gt;", ">")
67+
.replace("&quot;", '"')
68+
.replace("&#x27;", "'"))
69+
70+
6571
def get_link_choices(request, term="", lang=None, nbsp=None):
6672
global _querysets
6773

6874
if nbsp is None:
6975
nbsp = "" if term else "\u2000"
70-
available_objects = [dict(id=EMPTY_CHOICE[0][0], text=EMPTY_CHOICE[0][1])]
76+
available_objects = []
7177
# Now create our list of cms pages
7278
type_id = ContentType.objects.get_for_model(Page).id
7379
for value, descr in get_page_choices(lang):
@@ -78,7 +84,9 @@ def get_link_choices(request, term="", lang=None, nbsp=None):
7884
"children": [
7985
dict(
8086
id=f"{type_id}-{page}",
81-
text=mark_safe(name.replace("&nbsp;", nbsp)),
87+
# django admin's autocomplete view requires unescaped strings
88+
# get_page_choices escapes strings, so we undo the escape
89+
text=unescape(name, nbsp),
8290
)
8391
for page, name in descr
8492
if not isinstance(term, str) or term.upper() in name.upper()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by Django 5.0.6 on 2024-05-22 20:33
2+
3+
from django.db import migrations
4+
5+
6+
def rename(apps, old_name, new_name):
7+
UIItem = apps.get_model("djangocms_frontend", "FrontendUIItem")
8+
UIItem.objects.filter(ui_item=old_name).update(ui_item=new_name, plugin_type=f"{new_name}Plugin")
9+
10+
11+
class Migration(migrations.Migration):
12+
13+
dependencies = [
14+
('link', '0001_initial'),
15+
]
16+
17+
18+
operations = [
19+
migrations.RunPython(
20+
lambda apps, schema_editor: rename(apps, "Link", "TextLink"),
21+
lambda apps, schema_editor: rename(apps, "TextLink", "Link"),
22+
elidable=True,
23+
),
24+
]

djangocms_frontend/contrib/navigation/cms_plugins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ...common.background import BackgroundMixin
88
from ...helpers import first_choice, get_plugin_template, get_template_path
99
from .. import navigation
10-
from ..link.cms_plugins import LinkPlugin, LinkPluginMixin
10+
from ..link.cms_plugins import LinkPluginMixin, TextLinkPlugin
1111
from . import forms, models
1212

1313
mixin_factory = settings.get_renderer(navigation)
@@ -166,7 +166,7 @@ class NavContainerPlugin(
166166
@plugin_pool.register_plugin
167167
class NavLinkPlugin(
168168
mixin_factory("NavLink"),
169-
LinkPlugin,
169+
TextLinkPlugin,
170170
):
171171
"""
172172
A plugin that allows creating navigation links for the frontend.

0 commit comments

Comments
 (0)