Skip to content

Commit 81c7f43

Browse files
committed
Robust plugin moving
1 parent 0060988 commit 81c7f43

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

djangocms_rest/plugin_rendering.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ def render_cms_plugin(
8282
'<div class="indent">{value}</div></details>{close}<span class="sep">,</span>'
8383
)
8484

85+
# Tempalte for a non-collasable object/list
86+
FIXED_TEMPLATE = (
87+
'{open}<div class="indent">{value}</div>{close}<span class="sep">,</span>'
88+
)
89+
8590
# Tempalte for a single line key-value pair
8691
SIMPLE_TEMPLATE = (
8792
'<span class="key">"{key}"</span>: {value}<span class="sep">,</span>'
@@ -137,13 +142,14 @@ def highlight_json(
137142
for key, value in json_data.items()
138143
]
139144
if has_children:
140-
rendered_children = DETAILS_TEMPLATE.format(
141-
key=escape(field),
142-
value=''.join(children),
143-
open='[',
144-
close=']',
145+
items.append(
146+
DETAILS_TEMPLATE.format(
147+
key=escape(field),
148+
value=''.join(children),
149+
open='[',
150+
close=']',
151+
)
145152
)
146-
items.append(rendered_children)
147153
return {
148154
"open": '{',
149155
"close": '}',
@@ -165,6 +171,7 @@ class RESTRenderer(ContentRenderer):
165171
A custom renderer that uses the render_cms_plugin function to render
166172
CMS plugins in a RESTful way.
167173
"""
174+
placeholder_edit_template = "{content}{plugin_js}{placeholder_js}"
168175

169176
def render_plugin(
170177
self, instance, context, placeholder=None, editable: bool = False
@@ -208,13 +215,22 @@ def render_plugins(
208215
render_plugins=False,
209216
).data
210217

211-
yield OBJ_TEMPLATE.format(
218+
yield FIXED_TEMPLATE.format(
219+
placeholder_id=placeholder.pk,
212220
**highlight_json(
213221
placeholder_data,
214-
children=super().render_plugins(
222+
children=self.get_plugins_and_placeholder_lot(
215223
placeholder, language, context, editable=editable, template=template
216224
),
217225
field="content",
218226
)
219227
)
220228
yield "</div>"
229+
230+
def get_plugins_and_placeholder_lot(
231+
self, placeholder, language, context, editable=False, template=None
232+
) -> Iterable[str]:
233+
yield from super().render_plugins(
234+
placeholder, language, context, editable=editable, template=template
235+
)
236+
yield f'<div class="cms-placeholder cms-placeholder-{placeholder.pk}"></div>'

djangocms_rest/static/djangocms_rest/highlight.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
color: var(--value-color, blue);
4949
}
5050
.indent {
51-
padding-inline-start: 2em;
51+
padding-inline-start: 1em;
5252
border-inline-start: 1px solid var(--dca-gray-lightest, #f2f2f2);
53-
& > .sep:last-child {
53+
& > .sep:last-child, & > .sep:has(+ .cms-placeholder) {
5454
display: none;
5555
}
5656
}
@@ -62,4 +62,7 @@
6262
width: fit-content;
6363
cursor: pointer;
6464
}
65+
& > .sep:last-child {
66+
display: none;
67+
}
6568
}

0 commit comments

Comments
 (0)